Hello everyone,
I’m new to learning Python for Civil 3D and Dynamo, and I’m trying to create a Python script that automatically rebuilds a surface in Civil 3D. However, I’m running into an issue, and the script is not working as expected.
from Autodesk.AutoCAD.Runtime import *
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.EditorInput import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from Autodesk.AutoCAD.DynamoNodes import *
doc = Application.DocumentManager.MdiActiveDocument
ed = doc.Editor
if SurfaceCollection == surfaceName:
surface = s
break
Ensure we found the surface
#if surface is None:#
raise Exception(f"Surface with name ‘{surfaceName}’ not found.")#
Rebuild the surface
try:
surface.Rebuild()
print(f"Surface ‘{surfaceName}’ has been successfully rebuilt.“)
except Exception as e:
print(f"Error while rebuilding surface: {str(e)}”)
what is your issue? could you reformat the post to see the formatted code?
Also as @hosneyalaa suggested the best would be to share the dynamo file, if you are able to.
I’m very sorry but because I’m a new member here , it is not allowed for me to upload files .
So i uploaded the dynamo file on We Transfer , here is the link
import sys
import clr
clr.AddReference('AcMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry')
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
from System.Collections.Generic import Dictionary
adoc = Application.DocumentManager.MdiActiveDocument
cdoc = CivilApplication.ActiveDocument
from Autodesk.DesignScript.Geometry import *
def get_sample_line_info(SurfaceCollection , surfaceName):
global adoc
global cdoc
output = []
if not SurfaceCollection:
return
if not isinstance(SurfaceCollection, list):
sampleLines = [SurfaceCollection]
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
for Surfac in SurfaceCollection:
vals = []
sampleLineId = Surfac.InternalObjectId
objSurfac = t.GetObject(sampleLineId, OpenMode.ForRead)
if objSurfac == surfaceName:
objSurfac.Rebuild()
t.Commit()
return objSurfac
OUT = get_sample_line_info(IN[0], IN[1] )