Accessing Drawing, Feature, and Command Settings

Settings apply at three levels in AutoCAD Civil 3D:

  1. Drawing level: there are drawing-wide settings, such as units and zone, abbreviations, etc. There are also ambient settings, which affect a variety of AutoCAD Civil 3D behaviors. While these settings also apply drawing-wide, they can be overridden at the feature or command level.
  2. Feature (object) level: ambient settings override drawing level ambient settings for that feature only. There are also feature-specific settings, such as default styles.
  3. Command level: ambient settings can be set on a command-by-command basis. These settings override both drawing level and feature level settings.

For more information on settings in general, see Understanding Settings in the AutoCAD Civil 3D User’s Guide.

A document’s settings are accessed through the properties of the SettingsRoot object, which is obtained from the Document.Settings property. This object contains the DrawingSettings property (type SettingsDrawing), which contains all the top-level ambient settings for the document. It also has the GetSettings() method, which gets feature and command settings.

Drawing settings and general ambient settings are in the Autodesk.Civil.Settings namespace, while feature and command settings are in the namespace for the related feature. For example, alignment-related ambient and command settings are in the Autodesk.Civil.Land.Settings namespace.

The following sample shows how to access the angle settings for alignments:

SettingsAlignment alignmentSettings = doc.Settings.GetSettings<SettingsAlignment>();
Autodesk.Civil.Settings.SettingsAmbient.SettingsAngle angleSettings = alignmentSettings.Angle;
ed.WriteMessage(@"Alignment settings:\n  Precision: {0}\n  Rounding: {1}  
Unit: {2}\n  Drop Decimal: {3}\n  DropZeros: {4}\n ",
    angleSettings.Precision.Value, angleSettings.Rounding.Value, 
    angleSettings.Unit.Value, angleSettings.DropDecimalForWholeNumbers.Value, 
    angleSettings.DropLeadingZerosForDegrees.Value);  

The command settings apply to commands, and correspond to the settings in the Commands folder for each item in the AutoCAD Civil 3DToolspace Settings Tab. Each command setting has a corresponding class named SettingsCmdCommandName. For example, the settings class corresponding to the CreateAlignmentLayout command is SettingsCmdCreateAlignmentLayout. As with other types of settings, you use the CivilDocument.Settings.GetSettings() method to access command settings objects in the document.

The following snippet determines what the “Alignment Type Option” is for the CreateAlignmentLayout command:

SettingsCmdCreateAlignmentLayout alignLayoutCmdSettings = doc.Settings.GetSettings<SettingsCmdCreateAlignmentLayout>();         
ed.WriteMessage(@"Alignment Layout Command settings: AlignmentType: {0}  ",
    alignLayoutCmdSettings.AlignmentTypeOption.AlignmentType.Value
   );

The result of this code returns the current command setting:

Getting command settings