I’m working on a script to create wipeouts based on multiple Civil 3D surfaces. In the first part (as shown in the attached image), I successfully managed to extract the boundaries of the surfaces as closed 2D polylines.
Now, I’d like to extend the script so that it creates wipeouts directly from these polylines. After reading several topics on this forum, I noticed that using [Passthrough, WaitFor][0] could be the solution. I attempted this approach, but I’m not sure if I implemented it correctly.
To simplify debugging, I decided to split the workflow into two scripts for now:
The first script extracts the surface boundaries as 2D polylines.
The second script uses these polylines to create wipeouts.
However, in the second script, I can only get it to work for one polyline at a time. I tried adjusting the Lacing settings, but it didn’t resolve the issue.
Can someone help me? I changed the method from sending the command to using the API. The inputs are a couple of tables with X and Y coordinates. This is the code I’m trying to fix:
# 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')
# 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 *
# The inputs to this node will be stored as lists in the IN variables.
x_coords = IN[0] # List of X coordinates
y_coords = IN[1] # List of Y coordinates
# Get the active document and editor
adoc = Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor
db = adoc.Database
# Check input validity
if len(x_coords) < 3 or len(y_coords) < 3 or len(x_coords) != len(y_coords):
raise ValueError("Se requieren al menos 3 puntos y listas X, Y de la misma longitud.")
# Lock document before modifying AutoCAD
with adoc.LockDocument():
try:
# Start transaction
with db.TransactionManager.StartTransaction() as tr:
# Get Model Space
block_table = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
model_space = tr.GetObject(block_table[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
# Create a collection of 2D points
point_collection = Point2dCollection()
for x, y in zip(x_coords, y_coords):
point_collection.Add(Point2d(x, y))
# Close the shape by adding the first point at the end
point_collection.Add(Point2d(x_coords[0], y_coords[0]))
# Create the Wipeout object
wipeout = Wipeout()
wipeout.SetFrom(point_collection, Vector3d.ZAxis)
# Add the Wipeout to the Model Space
model_space.AppendEntity(wipeout)
tr.AddNewlyCreatedDBObject(wipeout, True)
# Commit transaction
tr.Commit()
# Output handle
OUT = wipeout.Handle
except Exception as e:
OUT = str(e)
import sys
import clr
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry')
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from System.Collections.Generic import Dictionary
adoc = Application.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
from Autodesk.DesignScript.Geometry import *
def get_sample_line_info(sampleLines):
global adoc
global cdoc
output = []
if not sampleLines:
return
if not isinstance(sampleLines, list):
sampleLines = [sampleLines]
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
#for sampleLine in sampleLines:
block_table = t.GetObject(db.BlockTableId, OpenMode.ForRead)
model_space = t.GetObject(block_table[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
point_collection = Point2dCollection()
vals = []
for sam in sampleLines:
point_collection.Add( Point2d(sam.X, sam.Y) )
vals.append(sam.X)
point_collection.Add(Point2d(sampleLines[0].X, sampleLines[0].Y))
wipeout = Wipeout()
wipeout.SetFrom(point_collection, Vector3d.ZAxis)
model_space.AppendEntity(wipeout)
t.AddNewlyCreatedDBObject(wipeout, True)
t.Commit()
return point_collection
OUT = get_sample_line_info(IN[0])