This is continuation of a series focusing on Civil 3D’s .Net API.
One of the great features of Civil 3D is its settings controls. Settings are based upon a hiearchal format (for more information on Settings see this former post).
We are going to look at how to get the settings at different levels.
Drawing Settings
The drawing settings object is somewhat easy. We will first have to get the current civil drawing (document) object and then get its settings.
Dim civDoc As Autodesk.Civil.ApplicationServices.CivilDocument
civDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument
Dim dwgSettings As Autodesk.Civil.Settings.SettingsDrawing
dwgSettings = civDoc.Settings.DrawingSettings
Inside the DrawingSettings object are the settings you would find the Drawing Settings dialog box in Civil 3D.
FeatureSettings
After drawing settings, it gets a little funner getting the settings. To get these settings, we have to use a method in the civDoc.Settings class called GetSettings. We call this method and pass to it the settings class we are trying to get from the drawing. See sample for the alignment feature settings below.
Dim stgsAlign As Autodesk.Civil.Land.Settings.SettingsAlignment
stgsAlign = civDoc.Settings.GetSettings(Of _
Autodesk.Civil.Land.Settings.SettingsAlignment)()
CommandSettings
Of course, if you can get the feature settings to work the rest is easy since both Feature and Command settings are classes in the .Net API. Just find the right class to pass to the civDoc.GetSettings method and you can get access to any setting in Civil 3D.
Dim stgsGen As Autodesk.Civil.Settings.SettingsCmdAddNoteLabel
stgsGen = civDoc.Settings.GetSettings(Of _
Autodesk.Civil.Settings.SettingsCmdAddNoteLabel)()
Full Code
Public Sub GetSettings()
Dim civDoc As Autodesk.Civil.ApplicationServices.CivilDocument
civDoc = Autodesk.Civil.ApplicationServices.CivilApplication.ActiveDocument
Dim dwgSettings As Autodesk.Civil.Settings.SettingsDrawing
dwgSettings = civDoc.Settings.DrawingSettings
Dim stgsAlign As Autodesk.Civil.Land.Settings.SettingsAlignment
stgsAlign = civDoc.Settings.GetSettings(Of _
Autodesk.Civil.Land.Settings.SettingsAlignment)()
Dim stgsGen As Autodesk.Civil.Settings.SettingsCmdAddNoteLabel
stgsGen = civDoc.Settings.GetSettings(Of _
Autodesk.Civil.Settings.SettingsCmdAddNoteLabel)()
Dim ed As Autodesk.AutoCAD.EditorInput.Editor
ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage(vbLf & _
"Your current elevation precision is " & _
dwgSettings.AmbientSettings.Elevation.Precision.Value.ToString)
ed.WriteMessage(vbLf & _
"Your current default alignment style is " & _
stgsAlign.StyleSettings.AlignmentStyle.Value)
ed.WriteMessage(vbLf & _
"Your current default general note label is " & _
stgsGen.Styles.NoteLabel.Value)
End Sub
Have fun…and please share some ideas for posting
Jos,
Thanks, This is great help seeing how and where to access different civil objects
John