Revit crash Issue found in auto dimension visual script


I have created above program to create auto dimension element to element.But if I run this program in assembly view revit get crashed.Is there any alternative node of familyinstance references.

I believe I had the same problem and ended up revamping the code. You will have to input the names of the references that you are wanting to get.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

#Preparing input from dynamo to revit
elements = UnwrapElement(IN[0]) if isinstance(IN[0],list) else [UnwrapElement(IN[0])]
refnames = IN[1]

reference=[]
planes=[]
names=[]

TransactionManager.Instance.EnsureInTransaction(doc)

for e in elements:
	for rf in refnames:
		refs = e.GetReferenceByName(rf)
		if refs is not None:
			reference.append(refs)		
			for r in reference:
				name = (e.GetReferenceName(r))
			names.append(name)

for ref in reference:
	sketchPlane = SketchPlane.Create(doc, ref)
	planes.append(sketchPlane.GetPlane().ToPlane(True))
	

TransactionManager.Instance.TransactionTaskDone()


OUT = reference, planes, names
2 Likes

Thanks @staylor as you provided python script now I found references properly.


There is issue that I am not able to separate out list of (Center left/right) Revit db reference.I have tried index of for that but not working properly.

Two options. Easiest, have two separate python scripts and input one reference name into each one. Or use the output of the reference names to create a boolean return (ex. List.Contains “Left”) then use those boolean results to filter the references list.

Hi,

The FamilyInstance Reference ByName node already separates the list of references by name.
A list.GetItemAtIndex will get the chosen reference list.

3 Likes

Hey @Alban_de_Chasteigner
I actually used that same node in 2022 and got the issue with crashing. So that’s why I ended up revamping the code. I also added that to a custom node to get the same outputs.

Hey @Mahesh14tapkir
If you want to get the same outputs as the FamilyInstance Reference.ByName, you can take the code that I provided and create your own custom node as shown below.

Can we get references location in dynamo as like get element location?

To help clarify, the references “Center (Left/Right)”, “Center (Front/Back)” and “Center (Top/Bottom)” are the main default reference planes in the element family. These are the same references being pulled by the “Family Instance References” node that you were originally using. So where they are located is based on the elements location in the family in relation to those main reference planes. Additionally you can add reference planes in the element family, where ever you want and you can name them. The code provided allows you to pull the references by their name. So you can actually set up the family to have dimensions pulled from any point (i.e. the center (insertion point) or from any edge. When placing reference planes in the family to be used for dimensioning, you have to keep in mind what the view direction of the element will be in the project view that you will be placing dimensions. If they are not co-planer, the dimension will be created, but will not show up in the view. Common problem being posted a lot in the forum.

To answer your question directly, the code returns reference planes in conjunction with the references, so you can get the location of the reference planes.

Hi,

Thanks for the feedback.
You or @Mahesh14tapkir, can you provide me with a stripped sample Revit file with the name of the family that causes the crash? I am not able to reproduce this behavior and this would allow me to improve the custom nodes.
Thanks.

I will see if I can recreate and provide to you. I do remember that it only happened when pulling references of an assembly and it seemed to happen if I ran the script made a change in another part of the script, saved and then ran again without closing the script. So not sure if element binding had any impact on the issue or not.

1 Like

@staylor you are right.I experienced crashing problem only for assembly but as you provided above script it works very smoothly.@Alban_de_Chasteeigner you can update the node accordingly.

We put dimensions in assembly but due to some co-linear elements and its col-linear references we get “0” value of dimensions. Can any dynamo node keep only one element reference for that col-linear elements?

Not that I am aware of. I use the reference plane locations to group the references and then just pull one of those from the results. Reference planes are fed into the Plane Origin and References are fed into the List.GroupByKey. There may be better methods, but this seems to work well enough
.

Code for “Result from Vector Check” node

import clr

vect = IN[0]
px = IN[1]
py = IN[2]
pz = IN[3]

vx = round(vect.X)
vy = round(vect.Y)
vz = round(vect.Z)

if vx != 0:
	result = px
elif vy != 0:
	result = py
else:
	result = pz

OUT = result

In which package We will get Point.Deconstruct?

It’s from WombatDynamo. You can also use a codeblock as shown below.