Added checking if the plot style exists.
;;----------------------------------------------------------------------;;
;; setPlotStyle FUNCTION
;; https://www.theswamp.org/index.php?topic=45000.msg502065#msg502065
;; Added checking if the plot style exists by 3dwananb on 2024.05.15
(defun setPlotStyle (ctb / CurDoc installedPs)
(setq CurDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq installedPs (vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (vla-get-ActiveLayout CurDoc))))) ;;get the plotstyles
(if (/= nil (vl-position ctb installedPs))
(progn
(princ (strcat "\nPlot Style successfully set to: '" ctb "'\n"))
(vlax-map-collection
(vla-get-Layouts
(vla-get-ActiveDocument (vlax-get-acad-object))
)
'(lambda (x) (vla-put-StyleSheet x ctb))
)
)
(princ (strcat "\nPlot Style '" ctb "' not found!\n"))
) ;; if verify if the plotstyle exist, if not, print to the commandline.
)
(setPlotStyle "monochrome.ctb")