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.
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 ?
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.
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.
# 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
@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.