Civil 3D - Python- create (tin)surface - Output

Hi all,

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.

surfaceName = IN[0]
styleName = IN[1]

adoc = Application.DocumentManager.MdiActiveDocument

Surfaces =

#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

Assign your output to the OUT variable.

OUT = surface

[Output]
image

1 Like

Hi @JPS,

Maybe this will help?

Hi Assem,

Your suggestion works. But i want to use the created surface in the python node in the node “TinSurfaceExtensions.AddNonDestructiveBreaklines”. That won’t work.

Hi @JPS,

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.

1 Like

You could actually do this directly form Python if you use Autodesk.AutoCAD.DynamoNodes.SelectionByQuery.GetObjectByObjectHandle(str(surfaceId .Handle))

3 Likes

Hi Paulo,

Yes, that was the solution.

Now i have an other question. If i set it false then i’m getting and error. How can i solve this?

[Node purpose]
Boolean {deleteSurface}

  • True => delete and create surface
  • False => select surface

[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

  •           t.Commit()*
             surface = SelectionByQuery.GetObjectByObjectHandle(str(obj.Handle))