Python Code to Draw Object in Civil3D Dwg

Hi everyone,

I am currently learning how to use Python in Civil 3D Dynamo, and I am trying to perform a very simple task — to draw two points and a line between them using Python.

However, after several attempts, I’m still unable to make it work. I’m using Autodesk Civil 3D 2025, and I have attached my Python script for reference.

Could someone please review the code and help me correct it so that it can successfully draw the points and the line in Civil 3D?

I would be very grateful for your kind help and guidance.

Best regards,
Babulal Sahu

Sample Code.txt (2.1 KB)

What error are you running into?

Dear Jacob, thank you for your reply.

Since I did not find a way to copy the error text, I have attached an image.


-

I have checked the Book by Anton Huizinga. I assume that using the Design Script code of the nodes/functions in Python for drawing objects in DWG does not work. I have to follow C# syntax in Python code to draw objects in DWG.

I am trying my first Python code in Dynamo Civil3D to draw objects in DWG. I hope I will be able to do it soon, after reading the book by Anton Huizinga.

Hi,

Try to catch the right error.

  • Avoid using the key with a .Net disposable object.
  • Use a context manager instead.

Example here.

1 Like