How to create automatic layouts

Anonymous

How to create automatic layouts

Anonymous
Not applicable

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. 

0 Likes
Reply
Accepted solutions (1)
34,128 Views
114 Replies
Replies (114)

istvan_voiculescu
Enthusiast
Enthusiast

What these two refer to? 

(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))))

I understand that the first refers to the first viewport, and the second to the second viewport, but I don't understand the conditions.

 

I am trying to adapt the routine to my layout, but no matter what viewport I make it always ends just creating the layouts and not getting the viewports scaled to the object. But however it works with the layout that was used as a template. Trying to compare that layout and viewport with my layout and viewport I cannot seem to find the difference... I think it is tied to that specific viewport created that maybe is defined in the lisp routine somehow, but cannot see where to change to make it work. So yeah, it works only with the original layout and viewport.

 

So can anyone decodify the line for me? 🙂 

 

I am trying to make the routine work for both cases with one viewport and one viewport and a keymap viewport...

 

ISTVAN “ISHKA” VOICULESCU
CAD/IT Systems Admin Sr.
BIM / CADD MANAGER
CITY OF AUSTIN, PUBLIC WORKS DEPARTMENT
ENGINEERING SERVICES DIVISION
0 Likes

paliwal222
Advocate
Advocate

Dear

sudhakar would you please explain me how you made "Test2.dwg"

Thanks

0 Likes

paliwal222
Advocate
Advocate

Dear sir,

would you please tell how to prepared a drawing before execute this lisp.

specially draw rectangle block and their numbering include attribute with in. 

Thanks.

0 Likes

saifudheen.pottoorD54SH
Observer
Observer
0 Likes

longhien2022
Explorer
Explorer

When I create automatic layouts with drawing :LONG1.LISP works fine. But when I change VIEWPORT position with drawing :Long2 to match my commonly used name frame, lisp doesn't work properly. Please help me adjust the lisp so that with drawing:Long2 works

 

z3600394256874_7e0b1debbccc476916217c3f971a25fa (1).jpg

0 Likes

roherad916
Participant
Participant

Hi, this code its very helpful for me, even nowadays, thanks!

Can you help me with some modifications?

I need to delete the 2nd viewport function and I need to change NO_OF_SHEETS for NEXT_SHEET

My blocks are aligned and separated a fixed distance on the X axis, so the order of the pages must be ascending on the X axis

 

I attach my drawing

 

Hope you can help me, 

Regards!

0 Likes

roherad916
Participant
Participant

Hi, to make it work with only one viewport refer to next link

 

https://forums.autodesk.com/t5/autocad-todos-los-productos/crear-layouts-de-forma-automatica-desde-e...

 

 

regards

 

0 Likes

roherad916
Participant
Participant
Hi,
Does this part of the code works?

;(setq TitleBlockName "XXX_2")
;(setq TitleBlockSheetNumberAttribute "SHEET_NO")
;(setq TitleBlockTotalSheetsAttribute "NO_OF_SHEETS")

Can't make it work, the number of sheets its the same in all tabs.


Regards
0 Likes

Amriya_Exe
Advocate
Advocate

someone please guide steps to make it work newbie.

What commands to use and how to config according to our requirement? 

0 Likes

Sea-Haven
Mentor
Mentor

Happy to discuss, the issue is everyone has different size title blocks and view ports so must customise the software to suit. This is mine.

SeaHaven_0-1672291173704.png

The end result in this case follows a pline or it can be grids of reactangs.

SeaHaven_1-1672291306058.png

0 Likes

YAYA.SADA
Advocate
Advocate
Hello friends,
I would like to adapt the "GridsToLayouts.lsp" lisp from @lando7189 to my "CFA-F_A3_2014" block,
I don't need the additional window at the bottom right.
The only thing that interests me is to be able to select my rectangles in model space and to have the page number (Folio attribute of the model space rectangle) indicated in this rectangle (ex. 01a or 02b etc).
I attach a dwg so that you can understand me.
In the object space I drew rectangles in red which could correspond to any drawing.
Thanks in advance to those who will help me.

 

0 Likes

Sea-Haven
Mentor
Mentor

So a layout for every block. The layout has a title block appears to be a A3 size, custom scale I think should be 1.00 but make the mview match just inside the layout same as you have now. The way to go is work out centroid of block and use that in the mview property centre. I have make rectangs and then layouts, so will have a think about it  based on your blocks.

 

 

0 Likes

YAYA.SADA
Advocate
Advocate

Hi,

Thank you,

but i have problem, i have this message 

