Is there a way to change multiple layouts in a drawing to a different plot style at once? I want to change about 10 layouts from plot style A to plot style B, I have a couple drawings I have to do this to.
|
Is there a way to change multiple layouts in a drawing to a different plot style at once? I want to change about 10 layouts from plot style A to plot style B, I have a couple drawings I have to do this to.
R.K. McSwain | CAD Panacea |
Thanks for the reply. I haven't dealt with this kind of code...so what extension will the file have and how do i load file to run?
Never mind figured it out. "lsp" and load as usual for lisp and it auto runs. Works great, thanks.
Is there a way to change the code to prompt for file? No big rush, code works great just trying to prevent from going back into lisp and changing each time.
Ok, give this a try. This not only let's you choose a plot style, but it will determine if the drawing is set up for named plot styles or color dependent plot styles, and then present a list of the correct type from which to choose. The list is gathered from the current plot style path.
Code:(vl-load-com) (defun setplotstyle:mkdialog ( / fp) (setq fp (open (strcat (getenv "temp") "\\setplotstyle.dcl") "w")) (write-line "sps : dialog {" fp) (write-line "width = 30;" fp) (write-line "label = \"Select a plot style\";" fp) (write-line ": list_box {" fp) (write-line "key = \"lst\";" fp) (write-line "allow_accept = true;" fp) (write-line "height = 10;" fp) (write-line "is_enabled = true;" fp) (write-line "}" fp) (write-line "ok_cancel;" fp) (write-line "}" fp) (close fp) ) (defun C:SetPlotStyle ( / x pslist dcl_id ret *acad-object*) (setplotstyle:mkdialog) (if (zerop (getvar "PSTYLEMODE")) (setq filter "*.stb") (setq filter "*.ctb") ) (setq *acad-object* (vlax-get-acad-object)) (setq pslist (vl-directory-files (vla-get-PrinterStyleSheetPath (vla-get-Files (vla-get-Preferences *acad-object*) ) ) filter 1) ) (if pslist (setq pslist (acad_strlsort pslist))) (setq dcl_id (load_dialog (strcat (getenv "temp") "\\setplotstyle.dcl"))) (cond ((not (new_dialog "sps" dcl_id)) (princ "Unable to load DIALOG!") (exit)) ) (action_tile "lst" "(setq ret (nth (atoi $value) pslist))") (if (not ret)(setq ret (itoa 0))) (action_tile "cancel" "(exit)") (start_list "lst") (mapcar 'add_list pslist) (end_list) (start_dialog) (unload_dialog dcl_id) (vlax-for x (vla-get-Layouts (vla-get-ActiveDocument *acad-object* ) ) (vla-put-StyleSheet x ret) ) (vlax-release-object *acad-object*) ); end defun
R.K. McSwain | CAD Panacea |
That's cool.
Is there any way to get it to recurse the directory to search the subdirectory of that folder?
Thanks.
Found one. I just added the subdirectory path. And used a recursive fn from _gile. Link to post in code.
Code:; UI to change all layouts to same PlotStyle (vl-load-com) (defun setplotstyle:mkdialog ( / fp) (setq fp (open (strcat (getenv "temp") "\\setplotstyle.dcl") "w")) (write-line "sps : dialog {" fp) (write-line "width = 120;" fp) (write-line "label = \"Select a plot style\";" fp) (write-line ": list_box {" fp) (write-line "key = \"lst\";" fp) (write-line "allow_accept = true;" fp) (write-line "height = 70;" fp) (write-line "is_enabled = true;" fp) (write-line "}" fp) (write-line "ok_cancel;" fp) (write-line "}" fp) (close fp) ) ; Sud-dir routine by _gile ; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/vl-directory-files-for-subdirectories/m-p/7815896/highlight/true#M365740 (defun allfiles (folder pattern) (apply 'append (cons (if (vl-directory-files folder pattern) (mapcar '(lambda (x) (strcat folder "\\" x)) (vl-directory-files folder pattern) ) ) (mapcar '(lambda (x) (allfiles (strcat folder "\\" x) pattern)) (vl-remove ".." (vl-remove "." (vl-directory-files folder nil -1))) ) ) ) ) (defun C:Plotstyle_Change_All_Layouts ( / x pslist dcl_id ret *acad-object*) (setplotstyle:mkdialog) (if (zerop (getvar "PSTYLEMODE")) (setq filter "*.stb") (setq filter "*.ctb") ) ; (setq *acad-object* (vlax-get-acad-object)) ; (setq pslist ; (vl-directory-files ; (vla-get-PrinterStyleSheetPath ; (vla-get-Files ; (vla-get-Preferences *acad-object*) ; ) ; ) ; filter ; 1) ; ) (setq pslist (allfiles "W:\\SS_CAD\\SS_AutoCAD Templates & Settings\\SS_Plotstyles" filter)) (if pslist (setq pslist (acad_strlsort pslist))) (setq dcl_id (load_dialog (strcat (getenv "temp") "\\setplotstyle.dcl"))) (cond ((not (new_dialog "sps" dcl_id)) (princ "Unable to load DIALOG!") (exit)) ) (action_tile "lst" "(setq ret (nth (atoi $value) pslist))") (if (not ret)(setq ret (itoa 0))) (action_tile "cancel" "(exit)") (start_list "lst") (mapcar 'add_list pslist) (end_list) (start_dialog) (unload_dialog dcl_id) (vlax-for x (vla-get-Layouts (vla-get-ActiveDocument *acad-object* ) ) (vla-put-StyleSheet x ret) ) (vlax-release-object *acad-object*) ); end defun