Hello, I have several DWG drawings that contain all the sheets of the document stacked on top of each other in model space. In layer 0, I have the title block, which is the same for all pages, and in layer 1, I have the information for page 1, in layer 2 for page 2, and so on. If I activate all the layers, all the sheets appear stacked on top of each other, making it impossible to distinguish them. What I want is to create a new layout for each page with the same viewport and activate the VP freeze 0 for the title block and for each specific page. Is it possible to create a routine to do this?
I've attached a sample DWG file. The LISP file should create Layouts 1, 2, 3, and 4, and so on, depending on the number of pages in the document.
Thank you.
Solved! Go to Solution.
Solved by Sea-Haven. Go to Solution.
This is what I can advance with the code; it can only create the layouts with the name of each layer. I still need to configure each viewport to activate and deactivate the corresponding VP freeze settings.
(defun c:CreateLayoutsFromLayers (/ doc layers layerName layoutName layObj)
;; Get the active document
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
;; Get the list of layers in the drawing
(setq layers (vla-get-Layers doc))
;; Iterate over each layer to create a corresponding layout
(vlax-for layer layers
(setq layerName (vla-get-Name layer)) ; Get the name of the layer
;; Exclude special layers that we do not want to create as layouts
(if (and (/= layerName "0") (/= layerName "Defpoints"))
(progn
(setq layoutName layerName) ; Use the layer name as the layout name
;; Create the layout with the corresponding name
(setq layObj (vla-Add (vla-get-Layouts doc) layoutName))
;; Here you can add more configurations for each layout if desired
)
)
)
;; Completion message
(princ "\nLayouts created successfully based on layer names!")
(princ)
)
(princ "\nUse the command 'CreateLayoutsFromLayers' to create layouts for each layer.")
(princ)
I think need a rolling layer list every time a layout is made the list is reorganised so 1st now becomes last, 2nd becomes 1st as I called just a guess description name a rolling list.
(1 2 3 4)
(2 3 4 1)
(3 4 1 2)
(4 1 2 3)
Need time to think about it.
Thank you for your time. That is one possible solution that I can think of. Another could be to move all the sheets along the X-axis by a certain distance. For example, move layer 1 by 500mm, layer 2 by 2x(500mm), layer 3 by 3x(500mm), and so on. Then, see how to create the layouts. I'm not sure; I'm actually looking for a way to make the plans functional. Thank you very much.
What if you wblocked each layer out as a separate dwg and each will also contain the title block layer?
That would be inconvenient; I have files with more than 200 pages. I am trying to organize them within a single DWG file.
Just not a good idea to vplayer freeze layer 0 in a vport. Because there may be other objects like blocks that may have been inserted on that layer. Then those would disappear. Perhaps move the title block objects to a new layer and vplayer freeze that new layer instead.
I don't need to VPFREEZE layer 0; it should be on in all the viewports because it contains the title block, which is the same for all the sheets. I only need to VPFREEZE all the layers that do not contain information related to the current page.
In any case, I am currently trying to move the pages incide the model space. I think it might be better to move the pages incide the model space to avoid having to use VPFREEZE.
thanks for the advice!
Your OP:
”…and activate the VP freeze 0 for the title block…”
was that 0 a typo?
Apologies for my mistake; what I meant to say is that I need to VPFREEZE all the layers except for layer 0 and the layer corresponding to the page.
In the example I attached, the layouts are created as they should look after executing the LISP.
Had a Customer that demanded that each sheet be on a Sheet#x Layer.
They had in one case about 190 sheets for a Controls Electrical set. I cannot share
the Customer's name, but what happened, is that by /zipping the final single drawing,
and /unzipping at the Customer's site, all H*ll broke out. Could not 'recover', couldn't Open it.
So, I hand carried the final .dwg to them, it took 15 minutes to 'Open' in R2012 Acad.
They then tried to 'plot' it to 11x17 for a panel folder for the shop floor. Never did get
a working copy after 3 days of effort.
So , my advice as an expert in the matter. Wblock all that stuff out to seperate files.
ECCAD
Yep that’s the risk of having all your eggs in one basket. It can be convenient when everything works. But one bit of corruption and then it’s game over.
Using this,
(setq layers (vla-get-Layers doc))
I get Count (RO) = 548 layers this is excessive so need to actually get a layer list of what actually does exist in terms of used layers so a Purge Layers should be done 1st. brings the list way down. 1 purge = 100. As this is a civ3D dwg you need to run purgestyleandsettings to remove layers that are linked to the CIV3D database, then run purge again.
So easiest way is maybe get a selection set of Model only all objects and then make a layer list. Note you must have a predefined layout with your title block etc change the "D01".
(defun c:wow ( / laylst lay )
; By Gile
(defun remove_doubles (lst)
(if lst
(cons (car lst) (remove_doubles (vl-remove (car lst) lst)))
)
)
(setq ss (ssget "X" '((410 . "Model"))))
(setq laylst '())
(repeat (setq x (sslength ss))
(setq lay (cdr (assoc 8 (entget (ssname ss (setq x (1- x)))))))
(setq laylst (cons lay laylst))
)
(setq laylst (mapcar 'cdr (vl-sort (mapcar '(lambda (x) (cons 1 x)) laylst) '(lambda (y z) (< (cdr y) (cdr z))))))
(setq laylst (remove_doubles laylst))
(if (member "0" laylst)
(setq laylst (vl-remove "0" laylst))
)
(if (member "Defpoints" laylst)
(setq laylst (vl-remove "Defpoints" laylst))
)
(setvar 'clayer "0")
(foreach lay laylst
(command "layout" "Copy" "D01" lay)
(setvar 'ctab lay)
(command "mspace")
(command "zoom" "e")
(command "vplayer" "F" "*" "" "T" lay "" "")
)
(princ)
)
(c:wow)
Thank you for the code; it worked with my example. However, should I create manually each of the layouts before running the LISP?
I was testing the code more thoroughly and it was very helpful, thank you so much, really "wow". Would it be possible to activate layer 0 in all views? Since that layer has the title block. Thank you very much.
EDIT:
(command "vplayer" "T" "0" "" "") ;activate layer 0 in all viewports if needed
Thanks for your help!
Glad to have helped, change wow to something else, same with "D01" just make sure you have 1 correct layout before starting as it copies that layout so just need title block in that layout in Paper space.
Can't find what you're looking for? Ask the community or share your knowledge.