Lisp to "Display plot styles" on open
Hi all! I'm hoping someone might be able to help me with a Lisp routine. I would like to have a Lisp that could change all layouts to "Display plot styles" on open. I have a couple Lisps already that get me pretty close but I was hoping that someone would be able to combine the two somehow.
I'm running Civil3D 2011 on Win7-64
I found this Lisp somewhere on this forum. I think originally it unchecked the "display plot styles" but I changed it to do the opposite. I turned it into a button, but its a manual button press and it only works on the current tab.
Code:
(defun pstyleDOshow (/ doc layoutobj)
(setq doc (vla-get-activedocument
(vlax-get-acad-object)
)
layoutobj (vla-get-activelayout doc)
)
(vla-put-showplotstyles layoutobj :vlax-true)
(vla-regen doc acAllViewports)
(mapcar 'vlax-release-object (list layoutobj doc))
(princ)
)
Then I have this Lisp to lock all viewports in an drawing automatically after opening a drawing. I just add this to my startup suite and it works great!
Code:
;;;VPLOCK.lsp locks all viewports automatically when opening a drawing
;;;no idea who wrote it
(defun vplock (yesno / ss lock x obj)
(vl-load-com)
(if (setq ss (ssget "X" '((0 . "VIEWPORT")(-4 . "/=")(69 . 1))))
(progn
(if (= "y" yesno) (setq lock :vlax-true)(setq lock :vlax-false))
(setq x 0)
(while (< x (sslength ss))
(setq obj (vlax-ename->vla-object (ssname ss x)))
(vla-put-displaylocked obj lock)
(setq x (1+ x))
)
)
)
(princ)
)
(vplock "y")
So I don't know if a combination of these two would work, but I thought I'd include both just in case it helps. Ultimately what I need is a way to change all viewports in a drawing to "display plot styles" every time I open a drawing. Is this possible? I've been trying to figure this out on my own for a while but I'm not that great at programing so I haven't been able to make it work correctly. I would really appreciate any help on this. Thanks!
Re: Lisp to "Display plot styles" on open
Try adding this to your startup suite:
Code:
(defun showpstyle ( / DOC LAYOUTS)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
layouts (vla-get-layouts doc)
); setq
(vlax-for n layouts
(vl-catch-all-apply 'vla-put-showplotstyles (list n :vlax-true))
); vlax-for
(vla-regen doc acAllViewports)
(mapcar 'vlax-release-object (list layouts doc))
(princ)
); defun
(showpstyle)
Re: Lisp to "Display plot styles" on open
Thanks gharvey for the quick reply! That worked perfectly! You're awesome!
Re: Lisp to "Display plot styles" on open
Re: Lisp to "Display plot styles" on open
Hi, GHarvey. Is there any way to write this so it will effect all paper space layouts and exclude the model layout. When I run it it changes all of my colors that are set to black/white (Pen 7) to white in model space.... My hope is to see model space in color, but paper space as a plot preview... (In Black) Thanks in advance!
Re: Lisp to "Display plot styles" on open
---------------------------
Re: Lisp to "Display plot styles" on open
Try the following revision...
Code:
(defun showpstyle ( / DOC LAYOUTS)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
layouts (vla-get-layouts doc)
); setq
(vlax-for n layouts
(if (/= "Model" (vla-get-name n))
(vl-catch-all-apply 'vla-put-showplotstyles (list n :vlax-true))
); if
); vlax-for
(vla-regen doc acAllViewports)
(mapcar 'vlax-release-object (list layouts doc))
(princ)
); defun
(showpstyle)
Re: Lisp to "Display plot styles" on open
Couple of things....
Unless I am overlooking something (which is entirely possible), there's no need to call vl-Catch-All-Apply when setting an Object's Property (in this case a Boolean), given that you've hard-coded an allowable value (in this case :vlax-True).
I would, however, recommend that one do so (that is, to use vl-Catch-All-Apply) if passing a parameter to the Object's Property as a value; just not needed here IMO.
Also, one need not release internal Object's; only external/interface Objects.
Code:
(defun c:ShowPlotStyles ( / acDoc)
(vlax-for oLayout
(vla-get-layouts
(setq acDoc
(vla-get-activedocument (vlax-get-acad-object))
)
)
(if (/= "Model" (vla-get-name oLayout))
(vla-put-showplotstyles oLayout :vlax-true)
)
)
(vla-regen acDoc acAllViewports)
(princ)
)
Separately, this could easily be expanded to incorporate a bit-coded setting, either drawing data (via XRecord?), or registry data to allow one to programmatically toggle the ShowPlotStyles Property value at drawing open, and/or while in session if desired
Psuedo system variable:
Code:
0 = All Layouts do not display plot styles
1 = All Layouts display plot styles, except for Model
2 = All Layouts display plot styles, including Model
Re: Lisp to "Display plot styles" on open
Thank You!! GHarvey & RenderMan
Re: Lisp to "Display plot styles" on open
Quote:
Originally Posted by
GHarvey
Try adding this to your startup suite:
Code:
(defun showpstyle ( / DOC LAYOUTS)
(setq doc (vla-get-activedocument (vlax-get-acad-object))
layouts (vla-get-layouts doc)
); setq
(vlax-for n layouts
(vl-catch-all-apply 'vla-put-showplotstyles (list n :vlax-true))
); vlax-for
(vla-regen doc acAllViewports)
(mapcar 'vlax-release-object (list layouts doc))
(princ)
); defun
(showpstyle)
this lisp does not response when i load. can anyone help me