PDA

View Full Version : Is Lisp the right tool to create this routine?


Gary.182361
2009-08-08, 03:20 AM
I know nothing about Lisp, but I figure it's time I learned. This is what I'd like to accomplish:

Have a routine that selects all viewports in a drawing, puts them on the vport layer, sets them to shade plot and locks the viewport. I have a lisp currently that will lock all viewports in a drawing, so I'm thinking maybe it would just take adding some information to it. This is what I have existing (from Cadalyst). What would I have to add? Thanks for any help!

;;CADALYST 07/06 Tip2129: LV.lsp Viewport Lock and Unlock (c) Theodorus Winata

;;; Function: Lock/Unlock Viewports
;;; Command Line: LV
;;; Description: By locking the Display you ensure your
;;; model view will not accidentally shift
;;; if you activate the viewport
;;;
;;; Developed by Theodorus Winata
;;; April 2006
;;;

(defun get-objects ()
(setq DPL (vlax-ename->vla-object (ssname SSG CNT))
CNT (1+ CNT)
);;setq
);;get-objects

;;;********** Error Handler **********
(defun ERR (msg)
(princ)
);;ERR

;;;********** Main Program **********
(defun C:LV (/ CME CNT DPL *ERROR* OP SSG)
(vl-load-com)
(setq *ERROR* ERR
CME (getvar "CMDECHO")
);;setq
(setvar "CMDECHO" 0)
(if (= (getvar "TILEMODE") 1) (setvar "TILEMODE" 0))
(command "pspace")
(setq SSG (ssget "X" (list (cons 0 "VIEWPORT")))
CNT 0
);;setq
(initget "Yes No")
(setq OP (getkword "Display locked [Yes/No] <Y>: "))
(cond
((or (= OP nil) (= OP "Yes"))
(repeat (sslength SSG)
(get-objects)
(vla-put-DisplayLocked DPL :vlax-true)
);;repeat
(prompt "\n\tAll Viewports Locked...!")
);;"Yes"
((= OP "No")
(repeat (sslength SSG)
(get-objects)
(vla-put-DisplayLocked DPL :vlax-false)
);;repeat
(prompt "\n\tAll Viewports Unlocked...!")
);;"No"
);;cond
(setvar "CMDECHO" CME)
(princ)
);;C:LV
(princ
(strcat
" LV.LSP v1.0 (Copyright 2006 by "
"\"Theo Winata and You\") loaded...!"
)
)
(princ)

info.159673
2009-08-09, 07:29 AM
I think you might want to step back a little.

Yes, you can do what you want in lisp. But you should spend some time learning it.

Load the routine the vlide and step through the code. Get to understand what each line is doing. Then once you understand what it does, you might be able to add to the code.

Asking "What would I have to add? " is asking a lot..

But...to try to answer more specifically.


"Have a routine that selects all viewports in a drawing" - look into selection sets with "x" and and entity filter (i forget what exactly what it's called). This will select all the viewports (or whatever you want) in your drawing. (note: i seem to remember a bug from a while back. When selecting or interacting with vports in lisp, autocad would crash). Having said that, modifying them with activex will be a lot easier...but is another level of lisp.

"puts them on the vport layer" - once you have the objects you want to change you can step through each one with

vla-foreach (or something like that)....it might be vla-for-each...or maybe vlax (you'll have to look in the documentation or the googleweb)

you can change the object layer several ways.
1) via the "command" . Here you would just issue the same autocad commands you issue from the command line...or at least similar.
2) activex - vla-put-layer objname layername
3) by modifying the entity directly (i'd have to look up the code....but it's entmod and entupd or somesuch)

"sets them to shade plot and locks the viewport" - this is essentially the same steps as changing the layer....just different properties.

------

ah...there is some good code in your sample

(ssget "X" (list (cons 0 "VIEWPORT"))) <--- this gets all your viewports like i mentioned above

(vla-put-DisplayLocked DPL :vlax-true) <--- this is an activex method for modifying the displaylocked property

....ok....maybe that will help you get started. Good luck.

irneb
2009-08-10, 09:03 AM
Firstly, the defun get-objects is simply a helper function to convert the usual entityname (or ename) as gotten from ssget & ssname into a vla-object ... this so ActiveX can be used. It's only needed if you use the vla / vlax functions on this entity ... otherwise you'd have used the older entget & entmod functions & change the values of the DXF codes.

There's 2 lines which change the VPorts. Both start with (vla-put-DisplayLocked ... these use the ActiveX property of each VPort named DisplayLocked. Seeing as this is actually not a Lisp native function the vlax:ttrue & vlax:false is used instead of the usual t or nil.

To make what you want, add another vla-put-.... function directly before or after each of these. To find out what name this function has look at Help --> Additional Resources --> Developer Help ... then open the ActiveX and VBA Reference section & its Object Model. Tip the Paper Space Viewport is under PaperSpace --> PViewport. The other Viewport is the model space tiled viewports.