"Automation error Problem loading VBA" when i launch the lisp
Sorry i'm novice on the lisp and sorry for my english.
I deleted lines which for me seems useless, because I don't want to have a second viewport, and I don't need the total number of sheets either.
On the other hand, I will need to be able to select the blocks of the model space myself and also that the folio numbers of its same blocks are reflected as sheet numbers.
(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                        "INEO-CADRE-FENETRE-E")
  (setq GridAttribute                    "FOLIO")
  (setq SourceLayout                     "03a")
  (setq TitleBlockHeight                 23)
  (setq KeyZoomFactor                    0.971)
  ;(setq TitleBlockName                   "CFA-F_A3_2014")
  ;(setq TitleBlockSheetNumberAttribute   "FOL")
 
  (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))))
              )
            (progn
              (vla-getboundingbox (vlax-ename->vla-object enam) 'ptmin 'ptmax)
              (setq vpno1 (cdr (assoc 69 (entget (setq vp1 (ssname ssvp1 0))))))
              (command "._mspace")
              (setvar "CVPORT" vpno1)
              (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 viewport 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:GridsToLayouts2 nil (GridsToLayouts T) (princ))
0 Likes

Sea-Haven
Mentor
Mentor

Its your lucky day, you owe me a beer. two things moved the block "E0-Cadre" so left corner is 0,0. The other is renamed the layout to Master and set the mview to unlocked. So if using a template edit these items. You can change the layout name in your dwg but must match in code. 

 

Extra plot layouts by range. Can be provided more beer.

 

 

 

 

; Make new layout tabs based on block in model spce
; By AlanH July 2023

(defun mktabs ( / ss obj inspt atts layname cpt bl tr ss2)

(setvar 'ctab "Model")
(command "zoom" "E")
(setq ss (ssget "X" '((0 . "INSERT")(2 . "E0-Cadre")(410 . "Model"))))

(repeat (setq x (sslength ss))
  (setq obj (vlax-ename->vla-object (ssname ss (setq x (- x 1)))))
  (setq inspt (vlax-get obj 'insertionpoint))
  (setq atts (vlax-invoke obj 'Getattributes))
  (setq layname (vlax-get (nth 0 atts) 'textstring))
  (setq cpt (mapcar '+ inspt (list 212.7405 137.0 0.0)))
  (setq bl (mapcar '+ inspt (list 20 30 0.0)))
  (setq tr (mapcar '+ inspt (list 395 244 0.0)))
  (setq ss2 (ssget "WP" (list tr bl)))
  (if (= ss2 nil)
   (princ "Skip empty block")
   (progn
    (command "layout" "c" "Master" layname)
    (setvar 'ctab layname)
    (command "zoom" "E")
    (command "mspace")
    (command "zoom" "C" cpt "0.9XP")
    (command "pspace")
    (setq ent (ssname (ssget "x" (list (cons 0  "Viewport")(cons 410 (getvar 'ctab)))) 0))
    (setq obj (vlax-ename->vla-object ent))
    (vla-put-DisplayLocked obj  -1)
    (setvar 'ctab "Model")
    )
  )
)
(princ)
)
(mktabs)

 

 

 

 

 

0 Likes

YAYA.SADA
Advocate
Advocate

Thank you, but I can't run the lisp, When I load the lisp I have "Commande: _appload MKtabs.lsp correctement chargé(s)
Commande: chaîne du mode ssget incorrecte
Entrez un facteur d'échelle (nX ou nXP):
Commande:
Entrez un facteur d'échelle (nX ou nXP): " which appears in the command line and as soon as I run the lisp using the "MKTABS" command, nothing happens, unknown command.

0 Likes

Sea-Haven
Mentor
Mentor

It works for me, did you make the 3 changes the default layout is named "Master" I also did a bedit on "E0-Cadre" and moved title block to match lower left at 0,0. Set the viewport to unlocked. Did you check it against your sample dwg ? Once you appload it will just run and make the layouts no user interaction required.

 

SeaHaven_0-1689132880700.png

Modified test dwg.

0 Likes

YAYA.SADA
Advocate
Advocate

Thank u , but i it's dont work, i've this message on command line

YAYASADA_0-1689148586501.png

 

0 Likes

YAYA.SADA
Advocate
Advocate

and when i enter the MKTABS command, i said me command doesn't exist

YAYASADA_0-1689148772619.png

 

0 Likes

Sea-Haven
Mentor
Mentor

I am running in english version I have come across a different language CAD not workig and solution was to add the force english in Command so will look at that and see if it makes any difference. Did you set the Master layout Mview to unlocked ? I lock after making the layout.

0 Likes

YAYA.SADA
Advocate
Advocate

Thank you, yes i setted the Master layout Mview to unlocked, but it's probably the fact that the commands are in English.

0 Likes