Need some help accessing viewport layer override settings
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am attempting to capture viewport layer override settings but am having little success. Could someone point me to the proper way of doing this. This is what I have so far.
I have also attached text files of my progress
-You have to be inside a viewport for it to initiate properly:
(defun c:SVP (/ activeDoc targetVP layers layerSettings file response layerName vpOverrides vpColor vpLineWeight vpLineType vpPlotStyle vpTransparency vpVisibility)
;; Get the active document
(setq activeDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Check if the cursor is in model space through a viewport
(if (= (vla-get-Mspace activeDoc) :vlax-false)
(progn
(princ "\n*** OPERATION CANCELED ***")
(princ "\nYou must be inside a viewport to save the VP settings.\n")
(princ)
)
(progn
;; Get the active viewport
(setq targetVP (vla-get-ActivePViewport activeDoc))
;; Check if the file already exists
(if (findfile "C:/Temp/VPsettings.txt")
(progn
;; Prompt user to proceed or cancel
(initget "C P")
(setq response (getkword "\nFile already exists. Proceed and overwrite the file? [C to cancel/P to proceed] <P>: "))
(if (not (or (equal response "P") (equal response "p") (equal response "")))
(progn
(princ "\nOperation has been canceled.\n")
(exit)
)
)
)
)
;; Open file for writing and make sure to close it properly
(setq file (open "C:/Temp/VPsettings.txt" "w"))
;; Check if file opened successfully
(if (not file)
(progn
(princ "\n*** ERROR: Unable to open file for writing ***\n")
(exit)
)
)
;; Get viewport layer overrides using entget
(setq layers (vla-get-Layers activeDoc))
(setq layerSettings '())
(vlax-for layer layers
(setq layerName (vla-get-Name layer))
(setq vpOverrides (entget (tblobjname "LAYER" layerName)))
;; Access VP-specific properties directly with checks
(setq vpColor (if (numberp (cdr (assoc 62 vpOverrides))) (cdr (assoc 62 vpOverrides)) 0))
(setq vpLineWeight (if (numberp (cdr (assoc 370 vpOverrides))) (cdr (assoc 370 vpOverrides)) 0))
(setq vpLineType (if (cdr (assoc 6 vpOverrides)) (cdr (assoc 6 vpOverrides)) "ByLayer"))
(setq vpPlotStyle (if (cdr (assoc 390 vpOverrides)) (cdr (assoc 390 vpOverrides)) ""))
(setq vpTransparency (if (numberp (cdr (assoc 440 vpOverrides))) (cdr (assoc 440 vpOverrides)) 0))
(setq vpVisibility (if (numberp (cdr (assoc 70 vpOverrides))) (cdr (assoc 70 vpOverrides)) 0))
;; Store the collected settings
(setq layerSettings
(cons (list layerName
(vla-get-Description layer)
(vla-get-Color layer)
(vla-get-LineWeight layer)
(vla-get-Linetype layer)
(vla-get-PlotStyleName layer)
(vla-get-Freeze layer)
(vla-get-Lock layer)
(vla-get-LayerOn layer)
;; VP-specific settings
vpColor
vpLineWeight
vpLineType
vpPlotStyle
vpTransparency
vpVisibility)
layerSettings))
)
;; Write settings to file
(foreach layer layerSettings
(write-line
(strcat
(nth 0 layer) "\t" ;; Layer Name
(if (nth 1 layer) (nth 1 layer) "N/A") "\t" ;; Description
(itoa (or (nth 2 layer) 0)) "\t" ;; Color
(itoa (or (nth 3 layer) 0)) "\t" ;; Line Weight
(if (nth 4 layer) (nth 4 layer) "N/A") "\t" ;; Line Type
(if (nth 5 layer) (nth 5 layer) "N/A") "\t" ;; Plot Style
(if (eq (nth 6 layer) :vlax-true) "Yes" "No") "\t" ;; Freeze
(if (eq (nth 7 layer) :vlax-true) "Yes" "No") "\t" ;; Lock
(if (eq (nth 8 layer) :vlax-true) "Yes" "No") "\t" ;; Layer On
;; VP-specific settings
(itoa (or (nth 9 layer) 0)) "\t" ;; VP Color
(itoa (or (nth 10 layer) 0)) "\t" ;; VP Line Weight
(if (nth 11 layer) (nth 11 layer) "N/A") "\t" ;; VP Line Type
(if (nth 12 layer) (nth 12 layer) "N/A") "\t" ;; VP Plot Style
(itoa (or (nth 13 layer) 0)) "\t" ;; VP Transparency
(if (eq (nth 14 layer) :vlax-true) "Yes" "No") ;; VP Visibility
)
file
)
)
;; Close the file
(close file)
;; Display completion message
(princ "\nThe \"VP\" Settings have been saved as VPSettings.txt in C:\\Temp.\n")
(princ)
)
)
)
;; Display message after LISP is loaded
(princ "\nType \"SVP\" to save viewport layer override settings.\n")
(princ "\nThe \"VP\" Settings will be saved as VPSettings.txt in C:\\Temp.\n")
(princ)
Best Regards
-Tim C.