Results 1 to 8 of 8

Thread: Batch Plot Style Change

  1. #1
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Batch Plot Style Change

    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.

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Lightbulb Re: Batch Plot Style Change

    Quote Originally Posted by OCD View Post
    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.
    Give this a try. Replace "acad.ctb" with your desired CTB file.

    Code:
    
    (vl-load-com)
    (vlax-for x
      (vla-get-Layouts
        (vla-get-ActiveDocument
          (vlax-get-acad-object)
        )
      )
      (vla-put-StyleSheet x "acad.ctb")
    )
    
    
    R.K. McSwain | CAD Panacea |

  3. #3
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Re: Batch Plot Style Change

    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?

  4. #4
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Re: Batch Plot Style Change

    Never mind figured it out. "lsp" and load as usual for lisp and it auto runs. Works great, thanks.

  5. #5
    Active Member
    Join Date
    2007-08
    Posts
    81
    Login to Give a bone
    0

    Default Re: Batch Plot Style Change

    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.

  6. #6
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Exclamation Re: Batch Plot Style Change

    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 |

  7. #7
    Member
    Join Date
    2013-04
    Posts
    25
    Login to Give a bone
    0

    Default Re: Batch Plot Style Change

    That's cool.

    Is there any way to get it to recurse the directory to search the subdirectory of that folder?

    Thanks.

  8. #8
    Member
    Join Date
    2013-04
    Posts
    25
    Login to Give a bone
    0

    Default Re: Batch Plot Style Change

    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

Similar Threads

  1. Specify the Plot Style for certain entities in a Named plot style drawing
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2014-10-28, 11:52 AM
  2. 2012: Can I change plot style with lisp or script?
    By dolan.raynor in forum AutoCAD General
    Replies: 3
    Last Post: 2013-07-18, 01:19 PM
  3. Change All Layers' Plot Style Setting
    By parker.depriest356295 in forum AutoLISP
    Replies: 1
    Last Post: 2013-02-05, 07:05 PM
  4. Named Plot Style OR Color Depemdent Plot Style
    By Masroor Javid in forum ACA General
    Replies: 2
    Last Post: 2007-09-11, 02:16 PM
  5. CHANGE PLOT STYLE TABLE
    By eng5 in forum AutoCAD General
    Replies: 2
    Last Post: 2005-03-08, 01:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •