Can I specify which layout to plot?

Can I specify which layout to plot?

jim.lawRPHLY
Contributor Contributor
1,359 Views
29 Replies
Message 1 of 30

Can I specify which layout to plot?

jim.lawRPHLY
Contributor
Contributor
I could really use your help! I am not a lisp guy at all but can read them for the most part. I am really lost trying to figure out where this lsp is pulling the names of the layout to plot.
Let me explain how this is supposed to work....
 
The user is asked if this is a prelim or final set they want to plot. If they say Prelim, it only is to plot certain layouts (4 of the 21 existing layouts). It will then purge the drawing, bind xrefs, and plot to a specific directory.
If it is a final it does the same but plots all the layouts.
 
We have since added new layouts and need some of them to plot in prelim. For the life of me I cannot see where that list of layouts is defined!! IS there a way I can manually put into the code which layouts, by name, to plot??
 
This is what it looks like.........
 
(defun DoBind ( / StateName )
 
(command "undo" "begin")
(command "model")
(command "zoom" "e")
(command "tilemode" 0)
(command "zoom" "e")
(command "-xref" "r" "*")
(command "-xref" "b" "*")
 
; If Prelim, delete unnecessary sheets.  If Final, skip this part
(if (= request "P") 
(progn
(setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
 
; For every layout tab in the drawing...
(vlax-for x (vla-get-layouts acdoc)
; ...make a new list item from the layout's tab number
; and name then add it to a list of such items
(setq layouts (cons (cons (vla-get-taborder x) (vla-get-name x)) layouts))
)
 
; Sort the layouts list by the first element of 
; each item (tab order) and save into new list 
; called lbto (layouts by tab order)
(setq lbto 
(cdr
    (mapcar 'cdr
            (vl-sort layouts
                    (function (lambda (x y) (< (car x) (car y))))
            )
    )
)
)
 
; Make a new list of layouts from AD1 and after
(setq delsheets (member "AD1" lbto))
 
; Delete each layout in the new list
(foreach sheet delsheets
(command "_.layout" "Delete" sheet)
)
)
)
 
; Purge after all other commands are done
(vla-purgeall (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-purgeall (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-purgeall (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-purgeall (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-purgeall (vla-get-ActiveDocument (vlax-get-acad-object)))
 
(command "undo" "end")
 
; If bound version already exists, this handles the file dialog for the user
(if (= exist 1)
(progn
(setvar "filedia" 0)
(command "saveas" "" savename "y")
(setvar "filedia" 1)
)
(progn
(vl-mkdir bindpath)
(setvar "filedia" 0)
(command "saveas" "" savename)
(setvar "filedia" 1)
)
)
)
 
;; Do Not Bind subfunction
(defun DoNotBind ( / )
(alert "Drawing not bound")
)
 
;; Main Function
(defun C:pbp ( / bindpath savename overwrite exist request)
 
;Commands in silent mode.
(setq oldosmode (getvar "osmode"))
(setq oldcmdecho (getvar "cmdecho"))
(setq oldnomutt (getvar "nomutt"))
(setvar "osmode" 0)
(setvar "cmdecho" 0)
(setvar "nomutt" 0)
 
; Ask if Prelim or Final
(initget "P F")
(setq request (getkword "\nRequest type [Prelim/Final]: "))
 
; Construct the path to deliverables folder from active drawing's path
(setq bindpath (vl-string-subst "\\Deliverables\\" "\\Drawings\\" (getvar "dwgprefix")))
 
; Combine deliverables path with current filename to see if already exists
(setq savename (strcat bindpath (vl-filename-base (getvar "dwgname"))))
 
; If bound version already exists, prompt to overwrite it or not
(if (findfile (strcat savename ".dwg"))
(progn
(setq exist 1)
(initget "Y N")
(setq overwrite (getkword "\nDeliverables already exist - Overwrite? [Yes/No]: <N>"))
(if (= overwrite "Y")
(DoBind) (DoNotBind)
)
)
; If no bound version exists, create one
(DoBind)
)
 
; Export to PDF (skip if user chose not to overwrite existing files)
(setvar "filedia" 0)
(setvar "nomutt" 1)
(if (= exist 1)
(if (= overwrite "Y")
(command "-export"
"p"
"a"
savename
"y"
)
)
(command "-export"
"p"
"a"
savename
)
)
(setvar "filedia" 1)
 
 
 
;Reset to original "osmode" and "cmdecho".
(setvar "osmode" oldosmode)
(setvar "cmdecho" oldcmdecho)
(setvar "nomutt" oldnomutt)
 
(princ)
(princ)
)
0 Likes
Accepted solutions (1)
1,360 Views
29 Replies
Replies (29)
Message 2 of 30

pendean
Community Legend
Community Legend

Q: do you folks use SSM (SheetSet Manager) with all of those layouts? Organizing sets like that is what it's best at, and publishing is just a right-click away too @jim.lawRPHLY 

0 Likes
Message 3 of 30

jim.lawRPHLY
Contributor
Contributor

We do not use sheets sets unfortunately! 

0 Likes
Message 4 of 30

ec-cad
Collaborator
Collaborator
(setq layout-list (layoutlist))

ECCAD

0 Likes
Message 5 of 30

paullimapa
Mentor
Mentor

It's good that the lisp code you posted does a great job commenting so you can tell exactly what it does. The section of the code that gives you the clue as to what layouts are actually deleted from the drawing so it won't "plot" is this:

; Make a new list of layouts from AD1 and after
(setq delsheets (member "AD1" lbto))

So whatever layouts you want to keep just move them so their position is before a layout named "AD1"

As an example, the code will delete the two layout tabs including "AD1": A3-Section & A4-Details

paullimapa_0-1743538801096.png

But I don't see anywhere in the code you posted that would "PLOT" all the remaining layouts. I do see a section at the end that "EXPORTs" the remaining layouts to PDF if that's what you mean.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 6 of 30

jim.lawRPHLY
Contributor
Contributor

THANKS! But I apologize, then what? I am not a programmer! 🙂

In the code I pasted, where would it go and what would it look like if we were using layout names like 1,2,3,4 ect... ??

0 Likes
Message 7 of 30

paullimapa
Mentor
Mentor

You don't actually have to be a programmer because as I said all you have to do in AutoCAD is move those layouts you want to keep in front of the layout called "AD1"

To move a layout right mouse click on that layout tab like in this example "A3-Section"

Then on the cursor menu select Move or Copy...

On the Move or Copy window select AD1 & click OK

Now layout A3-Section will be moved in front of layout AD1 so it won't be deleted.

paullimapa_0-1743539468212.png

paullimapa_1-1743539484561.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 8 of 30

jim.lawRPHLY
Contributor
Contributor

Great explanation! BUT Moving them would mess up the order if it was a "final" plot/export

It is possible to specify 2 sets of ranges in the code you sent me? example.... for prelim remove AD1-NN and all after R-S1-1???

jimlawRPHLY_0-1743539730926.png

THANKS FOR THE GREAT SPEEDY REPLIES!

0 Likes
Message 9 of 30

paullimapa
Mentor
Mentor

Well, I assume you're not going to use the same drawing for the Final plot because the lisp code would have removed those layouts for the Prelim

But since you do want to include all layouts in your final plot, after running the code for Prelim I assume you would not save the dwg but just quit out of it, right?

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 10 of 30

jim.lawRPHLY
Contributor
Contributor

They save as before they run this!

 

0 Likes
Message 11 of 30

paullimapa
Mentor
Mentor

Exactly, so the dwg is saved, then the lisp code is run.  So the layouts deleted would not be saved because you're going to quit out of the dwg. Then you'll open up the saved dwg and continue working on that.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 30

jim.lawRPHLY
Contributor
Contributor

CORRECT!

 

0 Likes
Message 13 of 30

paullimapa
Mentor
Mentor

So just move the layouts RA-1.1 & RA-1.2 in front of AD1 then run the code you posted to get the Export PDFs you need for Prelim. Then close out of the dwg without saving and you’re done. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 30

jim.lawRPHLY
Contributor
Contributor

Moving the layouts, just to plot, will give them fits. These planners are spoiled! 😉 I will play with it tomorrow! Will let you know! THANIKS AGAIN!

0 Likes
Message 15 of 30

paullimapa
Mentor
Mentor

Though you can manually hold the Ctrl+left mouse key to select multiple layouts then release the Ctrl key to move them as a group from one position to another you may also want to play with this free lisp routine called TabSort.lsp by Lee Mac.

It'll give you a GUI to let you do all kinds of things with layout tabs including selecting more than one to move as a group.

https://www.lee-mac.com/tabsort.html

paullimapa_0-1743542009193.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 16 of 30

paullimapa
Mentor
Mentor

If those layout names are always the same another words AD1 through NN appears first and then afterwards R-S1.1, then you can try loading & running the attached modified PBP.lsp code.

If you need to rename those layout names then change this section of the code:

; Declare layout names to look for
(setq layout-begin "AD1"
      layout-end   "NN"
      layout-rest  "R-S1.1"
)  

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 17 of 30

Sea-Haven
Mentor
Mentor

My laptop is broken but if you do a search here for plotpdfA3.lsp by me it plots layouts based on a range so you could do plot 1. - 5 , 1 - 99 for all. You can edit code to suit your layout title block. Posted on my IPad.

Message 18 of 30

jim.lawRPHLY
Contributor
Contributor

@Sea-Haven, a search came up empty....... thanks for your reply!

 

0 Likes
Message 20 of 30

jim.lawRPHLY
Contributor
Contributor

Everything is great! It deletes all of the layouts, except for the ones I want, BUT it does not include the 2 "R" layouts in the export, just the first 3!

Am I missing something? 

jimlawRPHLY_0-1743619931166.png

 

0 Likes