OUT shows null

I created a little script to transform 3D polylines of a CAD link to ducts:

The custom node looks like that:

I have the following code in the custom node:

import clr

clr.AddReference("RevitNodes")
import Revit

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

from Autodesk.Revit.Creation import *
clr.ImportExtensions(Revit.GeometryConversion)

from Revit.Elements import *

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

import System

	
doc = IN[0]	
l = IN[1]
k = IN[2]
ducttype = IN[3]	
systemtype = IN[4]
level = IN[5]
diameter = IN[6]

elements = []	

TransactionManager.Instance.EnsureInTransaction(doc)

for i,j in zip(k,l):
	try:
		x= i.ToXyz()
		y= j.ToXyz()	
		duct = Duct.Create(doc, ElementId(systemtype.Id), ElementId(ducttype.Id), ElementId(level.Id), x, y)
		
		param = duct.get_Parameter(BuiltInParameter.RBS_CURVE_DIAMETER_PARAM)
		param.SetValueString(diameter.ToString())
	
		elements.append(duct.ToDSType(False))	
	except:
		elements.append(None)
	
TransactionManager.Instance.TransactionTaskDone()
OUT = elements

The nodes seem to be created for the ducts but for some reason the ducts itself do not get created. The output allways shows “NULL” as well.
Any idea why this could be the case?

Probably to do with your lacing. Try set to longest.

Also, instead of appending None to Elements if there is an exception, try the following…

except Exception, ex:
		elements.append(ex.message)

This should help you understand where it is failing.

Hello @Alex_AT_UK
a few comments

  • missing import (ToDSType(bool) extension method)
  • to get current doc prefer use : doc = DocumentManager.Instance.CurrentDBDocument
  • need to UnwrapElement yours inputs to expose them at the Revit API (no need to convert Id)

read this :wink:

and if it’s possible avoid the try except (unless you have no other solution) :slight_smile:

2 Likes

Before diving in create your custom node, always make sure the python script works first the design graph environment.

Some errors i found while reading your python script:

  1. diameter is a number, not a string. So your ToString() of diameter will definition make your script fail.
  2. you did not import the extension of ToDSType(), so your script will fail as well

Some pointers:

  1. do not use try and except UNLESS you wanna raise your own exception to find out the exact root cause with your own warning message OR you really have no choice
  2. use UnwrapElement() extension method to retrieve Revit element from dynamo’s element instead of going one big round like what you did there.
  3. alway label your variable (be it abbr or short description). Its for better readability especially when you are asking the public for help :slight_smile:
2 Likes