I was recently asked whether it is possible to attach a shared parameter to a DWG drawing file imported into a Revit model. The exploration of this issue was interesting enough for me to like to share it.
First of all, if you are interested in attaching a shared parameter to Revit elements, there are some pretty clear examples available demonstrating how to achieve this. One is the FireRating sample in the Revit SDK, the other is the Revit API introduction labs suite 4-3-1, 4-3-2, and 4-3-3, which is based on the FireRating sample and includes some extensions as well. The former is in VB, the latter both C# and VB.
When defining a new shared parameter, you need to specify which categories it applies to. The FireRating sample attaches a shared parameter 'FireRating' to all doors in the Revit model, and it identifies them using the BuiltInCategory OST_Doors. The labs extend this slightly in order to show that you can attach a shared parameter to walls as well. Doors are standard family instances, whereas walls use a system family.
The interesting thing that cropped up exploring this for imported drawing files is that the process of importing the drawing into Revit causes Revit to create a new category specifically for the inserted file on the fly, named the same as the original drawing file. For instance, after inserting Drawing1.dwg, a new category named Drawing1.dwg appears in Document.Categories. Therefore, for imported drawing files, we obviously cannot use a built-in category to identify which instances to attach the parameter to.
So, to create a new shared parameter for an inserted drawing file, you will need to keep track of the drawing name and use that to identify the category to define the shared parameter for. I have tested this procedure in the attached C# version of the labs and verified that it works.
The set of categories defined in a document is managed using the Revit API Categories container class. One nice thing about this class is that it provides keyed access to the categories it contains by either category name or by built-in category enumeration value. In C#, we see the following two overloads:
public virtual Category get_Item( string key ); public virtual Category get_Item( BuiltInCategory categoryId );
In our case, this means that we can use both BuiltInCategory.OST_Doors and "Drawing1.dwg" as identifiers to define the category we are interested in:
static public BuiltInCategory Target = BuiltInCategory.OST_Doors; static public BuiltInCategory Target = BuiltInCategory.OST_Walls; static public string Target = "Drawing1.dwg";
In this simple example, we are using a hard-wired drawing file name. In real life, this would have to be managed more flexibly.
For the full code of the external command class Lab4_3_1_CreateAndBindSharedParam that creates the shared category for an imported drawing file, please look at the corresponding C# file in the Revit API introduction labs provided here.
Is it possible to add shared parameters in a .rfa file using the DotNet Revit API? The example for adding shared parameters to a DWG file does not work for RFA files. Can you please post some sample code for adding shared parameters to an RFA file. Thanks.
Posted by: A. Shankar | December 30, 2008 at 13:48
Hi Shankar, I might address this question in a separate post some time soon. Cheers, Jeremy.
Posted by: Jeremy Tammik | January 05, 2009 at 02:12
Dear Shankar,
I finally got around to addressing this question in a separate post:
http://thebuildingcoder.typepad.com/blog/2009/06/adding-a-shared-parameter-to-an-rfa-file.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 11, 2009 at 04:55
Hi Jeremy, Hi followers,
I'm coding a tool to manage Links to dwg-drawings. One 'routine' Links the dwg files to our Revit model using this Revit-API method:
Document.Link(string file, DWGImportOptions options, View pDBView, out ElementId elementId)
Since Revit 2015 there exists a new ImportOption 'AutoCorrectAlmostVHLines'. This Option can be set via a flag using API commands. I thought this should reflect the behavior of the standard dwg-Import dialog, but the Lines are always adapted to the xy-Grid. Even this method auto corrects.
private ElementId importFile(string file_name, DWGImportOptions opt) {
ElementId e_id = null;
opt.AutoCorrectAlmostVHLines = false;
Transaction t = new Transaction(doc, file_name + ";import dwg");
t.Start();
doc.Link(file_name, opt, doc.ActiveView, out e_id);
t.Commit();
//Element dwg_file = doc.get_Element(e_id);
return e_id;
}
In Version 2013 this auto correct did not exist, so the we just got awre of this. Did anyone else face such problems or does anyone have a good idea how to fix this?
I use Built: 20150127_0715(x64)-Update Release 6
Thnx in advance, Matthias
Posted by: Matthias | April 08, 2015 at 05:19