Hi,
I’m trying to export multiple LandXML fails from one dwg fail with Dynamo. There is an requirement that we have to export every single pavement surfaces to different landXML. I’m trying to create a dynamo script that will help me first of all identify all the tin surfaces in modelspace, secondly find the find all surfaces with similar pavement name and regroupe them under the right name. After that it has to export all the tin surfaces with a correct LandXML fail name to a specific folder. I have done the first two parts with an ease, but struggling to export the surfaces into landXML. I used chatGPT to make a custom Python node, which also seems to run on many issus - it seems like I solve one issue, but then find another one.
Here is my dynamo script:
And this is the the custom node:
"import clr
clr.AddReference(‘AcMgd’)
clr.AddReference(‘AcDbMgd’)
clr.AddReference(‘AecBaseMgd’)
clr.AddReference(‘AeccDbMgd’)
import Autodesk.AutoCAD.ApplicationServices as acApp
import Autodesk.AutoCAD.DatabaseServices as acDb
import Autodesk.Civil.ApplicationServices as civilApp
import Autodesk.Civil.DatabaseServices as civilDb
import System
Sisendid
surfacesIn = IN[0] # 2nd order list of Dynamo TinSurface wrapper objects
titles = IN[1] # List of export group names
filePathBase = IN[2] # Base path like “C:\Temp\Export”
doc = acApp.Application.DocumentManager.MdiActiveDocument
db = doc.Database
civdoc = civilApp.CivilApplication.ActiveDocument # CivilDocument objekt
results =
trans = None
try:
trans = db.TransactionManager.StartTransaction()
# Leia kõik pinnad dokumendist
surfIds = civdoc.SurfaceIds # See on ObjectIdCollection
surfaceMap = {}
# Ehita nimi -> ObjectId map
for surfId in surfIds:
surfObj = trans.GetObject(surfId, acDb.OpenMode.ForRead)
if hasattr(surfObj, "Name"):
surfaceMap[surfObj.Name] = surfId
# Käi läbi kõik sisendid
for i, surfaceGroup in enumerate(surfacesIn):
title = titles[i] if i < len(titles) else "Untitled"
for j, dynSurface in enumerate(surfaceGroup):
try:
if dynSurface is None:
results.append("Skipped: surface is None at group {}, index {}".format(i, j))
continue
# Hangi pinna nimi Dynamo wrapperist
surfName = dynSurface.Name
if surfName not in surfaceMap:
results.append("Skipped: surface '{}' not found in Civil doc".format(surfName))
continue
surfId = surfaceMap[surfName]
civilSurface = trans.GetObject(surfId, acDb.OpenMode.ForRead)
if hasattr(civilSurface, "ExportToLandXml"):
outPath = "{}_{}_{}.xml".format(filePathBase, title.replace(" ", "_"), j)
civilSurface.ExportToLandXml(outPath, True, True, True)
results.append("Exported: " + outPath)
else:
results.append("Skipped: AeccTinSurface has no ExportToLandXml")
except Exception as innerEx:
results.append("Inner error [{}][{}]: {}".format(i, j, str(innerEx)))
trans.Commit()
except Exception as e:
if trans is not None:
try:
trans.Abort()
except:
pass
results.append("Fatal error: " + str(e))
OUT = results
"
Here are the dynamo and Civil 3D files. Does anybody have an idea why my solution just doesn’t to the export part? Has anyone got a better solution for my problem?
LandXML Export2.dyn (30.0 KB)
LandXML.dwg (4.5 MB)
Best regards
Eno