Hi Everyone,
Please help me to create automatic layouts for the attached drawing
Also request you to please provide me the LISP/FAS file.
The attache dwg is simple drawing. But i have 200 grids in some cases.
Please help on this.
Thank you in advance.
Solved! Go to Solution.
Solved by lando7189. Go to Solution.
Your drawing uses proxy graphics so when I open it all I have is a bunch of boxes with a bit of text. I'm not sure what you want from what I see in the drawing I get.
The green color boxes are grids. For all the grids that are in model space i need to create automatic layout with zoomed view of each grid in each layout .
In the attached drawing, in the layout page i have one Title block is there. If i run the automatic tool/lisp, the grid in the model page should fit inside of title block area.
I hope you understand my problem.
Please help me on this.
Thanks in advance...
Regards,
Sudhakar
This should get you started.
(defun GridsToLayouts ( / ss layout i elists elist enam page prevpage vp id ptmin ptmax) (vl-load-com) (cond ((not (setq ss (ssget "x" (list (cons 8 "GRID"))))) (princ "\nNo entities on layer 'GRID' found.") ) ((not (member "001" (layoutlist))) (princ "\nLayout 001 not found.") ) (T (setq i 0 prevpage "001") (while (< i (sslength ss)) (setq elists (cons (entget (ssname ss i)) elists) i (1+ i)) ) (setq elists (vl-sort elists (function (lambda (e1 e2) (< (cadr (assoc 10 e1)) (cadr (assoc 10 e2)))))) i 0) (foreach elist elists (setq enam (cdr (assoc -1 elist)) i (1+ i) page (strcat "000" (itoa i)) page (substr page (- (strlen page) 2)) ) (if (not (member page (layoutlist))) (command "._layout" "c" prevpage page) ) (command "._layout" "s" page "._pspace") (if (setq ssvp (ssget "x" (list (cons 0 "VIEWPORT") (cons -4 "<AND") (cons -4 ">") (cons 40 700.0) (cons -4 ">") (cons 40 400.0) (cons -4 "AND>")))) (progn (setq id (cdr (assoc 69 (entget (setq vp (ssname ssvp 0)))))) (command "._mspace") (setvar "CVPORT" id) (vla-getboundingbox (vlax-ename->vla-object enam) 'ptmin 'ptmax) (vla-zoomwindow (vlax-get-acad-object) ptmin ptmax) (command "._pspace") ) (princ (strcat "\nUnable to find large viewport of at least 700x400 on page " page)) ) (setq prevpage page) ) ) ) ) (defun C:GridsToLayouts nil (GridsToLayouts) (princ))
Here is version 2 with a few additional bug catches (and bug fixes).
(defun GridsToLayouts ( / ss i elists elist enam page prevpage ssvp vp id ptmin ptmax) (vl-load-com) (cond ((not (setq ss (ssget "x" (list (cons 8 "GRID"))))) (princ "\nNo entities on layer 'GRID' found.") ) ((not (member "001" (layoutlist))) (princ "\nLayout '001' not found.") ) ((> (length (layoutlist)) 1) (princ "\nOnly layouts 'Model' and '001' should exist.") ) (T (setq i 0 prevpage "001") (while (< i (sslength ss)) (setq elists (cons (entget (ssname ss i)) elists) i (1+ i)) ) (setq elists (vl-sort elists (function (lambda (e1 e2) (< (cadr (assoc 10 e1)) (cadr (assoc 10 e2)))))) i 0) (princ "\nCreating layouts...") (foreach elist elists (if (and elist elists) (progn (setq enam (cdr (assoc -1 elist)) i (1+ i) page (strcat "000" (itoa i)) page (substr page (- (strlen page) 2)) ) (princ (strcat "\nCreating layout '" page "'... ")) (if (not (member page (layoutlist))) (vl-cmdf "._layout" "c" prevpage page) ) (vl-cmdf "._layout" "s" page "._pspace") (if (setq ssvp (ssget "x" (list (cons 0 "VIEWPORT") (cons -4 ">") (cons 40 700.0) (cons -4 ">") (cons 41 400.0)))) (progn (setq id (cdr (assoc 69 (entget (setq vp (ssname ssvp 0)))))) (vl-cmdf "._mspace") (setvar "CVPORT" id) (vla-getboundingbox (vlax-ename->vla-object enam) 'ptmin 'ptmax) (vla-zoomwindow (vlax-get-acad-object) ptmin ptmax) (vl-cmdf "._pspace") (vla-zoomextents (vlax-get-acad-object)) ) (princ (strcat "\nUnable to find large viewport of at least 700x400 on page " page)) ) (setq prevpage page) (if (= (length (layoutlist)) 255) (progn (princ "\nMaximum number of layouts met.") (setq elists nil) ) ) (vla-eval (vlax-get-acad-object) "DoEvents") ) ) ) (princ "\... GridsToLayouts finished.") ) ) ) (defun C:GridsToLayouts nil (GridsToLayouts) (princ))
At Very First, I want to say thank you to you for providing this help.
Whereas I got some issues while running the lisp. Please find the following details.
1. First provided lisp i can able run on test drawing which i have provided successfully. But i cannot able to run the second lisp on the same drawing.
2. I have one drawing (attached here) contains the grids are in not sequentially which means different locations. And i cannot able to run the both lisps on this drawing.
3. Also please help me the grid which is generated in the respective layout that grid view also need to come in the bottom right corner in the layout (screenshot attached).
Requesting you to please help me on these issues.
Thank you so much in advance.
Regards,
Sudhakar.
Good to hear back from you. I just noticed you are a new member, so welcome to the Forums!
I see that the new 'test' drawing you provided uses blocks for the grids... much better than just entities, plus having an attribute as an ID is a good.
Here is the revised code:
(defun GridsToLayouts ( UseUndoMarks / GridLayer GridAttribute SourceLayout TitleBlockHeight KeyZoomFactor TitleBlockName TitleBlockSheetNumberAttribute TitleBlockTotalSheetsAttribute vl-GetAttributeValue ss i enam edata grids grid id previd ssvp1 vp1 vpno1 ssvp2 vp2 vbno2 ptmin ptmax) (vl-load-com) ;;;*SOME SETTINGS THAT CAN BE CUSTOMIZED (setq GridLayer "GRID") (setq GridAttribute "MAPSHTNUM") (setq SourceLayout "001") (setq TitleBlockHeight 86) (setq KeyZoomFactor 0.5) ;(setq TitleBlockName "XXX_2") ;(setq TitleBlockSheetNumberAttribute "SHEET_NO") ;(setq TitleBlockTotalSheetsAttribute "NO_OF_SHEETS") (defun vl-GetAttributeValue ( blk tag ) (setq tag (strcase tag)) (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke blk 'getattributes) ) ) (cond ((not (setq ss (ssget "x" (list (cons 0 "INSERT") (cons 8 GridLayer))))) (princ (strcat "\nNo grid blocks on layer '" GridLayer "' found.")) ) ((not (member SourceLayout (layoutlist))) (princ (strcat "\nSource layout '" SourceLayout "' not found.")) ) ((> (length (layoutlist)) 1) (princ (strcat "\nOnly layouts 'Model' and '" SourceLayout "' should exist.")) ) (T (setq i 0) (while (< i (sslength ss)) (setq edata (entget (setq enam (ssname ss i)))) (if (and (= (cdr (assoc 0 edata)) "INSERT") (setq attval (vl-GetAttributeValue (vlax-ename->vla-object (cdr (assoc -1 edata))) GridAttribute)) ) (setq grids (cons (cons attval enam) grids)) ) (setq i (1+ i)) ) (setq grids (vl-sort grids (function (lambda (e1 e2) (< (car e1) (car e2)))))) (if UseUndoMarks (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))) (if grids (princ "\nCreating layouts...") (princ "\nNo grids found...") ) (foreach grid grids (if grids (progn (setq id (car grid) enam (cdr grid)) (princ (strcat "\nCreating layout '" id "'... ")) (if (not (member id (layoutlist))) (command "._layout" "c" previd id) ) (command "._layout" "s" id "._pspace") (if (and (setq ssvp1 (ssget "x" (list (cons 0 "VIEWPORT") (cons -4 "*,>,*") (list 10 0 TitleBlockHeight 0)))) (setq ssvp2 (ssget "x" (list (cons 0 "VIEWPORT") (cons -4 "*,<,*") (list 10 0 TitleBlockHeight 0)))) ) (progn (vla-getboundingbox (vlax-ename->vla-object enam) 'ptmin 'ptmax) (setq vpno1 (cdr (assoc 69 (entget (setq vp1 (ssname ssvp1 0)))))) (setq vpno2 (cdr (assoc 69 (entget (setq vp2 (ssname ssvp2 0)))))) (command "._mspace") (setvar "CVPORT" vpno1) (vla-zoomwindow (vlax-get-acad-object) ptmin ptmax) (setvar "CVPORT" vpno2) (vla-zoomwindow (vlax-get-acad-object) ptmin ptmax) (vla-zoomscaled (vlax-get-acad-object) KeyZoomFactor acZoomScaledRelative) (command "._pspace") (vla-zoomextents (vlax-get-acad-object)) ) (princ (strcat "\nUnable to find the two vieports needed for layout " id)) ) (setq previd id) (if (= (length (layoutlist)) 255) (progn (princ "\nMaximum number of layouts met.") (setq grids nil) ) ) (vla-eval (vlax-get-acad-object) "DoEvents") ) ) ) (princ "\... GridsToLayouts finished.") (if UseUndoMarks (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))) ) ) ) (defun C:GridsToLayouts nil (GridsToLayouts T) (princ))
Hi lando7189,
Thank you for inviting to me into forum.
Thank you for providing such a great help to me. But I'm getting a error while running the lisp. Please find the attachment for your reference
Do i need to follow any steps before running the lisp?
Could you please help me on this.
Regards,
Sudhakar.
Ah... you will need to download and install the VBA module for the version of AutoCAD and 32 or 64 bit platform you are using. They can be found here:
In the code, i started looking into possibly setting some of your page numbering attributes in your titleblock -- i didn't go any further on it because i noticed that the total pages in the title block is different then the number of layouts created (i am guessing that you must add some additional pages to the layouts created and use something else to control your titleblock).
Thank a lot lando7189.
I Can able run now...This is so much useful for me.
Thanks Again.
Regards,
Sudhakar.
Glad it works for you! I may find use for a version of this at my company...haha!
Have a great day! - Lanny
Hello, i have almost the same request.
I have also a block with an attribute in the modelspace of the drawing.
The block have different angles and diffent sizes.
What i want is an automatic creation of layouts from all this blocks.
In the attribute is the name of te layout.
I also get the same error "automation error.......failed" when i tried to run the lisp.
VBA is installed and working correctly.
Regards
Henk
Hi Troy,
i tried your Grids to layouts lisp its really amazing. it works great fro me.
And i have some requirements to be add to that lisp
1) i have several grids in my drawing and all the grids contain some number in MTEXT. that mtext should enter in layout CTAB as per grid
is it possible to do all at once? (Refer image 1)
2) And i need to enter adjacent layout numbers in the respective layout tab (refer image 2)
too many conditions vishwa0121. let me try my friend.
Regards,
best buddy
vishwa0121
This is not a problem.
Attach an example of your dwg file.
like this ?
new file attached
@maratovich wrote:like this ?
new file attached
I think your viewport scale is wrong. The example dwg uses 50 scale and yours is 1? Here is another take on it.
(defun c:foo (/ ad ll n p pv s tab) (cond ((setq s (ssget '((0 . "text") (8 . "CHR_FIELD_MAP_TEXT") (410 . "Model")))) (setq s (vl-sort (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) '(lambda (a b) (< (cdr (assoc 1 (entget a))) (cdr (assoc 1 (entget b))))) ) ) (setq ad (vla-get-activedocument (vlax-get-acad-object))) (foreach e s (cond ((vl-position (setq n (strcase (cdr (assoc 1 (entget e))))) (mapcar 'strcase (layoutlist))) (print (strcat "Layout " n " already exists...")) ) ((setq tab (vla-add (vla-get-layouts ad) n)) (setvar 'ctab n) ;; Viewport hard coded based on example drawing (setq pv (vlax-invoke (vla-get-paperspace ad) 'addpviewport '(8.0694 5.03978 0.0) 14.875 10.25 ) ) (vlax-put pv 'viewporton -1) (command "_.mspace") (vlax-invoke (vlax-get-acad-object) 'zoomcenter (cdr (assoc 11 (entget e))) 50) (vla-put-customscale pv (/ 1. 50)) (command "_.pspace") ) ) ) ) ) (princ) ) (vl-load-com)
I think your viewport scale is wrong. The example dwg uses 50 scale and yours is 1?
I can set any scale. You can + - the size of the viewport, and other parameters.
At the same time, the viewport is set to the desired printer, paper size, printing style.
Full preparation for publication.
You can directly print from the space model.
Can't find what you're looking for? Ask the community or share your knowledge.