Import Polyline from Autodesk.DesignScript

Hi,

I am going to create Polylines by Python scripts in Dynamo, the code of below does not work for me.

from Autodesk.DesignScript.Geometry import Polyline as DynPline

I have searched Dynamo Dictionary (dynamobim.com) and found there is not Polyline there and I don’t know why. As you know Polyline.ByPoints node works in Dynamo.

I have also searched “Polyine” in DesignScript catagory in this forum and no luck.
Could anyone please point me the right direction? Thank you!

I am using Civil 3D 2024 by the way and I succefully imported Point to my scripts and it’s working

Hi, I don’t have Civil
but if you do parallel with DynamoForRevit
by selecting help on the node you have information on its location

maybe this can help
cordially
christian.stan

To expand on what @christian.stan indicated.

A PolyLine is an AutoCAD object type, and as such cannot be used in the context of Dynamo’s Geometry library.

A PolyCurve is a Dynamo geometry type, and as such can be used in the context of Dynamo’s Geometry library.

So you may want to try this as your import:
from Autodesk.DesignScript.Geometry import *

If you also need to use the Revit API or Civil 3D API in the same node (and therefore need a class name to keep namespaces descrete) I recommend using this:
import Autodesk.DesignScript.Geometry as DG

You can then all any Dynamo geometry class using DG., such as lines (DG.Line), vectors (DG.Vector) and PolyCurves (DG.PolyCurve). This would make your polycurve constructor call DG.PolyCurve.ByPoints(dynamoPoints), and your points would become DG.Point.ByCoordaintes(x,y,z).

2 Likes

Hi @christian.stan ,

Thank you very much for you help, especially about how to find more information by " selecting help", appreciate it.

I am trying to use PolyCurve instead of Polyline according to your help, not finally get it worked for me though. I guess it’s because of syntax.

1 Like

Hi @jacob.small

Thank you so much for your kind detailed explaination, it helps a lot. I am trying to use PolyCurve however Dynamo&C3D keep crashing.

It’s frustrating that everytime it crashes I have to reboot C3D not just Dynamo, same crashing happens on both 2022 and 2024.

image

image

image

I finally got it worked for me.

I was thinking to create Polylines in C3D model space by Python Script, however I didn’t have to. I just need to get correct list of Points lists in Python Scripts and transfer them to Dynamo Polyline node, then Polyline node would help me to create Polylines in C3D.

I figured out sevral things anyway.

  • Python Scripts crashes C3D very very very very … easily by only wrong Syntax, very fragile. For example I typed “true/Ture” instead of “True” in PolyCurve(), C3D got crashed. I have to reboot C3D instead of just Dynamo.
    image

  • Very important concepts for newbie like me: Creating Geomery whinin Python Scripts does not effects in Dynamo until you OUT it, which means, OUT=your geomery.

Need help on questions:

How to create Geomery into C3D directly within Python Scripts, I will read some help on https://primer2.dynamobim.org/ to find more later on but very much appreciate if anyone could please point me the right direction.

I also could have gotten ChatGPT to help me however I am thinking it’s hopeless to get it veryfied in so fragile environment of C3D+Dynamo+Python Scripts. I don’t mind reboot C3D however it is so time consuming…

Thanks in advance

Generally speaking for support of Python scripts it is best to provide the code snippet to reproduce the issue.

When sharing said code be sure to use the pre-formatted text option (in the gear options for text formatting, select </> and then past the code between the demarcation symbols).

Thanks @jacob.small for your advice, yes have been using the pre-formatted text option as what I did in my initial post.

So far I did not expect C3D is sooooo easily got crashed by just maybe a simple syntax of Python scripts, soooo frustratiing and time wasting

Usually the issues are caused by inappropriate interactions with the document which would otherwise cause corruption. This is why when sharing code we need the larger context of the issue shared as the preformatted text, not just the single line. Glad you’re squared away though. :slight_smile:

Thank you Jacob.

I have been thinking share my code to you guys, however it was too simple as below:

polycurves.append(DG.PolyCurve.ByPoints(points,True))

Incorrect typing like “ture” or “Ture” can cause C3D to crash. I knew it was the exact reason as everything would be fine if I comment this line out.

As it’s so simple a syntax error, that’s why I think the environment is so fragile.

Anyway I would share my code next time just in case some enssential reasons could have been covered in simply codes that I did not know.

Again, thank you very much for your time and help, have a great day!

1 Like