Alignment and lock using Revit API

Alignment and lock using Revit API

Anonymous
Not applicable
4,886 Views
4 Replies
Message 1 of 5

Alignment and lock using Revit API

Anonymous
Not applicable

I have a Instance created in the project (indicated by red in the sample).

Is there any way to align and lock the grip (1) similarly done with the grip (2) using API?

0 Likes
Accepted solutions (2)
4,887 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Accepted solution

I was involved in a very similar discussion recently, take a look here: http://forums.autodesk.com/t5/Revit-API/Create-Dimension-Get-references-to-FamilyInstances/td-p/4990...

 

Basically, the answer is yes, you can, but as far as I know there is no official API method, you must rely on a workaround (hack) that is not entirely programmatic. Some manual work will be needed to determine the specific reference indexes to be used for each family you want to work with.

 

The method for getting the correct references is explained in my comments to the thread linked above. Once you have the references, pass them into the Autodesk.Revit.Creation.Document.NewAlignment() method to create your alignment lock.

0 Likes
Message 3 of 5

Anonymous
Not applicable

By the method above I can get these reference plans ?

0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

Step 1.

 

To get the indexes of the reference planes you need to create an instance of the family in a project file and manually add a dimension to them using the UI.

 

You then need to write an API command that can read out the actual references that the dimension is attached to. Dump these out as text using Reference.ConvertToStableRepresentation().

 

You'll get something that looks like:

 

66a421da-90cb-4df2-8efe-c312e4f78aa0-0003d32b:0:INSTANCE:a2177cbb-03d8-4416-a4d8-8ada6fc0165a-0003ebf0:2:SURFACE

 

The last digit (2) is the reference index (or id? not sure I'm just making this stuff up as I go). This is what you will need to record so that you can use it later.

 

Step 2.

 

Now, use this information to add a dimension / alignment to this reference using the API, you will need to take an instance of the family and extract some geometric faces. Be sure to set compute references in your geometry options and use GetSymbolGeometry while extracting.

 

Once you have a face, dump out it's reference using Reference.ConvertToStableRepresentation(). Take the reference string and substitute in the index number you found earlier. You can now build a reference using Reference.ParseFromStableRepresentation() which can be used to add a new dimension.

 

Done.

 

For any particular family you should only have to do the 1st manual step of extracting the index once and it will hold stable for any instance of that family. This hasn't been extensively tested so keep an eye on it, I am unsure whether minor mods to a family change the index values, but I'm sure that if someone were to delete the reference plane from the family and insert another in its place, the index would become invalid.

 

The second step can be automated, but I'm sure there will be a few gotcha's in there somewhere for nested and otherwise complex families.

 

Revit API programming, gotta love it sometimes 🙂

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks for the detailed explanation!

 

Now I got to do!

0 Likes