I’m looking for a bit of help in repeating a function for a different object each time.
I’ve essentially been messing around trying Python and the C3D API. I have successfully created a python script which creates an alignment from a selected polyline using the code below. However, I’m having trouble inputting multiple Polylines from a list and looping through these to create multiple alignments. The code I have attached below works but only creates one alignment before returning an error.
Any help with this one would be really appreciated !
# 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') # 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 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 (global variables). adoc = Application.DocumentManager.MdiActiveDocument editor = adoc.Editor def MultipleAlignFromOb(Pl): #Lock the document down with adoc.LockDocument(): #provide access to the drawing database and set it to db with adoc.Database as db: #from the drawing database open a transaction and set it as t with db.TransactionManager.StartTransaction() as t: # Place your code below # assign bt to grabbing the block table id and ask to write to it bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite) #assign btr to grabbing the block tablre record from block table model space and ask to write to it btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) #for the object ID(Polyline) inside the block table record for Pl in btr: #retreive all objects from the transaction and ask to read them. Set it to ObID ObID = t.GetObject(Pl, OpenMode.ForRead) CivilDocument = CivilApplication.ActiveDocument plops = PolylineOptions() plops.AddCurvesBetweenTangents = False plops.EraseExistingEntities = False plops.PlineId = Pl Alignment.Create(CivilDocument, plops, "New Alignment", "", "0", "Design Style LWT", "Standard") # Commit before end transaction #t.Commit() t.Commit() pass return MultipleAlignFromOb Pl = IN # Assign your output to the OUT variable. OUT = [MultipleAlignFromOb(Pl) for i in zip(Pl)]