Is there a way to extract a list of all the civil 3d styles in a drawing? Such as:
- Surface Styles.
- Surface Elevation Styles
- Profile View Label Styles
Is there a way to extract a list of all the civil 3d styles in a drawing? Such as:
This is perfect so now how do I get a list of letâs say âsurface stylesâ to a note pad document or in such a way that I can copy all of those style names into Excel?
The output is a dictionary, so take a look at the nodes under the âDictionaryâ shelf in the library.
Any other tips about how I can get to the surface names such that I can copy them out of the dynamo script and paste them into Excel?
Try Dictionary.ValueAtKey and Data.ExportExcel.
Is there an issue?
Since GetDocumentStyles was not put into core Dynamo and Civil 3D Toolkit has been abandoned, how can this be replicated? Is there not a way anymore in Dynamo to get all C3D styles in a drawing?
Hi @Cadguru42,
The only out-of-the-box nodes that are currently available for working with styles are CivilObject.Style and CivilObject.SetStyle. There may be a 3rd-party package available to do more with style management, but I canât say for sure. For anything related to the Civil 3D Toolkit, Iâd recommend posting in Civil 3D Toolkit Feedback thread to see if the authors can help.
As that package is effectively EoL users will be better suited finding or building alternative solutions.
@Cadguru42 how comfortable are you with Python or C#?
Iâm looking into learning Python, but man, Autodesk does not make it easy to see how to use it. Iâve spent all morning just trying to find stuff. I want to make a way to do a purge of all C3D styles in a drawing, but leave any named âStandardâ. I have no idea where to even start. Iâve found the basics regarding how to add a Python script for Dynamo, but no clue where to go from there.
I canât find how in Python to just get all styles in a C3D drawing.
Youâre not alone. Iâm looking for this too.
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.
All of this said, I donât want you (or the rest of the community) to continue to struggle with this. SoâŚ
########################################
############## 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!