This week I should be recording the VBA migration guide DevTV in German, and once again I cannot keep away from blogging instead. This is just a short and sweet little support case that I thought worth while describing for the general public:
Question: I am interested in the possible values of some specific parameters whose storage type is ElementId. One of them is the 'Start Connection' parameter on beams. If I want to set that parameter to something, I need the appropriate element id. Are there any enumerations like the built-in parameters that would help me determine the element id I need to use, for example, to set the Start Connection to 'Cantilever Moment Connection'?
I tried determining the proper value to use by setting it manually through the user interface and then retrieving it through the API. That returned an element id like 233422, which makes me think that there should be a cleaner way.
Answer: If the element id is positive, I would assume that it refers to a real element in the Revit database. Element ids that do not refer to real existing elements in the database are generally negative.
To test this in the user interface and RevitLookup, you can simply go to Manage > Inquiry > Select by ID, type in the element id you have obtained, e.g. 233422, and examine its type and other properties in RevitLookup by selecting Add-Ins > Revit Lookup > Snoop Current Selection...
I searched a randomly selected Revit Structure model on my system for an element named 'Cantilever Moment Connection' and could not find any, but there are some other interesting elements that seem to me like they may be similar to what you are looking for (copy to an editor if the lines are truncated):
Id=137086; Class=StructuralConnectionType; Name=Moment Frame; Id=137087; Class=StructuralConnectionType; Name=Cantilever Moment; Id=137088; Class=StructuralConnectionType; Name=Shear Column Connection; Id=137089; Class=StructuralConnectionType; Name=Moment Column Connection; Id=137090; Class=StructuralConnectionType; Name=Base Plate Symbol;
These are normal Revit elements of the class or System.Type StructuralConnectionType, which is derived from the Revit Element class. Their Category property is null, so we cannot use that to identify them.
I suspect that your 'Cantilever Moment Connection' object may be such an element as well.
If so, you can use the StructuralConnectionType class to filter for them, and the element Name property to determine each such object's name.
dear Jeremy Tammik
where from could I get the ids of path reinforcement parameters such as : "Primary Bar - Start Hook Type " :None
and Face :("Exterior" and "Interior")
for example : i want to change "face" of Path Reinforcement Object by code to make it "Exterior" insted of "Interior" where could i find Exterior parameter ID?
thanks you
Posted by: BASIL | February 19, 2011 at 08:16
Dear Basil,
As so often when exploring how to automate things in Revit, you will probably need to explore some of this for yourself interactively. Create a sample model and toggle the features you are interested in on and off manually through the user interface. At the same time, check what parameters are affected by analysing the model using RevitLookup. That should provide all the answers you need.
I did notice that the Revit Structure 2011 API introduced a new NewRebarHookType method:
http://thebuildingcoder.typepad.com/blog/2010/05/the-revit-structure-2011-api.html
I also once had a conversation on setting the rebar end hook parameters using
BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE and BuiltInParameter.REBAR_ELEM_HOOK_END_TYPE. If you set them to new ElementId( -1 ), you can simulate setting them to End Hook “None”. Here is the code we looked at back then:
transaction.Start( "Turn Off End Hook 1" );
Parameter hookStartParam = rebar.get_Parameter(
BuiltInParameter.REBAR_ELEM_HOOK_START_TYPE );
ElementId oldId = hookStartParam.AsElementId();
hookStartParam.Set( new ElementId( -1 ) );
transaction.Commit();
transaction.Start( "Turn Off End Hook 2" );
Parameter hookEndParam = rebar.get_Parameter(
BuiltInParameter.REBAR_ELEM_HOOK_END_TYPE );
ElementId oldId = hookEndParam.AsElementId();
hookEndParam.Set( new ElementId( -1 ) );
transaction.Commit();
I hope this helps.
Cheers, Jeremy.
Posted by: Jeremy Tammik | February 19, 2011 at 11:55
Hi Jeremy
When I create a new moment connection type.(for example new symbol for RBS Moment Frame) a new StructuralConnectionType Id is generated randomly by Revit.(something like 3975667)
Are there anyway to make the Id state the same?
Thanks
Posted by: Sarkate | April 07, 2015 at 14:10
Dear Locost7,
The StructuralConnectionType element id is probably not generated randomly.
Instead, I imagine that Revit is generating a new StructuralConnectionType element for you, and that is its element id.
You can check this by using the element lister:
http://thebuildingcoder.typepad.com/blog/2014/09/debugging-and-maintaining-the-image-relationship.html#2
You can also simply snoop the current database in RevitLookup and manually check whether a new StructuralConnectionType element has been added.
If the newly generated StructuralConnectionType element is identical to another StructuralConnectionType element that you already have in your project and would like to reuse, you can probably do so through the following steps:
1. Make a note of the newly generated element id X.
2. Determine the element id Y of the StructuralConnectionType that you would like to reuse for your new moment connection type Z.
3. Assign Y to Z, e.g. using the Element.ChangeTypeId method.
4. Delete X, e.g. using the Document.Delete method.
I hope this helps.
Please let us know how you end up solving this.
Thank you!
Cheers, Jeremy.
Posted by: Jeremy Tammik | April 07, 2015 at 15:50
Thanks for your reply Jeremy
I think I was thinking in a wrong direction when I was asking for help.
Actually I’m trying to write a code to assign Start/End Connection. To do this I need to
set new ElementID to the build in parameter. In this case a different ElementID mapping can be problematic. But I just found out there is no need to make the ElementID state the same. My solution is to retrieve the ElementID from the name of the Connection Type.
//Get Parameter:
BuiltInParameter.STRUCT_CONNECTION_BEAM_START
//filter by the StructuralConnectionType class
foreach (Element ConnType in new FilteredElementCollector(doc)
.OfClass(typeof(StructuralConnectionType))
.Cast()
.Where( m => m.Name.Equals("Moment Frame RBS")))
// Get ElementID and Convert to integer:
string NewId = ConnType.Id.ToString();
int idInt = Convert.ToInt32(NewId);
p.Set(new ElementId(idInt));
The key is to make sure the name is always the same for every project.
so now what I planing to do is to write a code to create the new Structural Connection Types instead of make them in the Structural Setting Panel manually. But somehow I got stuck on the StructuralConnectionType.Create Method. I’m not able to find any code snippets yet.
any suggestion for my solution?
BTW I just replaced my temporary username Locost7 to Sarkate which match the one I use in the official Autodesk API forum.
Thanks
Posted by: Sarkate | April 09, 2015 at 02:15