Originally Posted by
Opie
I think you are going down the wrong path to assign layers per object type. Those settings are located in the in the ObjectLayerSettings property of the active drawing's DrawingSettings property. When retrieving the Object Layer Settings properties, you'll notice all of the child properties are marked as read-only. Each one of these properties contains additional properties that are write enabled.
Unfortunately, my toolbox for this area is not fully fleshed out at the moment. Otherwise, I would share.
No worries; you're correct... And it didn't help matters that I had just finished work that night (the next morning?)... This was exactly the reminder I needed, WRT LISP + C3D, and for that I thank you.
Here's a sample routine to invoke the ADDSEGMENTLABELS Command with the specified settings:
Code:
(defun c:AddSanitaryFlowArrow ()
(_AddSegmentLabels "._addsegmentlabel" "P-SS-TX" "SS Flow Arrows" "SS Flow Arrows")
)
(defun c:AddSanitaryFlowArrows ()
(_AddSegmentLabels "._addsegmentlabels" "P-SS-TX" "SS Flow Arrows" "SS Flow Arrows")
)
;;; Arguments:
;;; commandName newGeneralSegmentLayerName newCurveLabelStyleName newLineLabelStyleName
** Note - the layer is created if it does not yet exist, but the Curve and Line Styles must already exist, or an error will result.
... And here's the dependent sub-function to handle the overhead of starting UNDO, storing the current settings, setting the new settings, and restoring when done, etc.:
Code:
(vl-load-com)
(defun _AddSegmentLabels (commandName newGeneralSegmentLayerName newCurveLabelStyleName
newLineLabelStyleName / *error* vrsn acApp
aeccApp aeccSettings aeccGeneralSegmentLabelLayer aeccGeneralCommandsSettings
aeccSegmentLabelSettings acDoc generalSegmentLayerName curveLabelStyleName
lineLabelStyleName)
(defun *error* (msg)
(if (and generalSegmentLayerName aeccGeneralSegmentLabelLayer)
(vlax-put aeccGeneralSegmentLabelLayer
'Layer
generalSegmentLayerName
)
)
(if (and curveLabelStyleName lineLabelStyleName aeccSegmentLabelStyleSettings)
(progn
(vlax-put aeccSegmentLabelStyleSettings
'CurveLabelStyle
curveLabelStyleName
)
(vlax-put aeccSegmentLabelStyleSettings
'LineLabelStyle
lineLabelStyleName
)
)
)
(if aeccApp
(vlax-release-object aeccApp)
)
(if acDoc
(vla-endundomark acDoc)
)
(cond ((not msg)) ; Normal exit
((member msg '("Function cancelled" "quit / exit abort"))) ; <esc> or (quit)
((princ (strcat "\n** Error: " msg " ** "))) ; Fatal error, display it
)
(princ)
)
(if
(and
(setq vrsn (getvar 'acadver))
(setq vrsn
(cond
((vl-string-search "20.1" vrsn) "10.5")
((vl-string-search "20.0" vrsn) "10.4")
((vl-string-search "19.1" vrsn) "10.3")
((vl-string-search "19.0" vrsn) "10.0")
((vl-string-search "18.2" vrsn) "9.0")
((vl-string-search "18.1" vrsn) "8.0")
((vl-string-search "18.0" vrsn) "7.0")
((vl-string-search "17.2" vrsn) "6.0")
((vl-string-search "17.1" vrsn) "5.0")
)
)
(setq aeccApp (vla-getinterfaceobject
(setq acApp (vlax-get-acad-object))
(strcat
"AeccXUiLand.AeccApplication."
vrsn
)
)
)
(setq aeccSettings (vlax-get (vlax-get aeccApp 'ActiveDocument) 'Settings))
(setq aeccGeneralSegmentLabelLayer
(vlax-get
(vlax-get
(vlax-get
aeccSettings
'DrawingSettings
)
'ObjectLayerSettings
)
'GeneralSegmentLabelLayer
)
)
(setq aeccGeneralSettings (vlax-get aeccSettings 'GeneralSettings))
(setq aeccGeneralCommandsSettings
(vlax-get
(vlax-get (vlax-get aeccApp 'ActiveDocument) 'Settings)
'GeneralCommandsSettings
)
)
(setq aeccSegmentLabelStyleSettings
(vlax-get
(vlax-get
aeccGeneralCommandsSettings
(if (wcmatch (strcase commandName) "*SEGMENTLABELS")
'AddSegmentLabelsSettings
'AddSegmentLabelSettings
)
)
'StyleSettings
)
)
)
(progn
(vla-startundomark
(setq acDoc (vla-get-activedocument acApp))
)
;; store the current settings
(setq generalSegmentLayerName (vlax-get aeccGeneralSegmentLabelLayer 'Layer))
(setq curveLabelStyleName
(vlax-get
(vlax-get aeccSegmentLabelStyleSettings
'CurveLabelStyle
)
'Value
)
)
(setq lineLabelStyleName
(vlax-get
(vlax-get aeccSegmentLabelStyleSettings
'LineLabelStyle
)
'Value
)
)
;; set curve and line label styles
(vlax-put aeccSegmentLabelStyleSettings 'CurveLabelStyle newCurveLabelStyleName)
(vlax-put aeccSegmentLabelStyleSettings 'LineLabelStyle newLineLabelStyleName)
;; create layer if it doesn't exist
(vla-add (vla-get-layers acDoc) newGeneralSegmentLayerName)
(vlax-put aeccGeneralSegmentLabelLayer 'Layer newGeneralSegmentLayerName)
(prompt
(strcat
"\nCurrent Settings: "
"\nGeneral Segment Layer = " generalSegmentLayerName " --> " newGeneralSegmentLayerName
"\nCurve Label Style(s) = " curveLabelStyleName " --> " newCurveLabelStyleName
"\nLine Label Style(s) = " lineLabelStyleName " --> " newLineLabelStyleName
"\n\n "
)
)
(command commandName)
(while (= 1 (getvar 'cmdactive))
(command pause)
)
)
(prompt
"\n** Unable to interface with \"AeccXUiLand.AeccApplication\" object ** \n"
)
)
(*error* nil)
)
** Note - Tested using Civil 3D 2015, but configured to allow functionality in Civil 3D 2008-2016; please report any issues.
Cheers