creation of layouts based on data in model space

creation of layouts based on data in model space

Anonymous
Not applicable
2,654 Views
12 Replies
Message 1 of 13

creation of layouts based on data in model space

Anonymous
Not applicable

hello,

got a bit of a question which may be an absolute pipe dream but here goes....

if i have a drawing with one layout, does anybody know or heard of a way to do the following using a lisp or script?

If i create lets say 4 rectangles which represent 1:500 viewports at A1 in my model, is there a way to duplicate the original layout and center each new viewport within these new layouts based on the rectangles within the model space?

Layout 1 = viewport matches rectangle 1
Layout 2 = viewport matches rectangle 2
Layout 3 = viewport matches rectangle 3
Layout 4 = viewport matches rectangle 4

i know how to set the view ports based on a centroid using a lisp, but not sure if new layouts can be copied/created based on some specific objects within the model space.

0 Likes
Accepted solutions (1)
2,655 Views
12 Replies
Replies (12)
Message 2 of 13

Anonymous
Not applicable

bump

0 Likes
Message 3 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

if i have a drawing with one layout, does anybody know or heard of a way to do the following using a lisp or script?

If i create lets say 4 rectangles which represent 1:500 viewports at A1 in my model, is there a way to duplicate the original layout and center each new viewport within these new layouts based on the rectangles within the model space?

Layout 1 = viewport matches rectangle 1
Layout 2 = viewport matches rectangle 2
Layout 3 = viewport matches rectangle 3
Layout 4 = viewport matches rectangle 4


Hi camardi,

 

quick and dirty,

test the code with the demo.dwg, not testing for UCS, rotated recangles, etc..

Just a starting point...

 

