Hi all,
The last code sample does work, but i had the next code working in C3D 2021, in 2022 it’s not working anymore. Does anyone has a solution?
The lines
- styleId = cdoc.Styles.SurfaceStyles[styleName]
- surfaceId = TinSurface.Create(surfaceName, styleId)
don’t work anymore
Load the Python Standard and DesignScript Libraries
import sys
import clr
import math
Add Assemblies for AutoCAD and Civil 3D APIs
clr.AddReference(‘AcDbMgd’)
clr.AddReference(‘AeccDbMgd’)
clr.AddReference(‘AutoCADNodes’)
clr.AddReference(‘Civil3DNodes’)
Import references from AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
Import references from Civil3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
import Autodesk.AutoCAD.DynamoNodes as DA
import Autodesk.Civil.DynamoNodes as DC
#Import References from dynamo
from Autodesk.AutoCAD.DynamoNodes import SelectionByQuery
The inputs to this node will be stored as a list in the IN variables.
surfaceName = IN[0]
styleName = IN[1]
MaximumTriangleLength = IN[2]
MaximumAngleBetweenAdjacentTinLines = IN[3]
deleteSurface = IN[4]
adoc = Application.DocumentManager.MdiActiveDocument
def delSurface(surfaceName):
global adoc
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
cdoc = CivilApplication.ActiveDocument
# list of existing Surfaces
SurfaceIds = cdoc.GetSurfaceIds()
for surfaceId in SurfaceIds:
oSurface = surfaceId.GetObject(OpenMode.ForRead)
if oSurface.Name == surfaceName:
myEnt = t.GetObject(surfaceId, OpenMode.ForWrite)
myEnt.Erase(True)
# Commit before end transaction
t.Commit()
def selSurface(surfaceName):
global adoc
surface = “”
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
cdoc = CivilApplication.ActiveDocument
# list of existing Surfaces
SurfaceIds = cdoc.GetSurfaceIds()
for surfaceId in SurfaceIds:
oSurface = surfaceId.GetObject(OpenMode.ForRead)
if oSurface.Name == surfaceName:
obj = t.GetObject(surfaceId, OpenMode.ForRead)
# Commit before end transaction
t.Commit()
surface = SelectionByQuery.GetObjectByObjectHandle(str(obj.Handle))
return surface
#==============================================================================================
Boolean {deleteSurface}
True => delete surface and create new surface
False => Select surface
#==============================================================================================
newSurface =
surfaceId=""
styleId=""
if deleteSurface == False:
newSurface = selSurface(surfaceName)
if deleteSurface == True:
delSurface(surfaceName)
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
cdoc = CivilApplication.ActiveDocument
print(“Start - Create surface”)
# Select a Surface style to use
styleId = cdoc.Styles.SurfaceStyles[styleName]
print(styleId)
# Create an empty TIN Surface
surfaceId = TinSurface.Create(surfaceName, styleId)
print(surfaceId)
# get Object
surface = t.GetObject(surfaceId, OpenMode.ForRead)
#newSurface.append (surface)
#surfId = TinSurface.Create(db, “test”)
#surf = t.GetObject(surfId, OpenMode.ForWrite)
# Commit before end transaction
t.Commit()
pass
newSurface = SelectionByQuery.GetObjectByObjectHandle(str(surfaceId.Handle))
Assign your output to the OUT variable.
OUT = newSurface