In one of the previous posts I have shown how to dimension curtain walls with Dynamo and Python. A thread on the Dynamo Forum made me realize that it will not work in case of elements coming from linked documents.
In order to create a new dimension line by script in Revit we have to prepare first a reference array – a list of references to all the objects we want to dimension. According to Revit API documentation for linked elements we have to create a special kind of reference- a LinkedReference. Like so:
linkedReference = obj.Reference.CreateLinkReference(linkedInstance)
Where “obj” is our dimensioned object and “linkedInstance” is an instance of the linked document. Unfortunately references created like this throw an error in Dynamo.
Further investigation led me to another thread on Autodesk forums, where a solution to this problem has been proposed – in C# though. So I have tried to translate it into Python code, that could work within Dynamo.
This is a helper function that would “fix” the reference:
def parseLinkedReference(doc, linkedRef): reps = linkedRef.ConvertToStableRepresentation(doc).split(':') res = '' first=True for i, s in enumerate(reps): t = s if "RVTLINK" in s: if(i<len(reps)-1): if reps[i+1]=="0": t = "RVTLINK" else: t = "0:RVTLINK" else: t = "0:RVTLINK" if not first: res = res + ":" + t else: res = t first = False ref = Reference.ParseFromStableRepresentation(doc,res) return ref
And this is how we can use it to dimension curtain wall grids, from a linked file:
refArray = ReferenceArray() doc = DocumentManager.Instance.CurrentDBDocument options = Options() options.ComputeReferences = True options.IncludeNonVisibleObjects = True for id in wall.CurtainGrid.GetVGridLineIds(): objectDoc = wall.Document gridLine = objectDoc.GetElement(id) gridGeo = gridLine.get_Geometry(options) for obj in gridGeo: if isinstance(obj,Line): linkedReference = obj.Reference.CreateLinkReference(linkedInstance) ref = parseLinkedReference(doc,linkedReference) refArray.Append(ref)