(defun c:demo (/ a b i lyt nm mx pt ss)
  (setq i 1)
  (while (setq ss (ssget "_+.:E:S" '((0 . "lwpolyline") (-4 . "&=") (70 . 1))))
    (vla-getboundingbox (vlax-ename->vla-object (ssname ss 0)) 'mn 'mx)
    (setq pt (mapcar '(lambda (a b) (/ (+ a b) 2)) (vlax-safearray->list mn) (vlax-safearray->list mx)))
    (setq lyt (strcat "Layout" (itoa (setq i (1+ i)))))
    (command "-layout" "_C" "Layout1" lyt)
    (setvar 'CTAB lyt)
    (command "_.mspace")
    (command "_zoom" "_C" pt "")
    (command "_.pspace")
    (setvar 'CTAB "Model")
  )
  (princ)
)

 

Hope this helps,
Henrique

EESignature

Message 4 of 13

Anonymous
Not applicable

Thanks mate, it is a great start.

 

all i need to try and work into that now is a bit of "IF" and try and remove the selection process and replace it with "IF" there is a layer x create layout, "IF" layer y create another layout, if there isnt layer z end process. 

 

Thanks again, i'll have to brush up on my autolisp skills again 🙂

0 Likes
Message 5 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

Thanks mate, it is a great start.

 

all i need to try and work into that now is a bit of "IF" and try and remove the selection process and replace it with "IF" there is a layer x create layout, "IF" layer y create another layout, if there isnt layer z end process. 

 

Thanks again, i'll have to brush up on my autolisp skills again 🙂


You're welcome, camardi.
Glad I could help.

 

For the 'if' I would suggest just start filtering the layer names

 

(vl-load-com)
(defun c:demo (/ a b i layt layt_lst mn mx obj pt ss)
  (setq layt_lst (layoutlist))
  (if (setq ss (ssget "_X"
                      (list '(0 . "lwpolyline") '(-4 . "&=") '(70 . 1) '(8 . "x,y,z") (cons 410 (getvar 'CTAB)))
               )
      )
    (repeat (setq i (sslength ss))
      (setq obj  (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            layt (vla-get-layer obj)
      )
      (vla-getboundingbox obj 'mn 'mx)
      (setq pt (mapcar '(lambda (a b) (/ (+ a b) 2)) (vlax-safearray->list mn) (vlax-safearray->list mx)))
      (if (not (vl-position layt layt_lst))
        (progn
          (command "-layout" "_C" "Layout1" layt)
          (setvar 'CTAB layt)
          (command "_.mspace")
          (command "_zoom" "_C" pt "")
          (command "_.pspace")
          (setvar 'CTAB "Model")
          (setq layt_lst (cons layt layt_lst))
        )
      )
    )
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 6 of 13

Anonymous
Not applicable

hey mate, what is the best way to do the filter using the autolisp language?

 

i havent really had too much of a play with some of this and normally try to just cheat and use a script most times.

0 Likes
Message 7 of 13

hmsilva
Mentor
Mentor

@Anonymous wrote:

...

 what is the best way to do the filter using the autolisp language?

...


Hi camardi,

 

you'll have to be more specific relative to what you need to filter...

 

Henrique

 

EESignature

0 Likes
Message 8 of 13

Anonymous
Not applicable

basically i will draw a rectangle on an individual layer for layout tab required.

 

i will also have to use something to say if there isnt a layer, stop the cycle and continue the lisp. thats why i was thinking the "IF" function before...

 

example

 

ie

Project 1

layer            layout

if

window 1 = layout 1

if

window 2 = layout 2

if

window 3 = layout 3

if

window 4 = layout 4

**continue

 

Project 2

layer            layout

window 1 = layout 1

if

window 2 = layout 2

if

window 3 = layout 3

if

window 4 = layout 4

if

window 5 = layout 5

if

window 6 = layout 6

**continue

0 Likes
Message 9 of 13

hmsilva
Mentor
Mentor
Accepted solution

Hi camardi,

to easier reading I did add some comments to the following code.
If you do not understand something, just ask...

 

(vl-load-com)
(defun c:demo (/ a b i lay layt layt_lst mn mx num obj pt ss)
  ; creates a list with the names of existing layouts
  (setq layt_lst (layoutlist))
  ; creates a selection set with closed lwpolylines, in current tab,
  ; and filter layers names with 'window' a 'space' and a numeric character.
  ; test if a valid selection set exists, and if true
  (if (setq ss (ssget "_X"
                      (list '(0 . "lwpolyline") '(-4 . "&=") '(70 . 1) '(8 . "window #*") (cons 410 (getvar 'CTAB)))
               )
      )
  ; repeat the selecton set length
    (repeat (setq i (sslength ss))
      ; set as a vla object
      (setq obj  (vlax-ename->vla-object (ssname ss (setq i (1- i))))
            ; get the name property
            lay  (vla-get-layer obj)
            ; get the numerical part from the layer name
            num  (substr lay (+ (vl-string-position (ascii " ") lay) 2))
            ; set the new layout name, 'layout' 'space' and numerical part
            layt (strcat "layout " num)
      )
      ; test if layout name don't exists in layout list,
      ; and if true
      (if (not (vl-position layt layt_lst))
        (progn
          ; get the lwpolyline bounding box
          (vla-getboundingbox obj 'mn 'mx)
          ; calculate the center point from bbox
          (setq pt (mapcar '(lambda (a b) (/ (+ a b) 2)) (vlax-safearray->list mn) (vlax-safearray->list mx)))
          ; copy 'Layout1' and set the new layout with the previous name stored in layt variable
          (command "-layout" "_C" "Layout1" layt)
          ; set the new layout, as current
          (setvar 'CTAB layt)
          ; activate floating model space
          (command "_.mspace")
          ; zoom to the lwpolyline center point
          (command "_zoom" "_C" pt "")
          ; return to paper space
          (command "_.pspace")
          ; return to model space
          (setvar 'CTAB "Model")
          ; store the new layout name in layout list
          (setq layt_lst (cons layt layt_lst))
        )
      )
    )
  )
  (princ)
)

 

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 10 of 13

Anonymous
Not applicable

Thanks a lot, with a little bit of tweaking (just changing layer names etc) with it, It works absolutely perfectly for what i want. 

0 Likes
Message 11 of 13

hmsilva
Mentor
Mentor

You're welcome, camardi!
Glad I could help

Henrique

EESignature

0 Likes
Message 12 of 13

Anonymous
Not applicable

hey its me again 🙂

 

still loving the lisp, got a fe further questions

 

- do you think the polyline/layer could be part of a xref (nested object)? i tried to modify it along the lines of "*window *" by putting a wildcard infront, but failed, but most likely because it couldnt find a polyline, instead a block. No biggy if it cant, i wrote a script to bring in a xref, bind it and explode it to every drawing which works great as well.

 

- could i set the viewport scale based on the dimensions of the polyline, which i think would also raise the question of the rotation based on the polyline...i was think of adding a line before

 

(command "_zoom" "1000/500xp")


(command "_zoom" "_C" pt "")

 

which would set the scale first before centering it. which i suppose i could look into a mv rotation as well based on a object.

 

- automatic sorting of the new layouts would be awesome as well 🙂

 

I'm away from my CAD computer all weekend, so will be having a crack at this before work on monday.

 

i thoughly recommend this lisp to anyone by the way. .

 

0 Likes
Message 13 of 13

hmsilva
Mentor
Mentor

Hi camardi,

 

I think it would be possible to use the polylines in the xref, but currently I have a few deadlines to meet, so I don't have much free time.

As soon as I have some spare time, I'll see what I can do...

 

Henrique

EESignature

0 Likes