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,127 Views
114 Replies
Replies (114)

YAYA.SADA
Advocate
Advocate

 

 

0 Likes

Sea-Haven
Mentor
Mentor

For Yada.Sada

 

In english (setvar 'ctab "Model") looks like (setvar 'ctab "Otyet") if I read image correct. Also (410 . "Model") 

 

; Make new layout tabs based on block in model spce
; By AlanH July 2023
; French version for Model

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

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

(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 "Otyet")
   )
  )
)
(princ)
)
(mktabs)

 

0 Likes

YAYA.SADA
Advocate
Advocate

;;; Créer des présentation basé sur un bloc de l'espace objet
;;; Par AlanH July 2023

;;; In French 

 

 

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

(setvar 'ctab "OBJET")
(command "ZOOM" "ET")
(setq ss (ssget "X" '((0 . "INSERER")(2 . "E0-Cadre")(410 . "OBJET"))))

(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 "FPOLY" (list tr bl)))
(if (= ss2 nil)
(princ "Skip empty block")
(progn
(command "PRESENTATION" "C" "Master" layname)
(setvar 'ctab layname)
(command "ZOOM" "E")
(command "ESPACEO")
(command "zoom" "C" cpt "0.9XP")
(command "ESPACEP")
(setq ent (ssname (ssget "x" (list (cons 0 "FENETRES")(cons 410 (getvar 'ctab)))) 0))
(setq obj (vlax-ename->vla-object ent))
(vla-put-DisplayLocked obj -1)
(setvar 'ctab "OBJET")
)
)
)
(princ)
)
(mktabs)

 

 

 

I've always this message, i remplaced all english command by French command

"MODEL"->"OBJET"

"ZOOM" "E"->"ZOOM" "ET" for Extents

"INSERT"->"INSERER"

"WP"->"FPOLY"

"VIEWPORTS"->"FENETRES"

"_.pspace"->"_.ESPACEP"

"_.layout"->"_.PRESENTATION"

"_.mspace"->"ESPACEO"

 

 

Commande: _appload MKtabs.lsp correctement chargé(s)
Commande: type d'argument incorrect: lselsetp nil

And when i type MKTABS, the command doesn't exist

 

What is the "X" here in the secance (setq ss (ssget "X" '((0 . "INSERER")(2 . "E0-Cadre")(410 . "OBJET"))))

 

and this (princ "Skip empty block") is it a command or a information text?

and (setq ent (ssname (ssget "x" (list (cons 0 "Viewport")(cons 410 (getvar 'ctab)))) 0))

is it "Viewport or viewports"

0 Likes

Sea-Haven
Mentor
Mentor

The code runs on load do not need Mktabs. If you want change the.

 

 

 

(defun c:mktabs 

and

(C:mktabs)

 

 

 

The "X" in a ssget implies get all, across the whole dwg, includes layouts.

 

 (princ "Skip empty block") replace with (princ) it is used to just show objects were skipped that did not match test.

 

Viewport or VIEWPORT or viewport should all work. Maybe french version is viewports, to check Properties, click on a viewport.

SeaHaven_0-1689727356841.png

 

Its getting an error due to language problem. In the version above I changed the command lines to force english translation please try as is don't change. We can add markers (princ "\n1") in the code so an see where it stops by the number got to say 5. Other wise maybe can test in VLIDE a lisp debugger for Autocad.

 

Will try to remove all Command and use VL which I think remains in english.

 

Please press F2 do a screen grab of command line so can see numbers if it does not work.

 

; Make new layout tabs based on block in model spce
; By AlanH July 2023
; French version for Model

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

(setvar 'ctab "Otyet")
(princ "\n1")
(command "zoom" "_E")
(princ "\n2")
(setq ss (ssget "X" '((0 . "INSERT")(2 . "E0-Cadre")(410 . "Otyet"))))

(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 "")
   (progn
    (command "_.layout" "c" "Master" layname)
	(princ "\n3")
    (setvar 'ctab layname)
    (command "_.zoom" "E")
    (command "_.mspace")(princ "\n4")
    (command "_.zoom" "C" cpt "0.9XP")(princ "\n5")
    (command "_.pspace")
    (setq ent (ssname (ssget "x" (list (cons 0  "Viewport")(cons 410 (getvar 'ctab)))) 0))
    (setq obj (vlax-ename->vla-object ent))
	(princ "\n6")
    (vla-put-DisplayLocked obj  -1)
    (setvar 'ctab "Otyet")
	(princ "\n7")
   )
  )
  (princ "\n8")
)
(princ)
)
(c:mktabs)

 

 

0 Likes

YAYA.SADA
Advocate
Advocate

Hello, sorry always a problem

Commande: MKTABS

1
Nécessite une distance, une valeur X ou une option.
Fonction annulée (in english Function canceled)
Spécifiez le coin d'une fenêtre, entrez un facteur d'échelle (nX ou nXP) ou
[Tout/Centre/DYnamique/ETendu/Précédent/Echelle/Fenêtre/Objet] <temps réel>:
Spécifiez le coin opposé:

 

For the command ZOOM, in english AutoCAD LT 2023 Help | ZOOM (Command) | Autodesk

For the commande ZOOM in French AutoCAD 2022 Aide | ZOOM (commande) | Autodesk

YAYASADA_1-1689753964003.png

 

 

 

0 Likes

Sea-Haven
Mentor
Mentor

You will need to get someone who codes in the French version as I can not help much more. Sorry about that.

0 Likes

YAYA.SADA
Advocate
Advocate

Thank you so much, you have already helped me a lot.

You're the best 😉

0 Likes

YAYA.SADA
Advocate
Advocate


hello, I hope you are well, someone was able to correct the problem I had with your Lisp (See below) however I have another problem, when I run the command, nothing happens after the 8th stage. Can you tell me why, please?

the lisp does not ask me to select the blocks

 

 

; Make new layout tabs based on block in model spce
; By AlanH July 2023
; French version for Model
 
(defun c:mktabs ( / ss obj inspt atts layname cpt bl tr ss2)
 
(setvar 'ctab "MODEL")
(princ "\n1")
(command "_.zoom" "_Extent")
(princ "\n2")
(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 THE BLOCK")
   (progn
    (command "_.layout" "_c" "Master" layname)
(princ "\n3")
    (setvar 'ctab layname)
    (command "_.zoom" "_Extent")
    (command "_.mspace")(princ "\n4")
    (command "_.zoom" "_C" cpt "0.9XP")(princ "\n5")
    (command "_.pspace")
    (setq ent (ssname (ssget "_X" (list (cons 0  "Viewport")(cons 410 (getvar 'ctab)))) 0))
    (setq obj (vlax-ename->vla-object ent))
(princ "\n6")
    (vla-put-DisplayLocked obj  -1)
    (setvar 'ctab "Model")
(princ "\n7")
   )
  )
  (princ "\n8")
)
(princ)
)
(c:mktabs)

 

0 Likes

YAYA.SADA
Advocate
Advocate

YAYASADA_0-1692715324875.png

 

0 Likes

CADaSchtroumpf
Advisor
Advisor

@Sea-Haven  a écrit :

You will need to get someone who codes in the French version as I can not help much more. Sorry about that.


@Sea-Haven 

Here an international version.

I also corrected the selection by WP in CP by providing the 4 points of the polygon because 2 points in WP returns an empty selection.

; Make new layout tabs based on block in model spce
; By AlanH July 2023
; French version for Model

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

(setvar 'ctab "Model")
(command "_.zoom" "_Extent")
(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 "_CP" (list tr (list (car bl) (cadr tr) 0.0) bl (list (car tr) (cadr bl) 0.0))))
  (if (= ss2 nil)
   (princ "Saute le bloc vide")
   (progn
    (command "_.layout" "_Copy" "Master" layname)
    (setvar 'ctab layname)
    (command "_.zoom" "_Extent")
    (command "_.mspace")
    (command "_.zoom" "_Ce" 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)
)
(c:mktabs)
0 Likes

YAYA.SADA
Advocate
Advocate

Thanks you so much,

you're the best of the best

0 Likes

YAYA.SADA
Advocate
Advocate

Can you explain to me ? please

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

 

0 Likes

YAYA.SADA
Advocate
Advocate

this is the center of the block E0-cadre

0 Likes

Sea-Haven
Mentor
Mentor

Thanks for having a look at it. 

0 Likes