TinSurface from 3D Faces

Hi @JPhil,

To get the edges and vertices from the Faces, you would do something like this:

However, it will be a very heavy set of operations to deconstruct the faces into vertices and edges and then build the TIN Surface from COGO Points and breaklines. It will be much faster to build the surface from the faces directly using the API. Here’s some code for you to try out in a Python node.

import clr

clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('AutoCADNodes')
clr.AddReference('Civil3DNodes')   

from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
import Autodesk.AutoCAD.DynamoNodes as DA
import Autodesk.Civil.DynamoNodes as DC

adoc = Application.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument

def create_tin_by_faces(surfaceName, faces):

    if surfaceName is None or faces is None:
        return
    
    if not isinstance(faces, list):
        faces = [faces]
    
    global adoc
    global cdoc

    with adoc.LockDocument():
        with adoc.Database as db:    
            with db.TransactionManager.StartTransaction() as t:
                surfId = TinSurface.Create(db, surfaceName)
                surf = t.GetObject(surfId, OpenMode.ForWrite)
                surfDwgObjs = surf.DrawingObjectsDefinition
                faceIds = ObjectIdCollection()
                for face in faces:
                    faceId = face.InternalObjectId
                    faceIds.Add(faceId)
                surfDwgObjs.AddFrom3DFaces(faceIds, True, "")
                t.Commit()
                pass
    return DC.Selection.SurfaceByName(surfaceName, DA.Document.Current)

OUT = create_tin_by_faces(IN[0], IN[1])
6 Likes