Jump to content

Lisp routine to print layout tabs and exclude model tab


jason_a

Recommended Posts

I'm trying to create an ACAD2000 lisp routine that will print only Paperspace tabs. This is what I have so far:

 

(defun c:Plt (/ )
 (foreach layoutname (layoutlist )
   (command "._layout" "set" layoutname )
   (command "-plot" 
"yes" 
layoutname 
"\\\\sbserver\\Canon ir3235" 
"LETTER" 
"INCHES" 
"PORTRAIT" 
"NO" ;PLOT UPSIDE DOWN
"LAYOUT" 
"1:1" 
"0.00,0.00" 
"YES" ;PLOT WITH PLOTSYTLES
"MONOCHROME.CTB" 
"NO" ;PLOT WITH LINEWEIGHTS
"NO" ;SCALE LINEWEIGHTS WITH PLOT SCALE
"YES" ;PLOT PAPER SPACE LAST
"NO" ;REMOVE HIDDEN LINES
"NO" ;WRITE THE PLOT TO A FILE
"NO" ;SAVE CHANGES TO LAYOUT
"YES");PROCEED WITH PLOT
 )
 (princ)
)

It works

 

BUT

 

some of my AutoCad files incorporate the Model tab into the layout list and I don't want that. So to rectify the problem, i'd like to place a model tab exclusion string into the lisp code.

 

I sourced this piece of code from the internet. It compiles an alphabetic layout tab order and removes the Model space tab from its list. How can I incorporate that piece of code into my existing routine?

 

;create list of layout tabs (in proper order)
(defun layouttablist (/ lst)
 (vlax-map-collection
   (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
   '(lambda (x) (setq lst (cons x lst))))
;;  sort in tab order
 (setq lst (vl-sort lst '(lambda (x y)
                           (< (vla-get-taborder x) (vla-get-taborder y)))))
;;  make list of names into strings  remove Model space
 (setq lst (vl-remove "Model" (mapcar '(lambda (x)(vla-get-name x))lst)))
)

Thanks

Link to comment
Share on other sites

Alternatively, another possibility:

 

(foreach layoutname
 (mapcar 'cdr
   (vl-sort
     (
       (lambda ( / l n )
         (vlax-for x
           (vla-get-Layouts
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
           (if (not (eq "MODEL" (strcase (setq n (vla-get-Name x)))))
             (setq l (cons (cons x n) l))
           )
         )
         l
       )
     )
     (function
       (lambda ( a b )
         (< (vla-get-TabOrder (car a)) (vla-get-TabOrder (car b)))
       )
     )
   )
 )
...
)

Or, in Vanilla perhaps:

 

(foreach layoutname
 (
   (lambda ( dict / def l n )
     (while (setq def (dictnext dict (null def)))
       (if (not (eq "MODEL" (strcase (setq n (cdr (assoc 1 (reverse def)))))))
         (setq l (cons n l))
       )
     )
     (reverse l)
   )
   (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
 )
...
)

Link to comment
Share on other sites

(layoutlist) doesn't include Model.

 

Yeah, I didn't think so either - but the OP states that some of his files do include it.

 

BUT some of my AutoCad files incorporate the Model tab into the layout list
Link to comment
Share on other sites

Yeah, I didn't think so either - but the OP states that some of his files do include it.
Wild. Must be an freaky thing with older versions. Might have something to do with files that could have been created with r14 (before layouts existed).

 

To answer the OP's question:

Replace: (foreach layoutname (layoutlist )

With: (foreach layoutname (layouttablist)

Link to comment
Share on other sites

So I tried replacing layoutlist with layouttablist and got the following:

Command: (layouttablist)
; error: no function definition: LAYOUTTABLIST

This is what I get when I simply use layoutlist in the offending drawing:

Command: (layoutlist)
("Layout1" "Model")

Mind you, if I use layoutlist in other drawings, it works fine and i'll get:

Command: (layoutlist)
("Layout1")

So I suspect something is up inside that specific offending drawing. A setting or switch i'm not aware of.

 

I incorporated (vl-remove "Model" (layoutlist)) into the code but it didn't eliminate the model tab selection.

(defun c:Plt (/ )
 (foreach layoutname (layoutlist )
 (vl-remove "Model" (layoutlist)) ;<---------------
   (command "._layout" "set" layoutname )
   (command "-plot" 
"yes" 
layoutname 
"etc etc...."

Then I copied the following into my routine

(defun c:Plt (/ )
 ;(foreach layoutname (layoutlist )
(foreach layoutname
 (mapcar 'cdr
   (vl-sort
     (
       (lambda ( / l n )
         (vlax-for x
           (vla-get-Layouts
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
           (if (not (eq "MODEL" (strcase (setq n (vla-get-Name x)))))
             (setq l (cons (cons x n) l))
           )
         )
         l
       )
     )
     (function
       (lambda ( a b )
         (< (vla-get-TabOrder (car a)) (vla-get-TabOrder (car b)))
       )
     )
   )
 )
   (command "._layout" "set" layoutname )
   (command "-plot" 
"yes" 
layoutname 
"etc etc...."

and that does the trick. Hopefully I won't run into any other problems. Thanks for your help!

 

I can now use this lisp file in conjunction with EZScriptpro and print the approx 400 drawings to complete my project. I didn't like Batch Plot Utility because it would open all the drawings and slow my computer down. With EZScriptpro, it opens a drawing, runs the lisp file, closes the drawing and continues the process. Thanks!

Link to comment
Share on other sites

I incorporated (vl-remove "Model" (layoutlist)) into the code but it didn't eliminate the model tab selection.

(defun c:Plt (/ )
 (foreach layoutname (layoutlist )
 (vl-remove "Model" (layoutlist)) ;<---------------
   (command "._layout" "set" layoutname )
   (command "-plot" 
"yes" 
layoutname 
"etc etc...."

 

This is because you incorporated it incorrectly:

 

(defun c:Plt ( / )
 (foreach layoutname [color=red][b](vl-remove "Model" (layoutlist))[/b][/color]
   (command "._layout" "set" layoutname)
   (command "-plot" 
"yes" 
layoutname 
"etc etc...."

Link to comment
Share on other sites

Works great and thanks for the clarification.

 

Lastly, now that you've provided two different ways to accomplish the same task, is one routine superior to the other?

 

 

edit:

 

Scratch the question. I see that one of them organizes the tabs.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...