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

**URL:** <https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134>\
**Category:** Civil 3D\
**Created:** [June 15, 2021, 6:54am UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134 "2021-06-15T06:54:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPS](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@JPS](https://forum.dynamobim.com/u/JPS)\
**Post date:** [June 15, 2021, 6:54am UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/1 "2021-06-15T06:54:48Z")

</div>

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](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/2/0228cb406bac5b405b25e92138b8e6f132600908.png)

---

<div class="post-metadata">

**Author:** ![Assem.Daaboul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/assem.daaboul/32/116900_2.png) [@Assem.Daaboul](https://forum.dynamobim.com/u/Assem.Daaboul)\
**Post date:** [June 15, 2021, 7:56am UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/2 "2021-06-15T07:56:46Z")

</div>

Hi @JPS,

Maybe this will help?

> [@Create corridor surface (python)](https://forum.dynamobim.com/t/create-corridor-surface-python/49010/7):
>
> This should solve your problem:

---

<div class="post-metadata">

**Author:** ![JPS](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@JPS](https://forum.dynamobim.com/u/JPS)\
**Post date:** [June 15, 2021, 8:34am UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/3 "2021-06-15T08:34:31Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/2/b2c3e7fb7c7b1c1dfae9081bde501faf95811ded.jpeg)

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [June 15, 2021, 2:16pm UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/4 "2021-06-15T14:16:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paolo\_Emilio\_Serra1](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/paolo_emilio_serra1/32/12902_2.png) [@Paolo\_Emilio\_Serra1](https://forum.dynamobim.com/u/Paolo_Emilio_Serra1)\
**Post date:** [June 15, 2021, 2:46pm UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/5 "2021-06-15T14:46:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JPS](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@JPS](https://forum.dynamobim.com/u/JPS)\
**Post date:** [June 16, 2021, 7:23am UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/6 "2021-06-16T07:23:27Z")

</div>

Hi Paulo,

Yes, that was the solution.

---

<div class="post-metadata">

**Author:** ![JPS](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@JPS](https://forum.dynamobim.com/u/JPS)\
**Post date:** [June 16, 2021, 10:26am UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/7 "2021-06-16T10:26:36Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/8/880037b1db6ac86889494de9fed1cef15cdd6092.png)

[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)

---

<div class="post-metadata">

**Author:** ![JPS](https://avatars.discourse-cdn.com/v4/letter/j/b4bc9f/32.png) [@JPS](https://forum.dynamobim.com/u/JPS)\
**Post date:** [June 17, 2021, 5:48pm UTC](https://forum.dynamobim.com/t/civil-3d-python-create-tin-surface-output/65134/8 "2021-06-17T17:48:03Z")

</div>

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))
```
