Error in getting curve through python

python
dynamo

#1

Hi There

Can anyone suggest what is problem here in my code. See attached images. It says there is some error on line 11. I couldn’t find or understand that error. Please explain.


#2

feed the data to the Python Script node :grin:


#3


#4

You cannot get the centerline of a “list” which your “IN[0]” is (a list of 8 rebars), try to do a loop over the items in your input list.

Essentially IN[0] = {Rebar 211332, Rebar 211334, Rebar 211335 …}
If you insert a loop like: (Insert below instead of your line 11

Rebars = IN[0]

curves = []
for i in range(len(Rebars)):
    curves.append(UnwrapElement(Rebars[i].GetCenterlineCurves(0,0,0)

… and then continue your script from line 12


#5

Thanks for your reply and Suggestion.

i use that program but is’t not working.

See below :point_down::point_down:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
unexpected token 'dynamocurves’


#6

Can you throw me a sample Revit file with the rebars in it so that I can perform a quick test?


#7

TEST.rvt (1.6 MB)


#8

Hi Robert
I guess the reason you want to use the “ToProtoType()” is to convert from Revit Geometry to Dynamo Geometry, although if you check the element type of the rebars as in my screenshot these are “elements” and not geometry. I’ve done this and get’s an output, is this what you desired? If not let me know what your end-goal is :slight_smile:


import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

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

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

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

Rebars = UnwrapElement(IN[0])
dynCurve = []
curves = []
for i in range(len(Rebars)):
    curves.append(Rebars[i].GetCenterlineCurves(0,0,0,0,0))
OUT = curves

This is interesting reading: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#revitapi


#9

Hi Jonathan

As per your instruction & code supplied by you, i am getting output as circled in red. But i want output as shown in blue circle. Can you please provide suggestions on that.


#10

Using the script provided by Einer (which I’m sure is the one you’re using) from this thread on a single rebar in your file i get the following output: Rebar 2d detailing (Like Sofistik)

image

If you wish to get these curves back to a detailcurve you could have a look in this thread:


#11

Hi Jonathan

Yes you are right. It works for single bar but not for multi bars. Please see attached image.

Can you please suggest anything to get same output for multi bars.


#12

Like so:

dynCurve = []
for i in range(len(IN[0])):
    curves = (UnwrapElement(IN[0][i]).GetCenterlineCurves(0,0,0,0,0))
    for curve in curves:
        dynCurve.append(curve.ToProtoType())

If a comment solves your problem please mark that comment as the solution so that others might be helped in the future. And maybe leave a like here and there.


#13

Hi Jonathan

I want sub-list of all archs in single rebar. For an example bar with hook of 180 degrees at both ends will have 3 lines & 2 archs. So i want list of all 5 in output. Can you please suggest a way for that.

Thanks mate…cheers…!!


#14

You could consider something like this:
image

EDIT: updated code to be more efficient.

inCurves = list(UnwrapElement(IN[0]))
outCurve = []
for curves in inCurves:
    dynCurve = []
    for item in curves.GetCenterlineCurves(0,0,0,0,0):
        dynCurve.append(item.ToProtoType())
    outCurve.append(dynCurve)

#15

Can i make it a Curve??


#16

This is a new issue, please create a separate question for that, that is if a poly-curve doesn’t do the job for you.