A few things on this.
-
I recall that it is generally not recommended that you learn how to swim by jumping out of a plane over the middle of the pacific ocean, though I cannot find a source for it at the moment. In your case it sounds as if you’re attempting to learn Python (how to swim), how to access the .NET environment from Python (how to jump into water), how to use the AutoCAD API (how to use a parachute), and the Civil 3D API (how to jump out of a plane) concurrently. That isn’t going to be easy and you’re going to experience some discomfort (to put it mildly). Instead you should segment things into a sequences. Learn Python. Then learn how to access .NET from Python. Then learn how to use the AutoCAD API. Then learn how to use the Civil 3D API. Then (finally) try to solve your problem.
I understand this doesn’t help you solve your problem today, but it’s how you get to the point where you can solve the problem for yourself, which likely should be the end goal for the community on the forum and Dynamo users alike. -
While the Autocad and Civil 3D teams can provide documentation on using their APIs with Python, they shouldn’t be expected to provide documentation on Python or how to access the .NET environment there from. That’s like asking the Civil 3D team to document how to use Windows to create a shortcut to a DWG on your desktop. Fortunately the former has a good start on the primer, found here. Follow that closely after you do some Python and accessing .NET from Python basics. again, it doesn’t solve today’s problem but it helps you get to that point.
-
Now to go about solving an actual question - how do you remove all Civil 3D styles which don’t have the string "standard’ in their name.
- List out the steps needed to achieve your outcome
- Look into what you can perform without any custom scripting - i.e. if you were to receive an AutoCAD Object or Civil3D Object in a generic wrapper could you delete it? Could you extract the name to see which needed to be deleted?
- Use Python to script around the knowledge gaps, carefully converting into Dynamo native content so youc an leverage it where possible. Note that the nature of Pythona ccessing the Civil 3D environment is unstable - if you miss a carriage return or wrap something incorrectly then things will crash spectacularly, so save the Python script and then the Dynamo graph after successful edits (or failures), document stuff as you go, What worked, what didn’t, what’s good, what feels wrong.
All of this said, I don’t want you (or the rest of the community) to continue to struggle with this. So…
This Python should get you started.
########################################
############## Properties ##############
########################################
__author__ = 'Jacob Small'
__version__ = '0.1.0'
__description__ = "Proof of concept showing how to get the styles from a civil document"
__DynamoBuilds__ = "3.3"
__ReleaseNotes__ = "Proof of concept only - test thoroughly before implementing in production."
__Dependancies__ = "None"
__Copyright__ = "2025, Autodesk Inc."
__license__ = "Apache 2"
########################################
### Configure the Python environment ###
########################################
# Load the Python Standard and DesignScript Libraries
import sys #add the sys module to the Python environemnt
import clr #add the CLR module to the Python environment
# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd') #add the managed autocad library to the CLR
clr.AddReference('AcCoreMgd') #add the managed autocad core library to the CLR
clr.AddReference('AcDbMgd') #add the managed autocad DB library to the CLR
clr.AddReference('AecBaseMgd') #add the managed civil 3d base properties library to the CLR
clr.AddReference('AecPropDataMgd') #add the managed civil 3d property data library to the CLR
clr.AddReference('AeccDbMgd') #add the managed civil 3D db library to the CLR
# Import references from AutoCAD
from Autodesk.AutoCAD.Runtime import * #import the full autocad runtime library to the Python evnrionment
from Autodesk.AutoCAD.ApplicationServices import * #import the full autocad Application services library to the Python evnrionment
from Autodesk.AutoCAD.EditorInput import * #import the full autocad Editor input library to the Python evnrionment
from Autodesk.AutoCAD.DatabaseServices import * #import the full Autocad databse services library to the Python evnrionment
from Autodesk.AutoCAD.Geometry import * #import the Autocad Geometry library to the Python evnrionment
# Import references from Civil3D
from Autodesk.Civil.ApplicationServices import * #import the full application services library to the Python evnrionment
from Autodesk.Civil.DatabaseServices import * #import the full civil database services library to the Python evnrionment
### basic Dynamo imports ###
clr.AddReference('ProtoGeometry') #add the Dynamo geometry library to the CLR
from Autodesk.DesignScript import Geometry as DG #add the Dynamo geometry class using the alias DG, to ensure no overlap between class calls in Revit or Dynamo
### dynamo for Civil imports
from Autodesk.AutoCAD.DynamoNodes import SelectionByQuery #import the Dynamo for Civil 3D selection by query class to the Python environment
#########################################
###### Global variables and inputs ######
#########################################
adoc = Application.DocumentManager.MdiActiveDocument #get the active autocad document
results = [] #an empty list to hold the results
#########################################
############ Code goes here #############
#########################################
with adoc.LockDocument(), adoc.Database as db, db.TransactionManager.StartTransaction() as t: #lock the document so you can read/write without breaking anything, then get the autocad database from the document as db, and start a transaction with the autocad database as t
#### my template usually omits the lines between this comment and the next four hashtag comment
cdoc = CivilDocument.GetCivilDocument(db) #get the civil document from the database
cStyles = cdoc.Styles #get the styles from the civil document
styles = [results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.AlignmentDesignCheckSets] #get the styles from the document
#line 41 to 43 are a step by step set of actions, which can be replaced by line 45
#alignmentStyles = cStyles.AlignmentStyles #get the alignment styles, which is a list of object ids
#alignmentStyleObjects = [ t.GetObject(i, OpenMode.ForWrite) for i in alignmentStyles ] #get the alignment style objects from the alignment styles list
#[results.append(i) for i in alignmentStyleObjects] #append the alignment styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.AlignmentStyles] #write the alignment styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.AssemblyStyles] # write the assembly styles to the results list
bandstyles = cStyles.BandStyles #get the band styles - these are a root object with sub objects, so you have to do some additional investigation
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.ProfileViewHorizontalGeometryBandStyles] #write the profile view horizontal geometry band styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.ProfileViewPipeNetworkBandStyles] #write the profile view pipe network ban styles to the results list
#lines 53 to 58 are more of the ssame for band styles
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.ProfileViewProfileDataBandStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.ProfileViewSectionalDataBandStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.ProfileViewSuperElevationBandStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.ProfileViewVerticalGeometryBandStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.SectionViewSectionDataBandStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in bandstyles.SectionViewSegmentsBandStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.BuildingSiteStyles] #write the building site styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.CantViewStyles] #write the cant view styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.CatchmentStyles] #write catchment styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.CodeSetStyles] #write code set styles to the results list - note these have additional structure to them
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.CorridorStyles] #write corridor styles to the results list
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.FeatureLineStyles] #write feature line styles
#line 73 to 81 are more of the same
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.GradingCriteriaSets]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.GradingStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.GroupPlotStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.InterferenceStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in cStyles.IntersectionStyles]
labelSetStyles = cStyles.LabelSetStyles #get the label set styles - these are a root object with sub objects, so you have to do some additional investigation
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in labelSetStyles.AlignmentLabelSetStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in labelSetStyles.ProfileLabelSetStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in labelSetStyles.SectionLabelSetStyles]
labelStyles = cStyles.LabelStyles #get the label styles which are a root object with sub objects, so you have to do some additional investigation
alignmentLabelStyles = labelStyles.AlignmentLabelStyles #get the alingment label styles which are a root object, so you have to do some additional investigation
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.CantCriticalPointsLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.CurveLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.DesignSpeedLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.GeometryPointLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.LineLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.MajorStationLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.MinorStationLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.PointOfIntersectionLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.SpiralLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.StationEquationLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.StationOffsetLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.SuperelevationCriticalPointsLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.TangentIntersectionLabelStyles]
[results.append(t.GetObject(i, OpenMode.ForWrite)) for i in alignmentLabelStyles.VerticalGeometryPointLabelStyles]
# you'll need to pick up the mining of styles here
# you'll need to work on filtering of styles to remain here
# you'll need to work on deletion of unwanted styles here
#### my template usually picks back up here
t.Commit() #commit the transaction
pass #pass any errors
OUT = results #return the results to the Dynamo environment. Note these are the native API objects, so you won't be able to use standard Dynamo nodes on them, but you can work with them in this Python environment. Take an object, look at the directory of calls youc an make on it using dir(object) and leverage those calls from there. Save often and early.
It won’t do everything you (or others) are after, but it should show you how to get to each type of style in an active transaction without breaking things. You should have enough to get yourself going though. Best of luck!