Spot Elevation nod - problem with referencing elements

Hi all,

I am still begginer both at Dynamo and Phyton, and i have been trying to make the script for placing Spot Elevations on ducts, cable trays and pipes and it all works well with rectangular ducts and cable trays, but it wont work with round ducts and pipes. I am using Clockwork’s SpotElevation.ByPoint node. After trying various kind of inputs to the node with no success, i started looking into the code and i think that the problem is with referencing elements (lines 30,32). I tried playing with it and changing members of FindReferenceTarget to edge,all,element and curve with various input points from the pipe but i cant make it to work. I will attach one simple example of the script. Hope someone can help me out with this.

Tag - Spot Elevation.dyn (12.6 KB)

Thanks in advance for any help you could provide.

    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
views = UnwrapElement(IN[0])
pts = UnwrapElement(IN[1])
bend = UnwrapElement(IN[2])
end = UnwrapElement(IN[3])
leader = UnwrapElement(IN[4])
isoview = UnwrapElement(IN[5])
intsecvec = UnwrapElement(IN[6])
elementlist = []

i = 0;
TransactionManager.Instance.EnsureInTransaction(doc)
for pt in pts:
	view = views[i]
	pt = pt.ToXyz()
	refintsec = ReferenceIntersector(isoview)
	refintsec.TargetType = FindReferenceTarget.Face
	try:
		ref = refintsec.FindNearest(pt,intsecvec[i].AsPoint().ToXyz()).GetReference()
		elementlist.append(doc.Create.NewSpotElevation(view, ref, pt, pt.Add(bend.AsPoint().ToXyz()), pt.Add(end.AsPoint().ToXyz()), pt, leader))
	except:
		elementlist.append(None)
	i += 1
TransactionManager.Instance.TransactionTaskDone()

OUT = elementlist

Could edit your message and replace the code with the proper formatting? Only the first line had formatting so it’s very difficult to tell how everything is being sequenced.

@cgartland i think i got it now. Also added a dynamo script.

1 Like

Although I don’t have any specific guidance or experience with creating spot elevations through the API, I would start with reorganizing the code you copied from the node. The way it is currently organized makes it difficult to debug, mainly due to the following bit:

try:
	ref = refintsec.FindNearest(pt,intsecvec[i].AsPoint().ToXyz()).GetReference()
    elementlist.append(doc.Create.NewSpotElevation(view, ref, pt, pt.Add(bend.AsPoint().ToXyz()), pt.Add(end.AsPoint().ToXyz()), pt, leader))
except:
	elementlist.append(None)

You can start by removing the try and except blocks. The way it is currently structured, it will try absolutely everything and catch any and all exceptions (and will not raise any exceptions, which is why you’re having difficulty modifying it yourself).

Did you get this sorted?