Help writing a Lisp...

Help writing a Lisp...

Anonymous
Not applicable
729 Views
3 Replies
Message 1 of 4

Help writing a Lisp...

Anonymous
Not applicable

I believe it's possible, but I'm not sure how to do it myself...

I'd like a lisp that I'll use for closeout packages, ideally it would be 1 command to 

1) open dwg

2) use viewvis lisp (viewvis, ON)

3) switch to model space

4) hatchback

5)texttofront, all

 

Once I open all 25-ish drawings, 1 at a time, I would then publish to a single, multipage PDF file. 

Thanks,

 

 

This is the viewvis lisp I use

(vl-load-com)
(defun C:viewvis (/ vlist yesno targetvp i maxvp)
(setq i 0)
(initget "ON OFF")
(setq yesno (cond ((getkword "\nTurn all viewports on or off? [ON/OFF] <ON>: ")) ("ON")))
(setq maxvp (getvar "maxactvp"))
(setvar "maxactvp" 2)
(while (and (/= i (length (layoutlist))) (/= (getvar "dwgname") drawingrefresh))
(setvar "ctab" (nth i (layoutlist)))
(setq i (1+ i))
)
(setq drawingrefresh (getvar "dwgname"))
(setq vlist (ssget "x" (list '(0 . "viewport") '(-4 . "/=") '(69 . 1))))
(while (/= 0 (sslength vlist))
(setq targetvp (vlax-ename->vla-object (ssname vlist 0)))
(if (= yesno "ON")
(vla-display targetvp :vlax-true)
(vla-display targetvp :vlax-false)
)
(ssdel (ssname vlist 0) vlist)
)
(setvar "maxactvp" maxvp)
(princ)
)

0 Likes
730 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

You're going to have to structure that a little differently from what you're picturing.  An AutoLisp routine can't start in one drawing and continue in another.  I would build your steps 3, 4 & 5 into (viewvis) [or call the consolidation of those functions something else], and then you'll need to make a SCRIPT to apply that routine in drawings which you can step through with something like SCRIPTPRO.  Search for Scriptpro on these Forums for examples of its usage [it's not something I've worked with -- I just know it's a way to run things on multiple drawings in a way that Lisp can't].

Kent Cooper, AIA
0 Likes
Message 3 of 4

john.uhden
Mentor
Mentor
As long as MDI is on, you could set up acaddoc.lsp to load and run the desired function to open any number of dwgs and process them. Of course the function should save the opened dwgs before closing them.

John F. Uhden

0 Likes
Message 4 of 4

Anonymous
Not applicable

Thank you for your advise... After a little more research and some trial/error I've come up with this - not perfect, but certainly a time saver for me - 

 

I added these 2 lisps to my startup suite:

VPON (viewports on)

     ;turn all viewports on
     (defun c:vpon ( )
     (foreach x (layoutlist)
     (command "layout" "set" x)
     (command "mview" "on" "all" "")
     )
     )

VPL (viewports locked)

     ;lock all mview
     (defun c:vpl ( )
     (foreach x (layoutlist)
     (command "layout" "set" x)
     (command "mview" "lock" "on" "all" "")
     )
     )

 

And then I tried the "action recorder" - it's always intrigued me, but I've never used it. 

 closeout.png

 

If I start in a (any) layout tab, it'll

1) switch to model space

2) hatch to back

3) text and dims to front

4) turn all viewports on

5) switch back to model space

6) lock all viewports

7)QSave

 

I tried to combine steps 4 & 6, but I wasn't able to work it out, so I ran them separately for now.

So I'll still have to open all 25 drawings separately, but I won't have to run through each of their tabs. 

After I've "played" this recorded action for each, I'll then publish to 1 PDF file...

 

Improvements I could make? Did I take the longest route around? 

 

0 Likes