I’m trying to learn how to create nodes, from python, following the references to posts that were previously made, why the error?
import sys
import clr
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import*
from System.Collections.Generic import IList, List
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
# dynamo curves as input
curves = UnwrapElement(IN[0])
rebar_style = UnwrapElement(IN[1])
rebar_bar_type = UnwrapElement(IN[2])
start_hook_type = UnwrapElement(IN[3])
end_hook_type = UnwrapElement(IN[4])
start_hook_orientation = IN[5]
end_hook_orientation = IN[6]
host_element = UnwrapElement(IN[7])
vector = IN[8]
def CreateRebarFromCurve(curves, rebar_style, rebar_bar_type, start_hook_type, end_hook_type, start_hook_orientation, end_hook_orientation, host_element, vector):
rebars = []
TransactionManager.Instance.EnsureInTransaction(doc)
for c, v in zip(curves, vector):
curv = List[Curve]()
curv.Add(c.ToRevitType())
rebar = Rebar.CreateFromCurves(doc, rebar_style, rebar_bar_type, start_hook_type, end_hook_type, host_element, v.ToRevitType(), curv, start_hook_orientation, end_hook_orientation, True, False)
rebars.append(rebar)
TransactionManager.Instance.TransactionTaskDone()
return rebars
OUT = CreateRebarFromCurve(curves, rebar_style, rebar_bar_type, start_hook_type, end_hook_type, start_hook_orientation, end_hook_orientation, host_element, vector)
Hi
the error indicates that you are trying to iterate on a non-iterable object
Check that curves
and vector
are input lists of the same size
or
just use a for-loop (instead zip() )on the curves object and use vector
(type conversion to be done) directly in the Rebar.CreateFromCurves()
method.
2 Likes
I’ve checked the list curve, right
rebar Python.dyn.rvt (7.5 MB)
Rebar Python.dyn (27.0 KB)
Good morning
you are missing:
import System
in your code
Sincerely
christian.stan
Hi,
you must analyze the error message, in this example there is a problem with several object types passed as arguments that do not match with the Revit API.
here the fixed code
import sys
import clr
import System
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
from System.Collections.Generic import IList, List
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
doc = DocumentManager.Instance.CurrentDBDocument
# dynamo curves as input
curves = UnwrapElement(IN[0])
rebar_style = System.Enum.Parse(RebarStyle, IN[1])
rebar_bar_type = UnwrapElement(IN[2])
start_hook_type = UnwrapElement(IN[3])
end_hook_type = UnwrapElement(IN[4])
start_hook_orientation = System.Enum.Parse(RebarHookOrientation, IN[5])
end_hook_orientation = System.Enum.Parse(RebarHookOrientation, IN[6])
host_element = UnwrapElement(IN[7])
vector = IN[8]
def CreateRebarFromCurve(curves, rebar_style, rebar_bar_type, start_hook_type, end_hook_type, start_hook_orientation, end_hook_orientation, host_element, vector):
rebars = []
TransactionManager.Instance.EnsureInTransaction(doc)
for c, v in zip(curves, vector):
curv = List[Curve]()
curv.Add(c.ToRevitType())
rebar = Rebar.CreateFromCurves(doc,
rebar_style,
rebar_bar_type,
start_hook_type,
end_hook_type,
host_element,
v.ToRevitType(),
curv,
start_hook_orientation,
end_hook_orientation,
True,
False)
rebars.append(rebar)
TransactionManager.Instance.TransactionTaskDone()
return rebars
OUT = CreateRebarFromCurve(curves, rebar_style, rebar_bar_type, start_hook_type, end_hook_type, start_hook_orientation, end_hook_orientation, host_element, vector)
2 Likes
It turns out that the string must be converted, yes, I think at the beginning he can read string data ,
Sorry mr, I tried again, by create a rebar curve stirrup, showing an EOF error, but I tried to make the standard rebar successful, why?
ikhsan.pc:
showing an EOF error
check the end of your script, missing parenthesis or missing quotes
1 Like