Help with Python Script for Autocad

I am really new to Python and trying to create while loop in Python script node of Dynamo. bellow is my efforts without any knowledge of python and basic search on google for while loop. so pardon me if its full of mistakes and errors, it would be really great if someone can guide me to get this sorted.

attached dyn for reference.ttr_test.dyn (31.7 KB)

1 Like

hello @shahid.shaikh_C3D
try to add a tab


read this

1 Like

Thanks for the reply @c.poupin. though it will be difficult for me to understand this coding language, took some baby steps as per the article and corrected the script. still seems i am way out of track ? apart from indent do you think anything else needed in the code or workflow is correct ?


ttr_test.dyn (31.8 KB)

1 Like

hello @shahid.shaikh_C3D
you are defined 2 alias you can use them

1 Like

Hi @c.poupin Apologies for the late reply…
took some time and help and worked on the script …good news is its working now, but it wont exit the loop and never complete the run.

Please suggest if it can update the loop somehow

1 Like

Hi @shahid.shaikh_C3D,

If you want to simplify things, you could remove lines 59-74. They are for handling transactions with the AutoCAD/Civil 3D database via the API, which doesn’t appear to be your goal.

2 Likes

hello @shahid.shaikh_C3D
a simple example to create a circle in Civil3D from a Dynamo Geometry

# Load the Python Standard and DesignScript Libraries
import sys
import clr

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry')

# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *

import Autodesk.DesignScript.Geometry as DS

# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
center = IN[0]
#create a proto Geometry
circleDs = DS.Circle.ByCenterPointRadius(center, 50)
with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # Place your code below
            # 
            #
            acBlkTbl = t.GetObject(db.BlockTableId, OpenMode.ForRead)
            acBlkTblRec = t.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],  OpenMode.ForWrite)
            acCirc = Circle()
            acCirc.Center = Point3d(circleDs.CenterPoint.X, circleDs.CenterPoint.Y, circleDs.CenterPoint.Z)
            acCirc.Radius = circleDs.Radius
            acBlkTblRec.AppendEntity(acCirc)
            t.AddNewlyCreatedDBObject(acCirc, True)
            # Commit before end transaction
            t.Commit()
            

# Assign your output to the OUT variable.
OUT = circleDs
1 Like

@c.poupin thanks for reply…its not a simple circle. if you look at the code, its trying to find the center and radius from a loop and at the moment its not exiting loop.

1 Like