The python code below creates a (tin)surface, but the output is not the correct format, which can be used in following nodes, for example the Civil3d Toolkit node “TinSurfaceExtensions.AddStandardBreaklines”.
How do i get the right output format?
[Code]
The inputs to this node will be stored as a list in the IN variables.
#Surfaceslst =
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)
# Select a Surface style to us
styleId = cdoc.Styles.SurfaceStyles[styleName]
# Create an empty TIN Surface
surfaceId = TinSurface.Create(surfaceName, styleId)
newSurface.append (surfaceId)
# get Object
surface = t.GetObject(surfaceId, OpenMode.ForRead)
# Commit before end transaction
t.Commit()
pass
Your suggestion works. But i want to use the created surface in the python node in the node “TinSurfaceExtensions.AddNonDestructiveBreaklines”. That won’t work.
A simple solution would be to use the OOTB node to select the surface by name after it’s been added to the database. That would get you the Autodesk.Civil.DynamoNodes object type instead of the Autodesk.Civil.DatabaseServices type.
You could actually do this directly form Python if you use Autodesk.AutoCAD.DynamoNodes.SelectionByQuery.GetObjectByObjectHandle(str(surfaceId .Handle))
[Code]
def selSurface(surfaceName):
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:
surface = SelectionByQuery.GetObjectByObjectHandle(str(surfaceId.Handle))
return surface
newSurface =
if deleteSurface == False:
newSurface = selSurface(surfaceName)
I found the solution, i was missing the commit before making the selection.
[code]
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