Jump to content

Automatic layout setup


Nila

Recommended Posts

  • 3 weeks later...

I made something.

See if it can be useful to you.

 

- It will copy "Layout1" multiple times, and name them "Paper1", "Paper2", ...

So prepare the pagesetup of Layout1.  Remove the viewport (new viewports will be created), but you can add a cartouche (or whatever you need there)

 

Command ALS (for Automatic Layout Setup)

- user set the length, height and overlap (for example 800 500 50).

- user selects a polyline.

 

-> Along the polyline rectangles (polylines) are created.

-> Paper spaces are created, each with a viewport the same size as the rectangles.

-> Each viewport pans/zooms (scale is set to 1.00) to a next rectangle

 

Try it on my dwg first

 


(vl-load-com)

;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/
(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst)))
)

                   
;; based on @see http://www.lee-mac.com/totallengthandarea.html
(defun totalLengthPolyline ( s / i)
     (setq l 0.0)
     (repeat (setq i (sslength s))
         (setq e (ssname s (setq i (1- i)))
               l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
         )
     )
  l
)

;;;;;;;;;;;;;;;;;;;;;;

(defun vat (viewport_length viewport_height overlap / obj pline total_length needle mp1 mp2 ang1 rec1 rec2 rec3 rec4)
  ;; settings
  ;;(setq viewport_length 700.0)
  ;;(setq viewport_height 400.0)
  ;;(setq overlap 50.0)
 
  ;;
  (princ "\nSelect Polytine")
  (setq pline (ssget (list (cons 0 "LWPOLYLINE,POLYLINE")) ))
  (setq obj (vlax-ename->vla-object (ssname pline 0)))
 
  (princ
    (setq total_length (totalLengthPolyline pline))
  )
 
  (setq needle 0.0)
  (while (< needle total_length)  ;; (+ total_length viewport_length)
    (setq mp1 (vlax-curve-getPointAtDist obj needle))
    (setq needle (+ needle viewport_length))
    (setq mp2 (vlax-curve-getPointAtDist obj needle))
    ;; last point, take the end of the polyline
    (if (= mp2 nil)
      (setq mp2 (vlax-curve-getPointAtDist obj total_length))
    )
    
    (setq ang1 (angle mp1 mp2))
    
    (setq rec1 (polar mp2 (+ ang1 (/ pi 2)) (/ viewport_height 2)))
    (setq rec2 (polar rec1 (+ ang1 pi) viewport_length))
    (setq rec3 (polar rec2 (+ ang1 (* pi 1.5)) viewport_height))
    (setq rec4 (polar rec3 ang1 viewport_length))
    
    ;; fill in the globals
    (setq LWPolylines_data (append LWPolylines_data (list
      (list rec1 rec2 rec3 rec4)
    )))
    (setq LWPolylines (append LWPolylines (list
      (LWPoly (list rec1 rec2 rec3 rec4) 1)
    )))
    (setq pointpairs (append pointpairs (list
      (list mp1 mp2)
    )))
    
    (setq needle (- needle overlap))
  )
  (princ)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; c:copying-lay-out
;; It will name the layouts "Paper1", "Paper2", ...
(defun clo (pointpairs / i n layoutname )
  (if
    (and
      (setq layoutname "Layout1")
      (setq n (length pointpairs))             ;; number of new layouts
      (setq i (+ n 1))
      (member layoutname  (layoutlist))
    )
    (repeat n
      (command "layout" "Copy"  layoutname  (strcat "Paper" (rtos (setq i (- i 1)))) )
    );; repeat
    
  );; if
  (princ)
);; demo

(defun AlignView (p1 p2 / ang)
  ;;(command "ucs" "world" "\\")
  (and
    ;;(setq p1 (getpoint "\nFirst alignment point: "))
    ;;(setq p2 (getpoint p1 "\nSecond alignment point: "))
    (setq ang (- (angle (trans p1 1 0) (trans p2 1 0))))
    (command "_.dview" "" "_twist" (angtos ang (getvar 'aunits) 16) "")
  )
  (command "ucs" "view" "\\")
  (princ)
)

;; rotate view
(defun rv    (1point 2point / )
      (command "_ucs" "_w")
      (if (and 1point 2point)
        (progn
        (command "_zoom" "_c" 1point "")
        (if (= (getvar "angdir") 0)
          (command "_dview" ""  "_tw" (angtos (+ (* -1 (angle 1point 2point)) (getvar "angbase"))(getvar "aunits") 10) "")
          (command "_dview" ""  "_tw" (angtos (+ (angle 1point 2point) (getvar "angbase")) (getvar "aunits") 10) "")
        )
        (setvar "snapang" (angle 1point 2point))
      );progn
      (progn
        (command "_dview" "" "_tw" "0" "")
        (setvar "snapang" 0.0)
      );progn
      )
      (command "_ucs" "_w")
      (princ)
);end defun


;; globals
(setq pointpairs (list))
(setq LWPolylines (list))
(setq LWPolylines_data (list))


(defun ALS (viewport_length viewport_height overlap /  i pair pt1 pt2)

  ;; settings
  ;;(setq viewport_length 800.0)
  ;;(setq viewport_height 500.0)
  ;;(setq overlap 50.0)

  ;; (re) initiate globals
  (setq LWPolylines (list))
  (setq LWPolylines_data (list))
  (setq pointpairs (list))

  (vat viewport_length viewport_height overlap)
  (clo pointpairs)
 
  (princ LWPolylines_data)
 
  (setq i 0)
  (foreach pair pointpairs
 
    (setvar "ctab" (strcat "Paper" (itoa (+ i 1) )))
    
    ;; This example creates a paper space viewport and makes it active.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
 
    (setq centerPoint (vlax-3d-point (/ viewport_length 2.0) (/ viewport_height 2.0) 0)
          height viewport_height
          width viewport_length)
    
    ;; Create a paper space Viewport object
    (vla-put-ActiveSpace doc acPaperSpace)
    (setq newPViewport (vla-AddPViewport (vla-get-PaperSpace doc) centerPoint width height))
    (vla-ZoomAll acadObj)
    (vla-Display newPViewport :vlax-true)
    
    ;; Before making a pViewport active,
    ;; the mspace property needs to be True
    (vla-put-MSpace doc :vlax-true)
    (vla-put-ActivePViewport doc newPViewport)
 
    (rv (nth 0 pair) (nth 1 pair))  ;;  pt1 pt2
   
    ;zoom window
    (setq pt1 (nth 2 (nth i LWPolylines_data)))
    (setq pt2 (nth 0 (nth i LWPolylines_data)))
    
    (command "zoom" "_o" (nth i LWPolylines) "")
    
    (vla-put-MSpace doc :vlax-false)
    
    (vla-put-customscale newPViewport 1.0)
    
    ;;(command "_.PSPACE")
    ;;(command "ucs" "world" "\\")
    (setq i (+ i 1))
  )
)

;; Automatic layout setup
(defun c:ALS2 ( /  viewport_length viewport_height overlap )
  ;; settings
  (setq viewport_length 800.0)
  (setq viewport_height 500.0)
  (setq overlap 50.0)
 
  (ALS
    viewport_length
    viewport_height
    overlap
  )
)

;; Automatic layout setup
(defun c:ALS ( / )

  (ALS
    (getreal "\nViewport length: ")
    (getreal "\nViewport height: ")
    (getreal "\noverlap: ")
  )
)

viewports_along_track.dwg

Edited by Emmanuel Delay
  • Like 4
Link to comment
Share on other sites

  • 1 year later...

Good afternoon, Emmanuel Delay. I tried your layout lisp this afternoon and found it to be quite remarkable. The project I'm currently working on has almost 200 layouts. I seem to be having trouble getting the views to work.  The sheets create flawlessly, but no MVs. Any idea what I doing wrong? Any help would be greatly appreciated. You must be a production legend with lisp skills like that.

Thanks in advance!

PS I did erase the MV in the 1st layout

Link to comment
Share on other sites

15 hours ago, rickquin said:

The project I'm currently working on has almost 200 layouts. I seem to be having trouble getting the views to work. 

 

Doesn't really help with the layout but does the last part of the video showing the boundary of the view ports in model space.

 

;;------------------------------------------------------------------------------------------------------------;;
;; Creates Viewport outline and moves it to Model space
(defun C:VP2M (/ Tab ss n ename elist MiscOn cen c40 c41 lay PT1 PT2)
  (foreach tab (layoutlist)
    (setvar "ctab" tab)
    (setq Tab (getvar "ctab"))
    (if (setq ss (ssget "X" (list '(0 . "viewport") (cons '410 Tab))))
      (repeat (setq n (sslength ss))
        (setq ename (ssname ss (setq n (1- n))) elist (entget ename))
        (if (> (cdr (assoc '69 elist)) 1)              ; skip display viewport
          (progn
            (if (= (cdr (assoc '68 elist)) 0)          ; is viewport active?
              (progn
                (setq MiscOn 'NO)
                (vl-cmdf "._Mview" "_on" "_si" ename)  ; activate viewport
              )  ; progn
              (setq MiscOn 'YES)
            )    ; if
            (setq cen (cdr (assoc '10 elist)))
            (setq c40 (cdr (assoc '40 elist)))
            (setq c41 (cdr (assoc '41 elist)))
            (setq lay (cdr (assoc '8 elist)))
            (setq PT1 (list (- (car cen) (/ c40 2)) (- (cadr cen) (/ c41 2))))
            (setq PT2 (list (+ (car cen) (/ c40 2)) (+ (cadr cen) (/ c41 2))))
            (vl-cmdf "_.Pspace")
            (vl-cmdf "_.Rectangle" PT1 PT2)
            (vl-cmdf "_.Chprop" "_Last" "" "_LA" lay "")
            (vl-cmdf "_.Chspace" "_Last" "")
            (vl-cmdf "_.Pspace")
            (if (eq MiscOn 'NO)
              (vl-cmdf "_.Mview" "_off" "_si" ename)  ; deactivate viewport
            )
          )
        )
      )
    )
  )  ;foreach
  (setvar 'Tilemode 1)
)

 

Link to comment
Share on other sites

Emmanuel's LISP actually does that part really well,  creates the sheets, numbers them, it's pretty stinking genius, everything but cutting the Mviews. I'm pretty sure I'm not doing something right. After looking at it again, I may not be running a second part, part of the LISP, dunno? 

Anyway, thanks Mhupp

 

Link to comment
Share on other sites

Oh fabulous! I sent an email to the support staff yesterday. I am wondering if this software would work for views that are arranged in a grid rather than along a proposed alignment. 

GRID1.jpg

Link to comment
Share on other sites

11 minutes ago, rickquin said:

Oh fabulous!

 

If you're talking about - AutoViewport
1. The letter did not arrive, check the shipping address.
2. Yes, it will work on the grid. There is a setting - sorting by XY

3. You can check it yourself by running the program.

Link to comment
Share on other sites

  • 1 year later...

 

Khi tôi tạo bố cục tự động bằng bản vẽ: LONG1.LISP hoạt động tốt. Nhưng khi tôi thay đổi vị trí VIEWPORT bằng hình vẽ: Long2 để khớp với khung tên thường dùng của tôi, thì lisp không hoạt động bình thường. Xin hãy giúp tôi chỉnh ngọng để với bản vẽ: Long2 hoạt động

 

z3600394256874_7e0b1debbccc476916217c3f971a25fa (1).jpg

GridsToLayouts.lsp LONG1.dwg LONG2.dwg

Link to comment
Share on other sites

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.thanks

z3600394256874_7e0b1debbccc476916217c3f971a25fa (1).jpg

GridsToLayouts.lsp LONG1.dwg LONG2.dwg

Link to comment
Share on other sites

  • 1 year later...
On 6/18/2019 at 4:36 PM, Emmanuel Delay said:

I made something.

See if it can be useful to you.

 

- It will copy "Layout1" multiple times, and name them "Paper1", "Paper2", ...

So prepare the pagesetup of Layout1.  Remove the viewport (new viewports will be created), but you can add a cartouche (or whatever you need there)

 

Command ALS (for Automatic Layout Setup)

- user set the length, height and overlap (for example 800 500 50).

- user selects a polyline.

 

-> Along the polyline rectangles (polylines) are created.

-> Paper spaces are created, each with a viewport the same size as the rectangles.

-> Each viewport pans/zooms (scale is set to 1.00) to a next rectangle

 

Try it on my dwg first

 

(vl-load-com)

;; https://www.cadtutor.net/forum/topic/18257-entmake-functions/
(defun LWPoly (lst cls)
 (entmakex (append (list (cons 0 "LWPOLYLINE")
                         (cons 100 "AcDbEntity")
                         (cons 100 "AcDbPolyline")
                         (cons 90 (length lst))
                         (cons 70 cls))
                   (mapcar (function (lambda (p) (cons 10 p))) lst)))
)

                   
;; based on @see http://www.lee-mac.com/totallengthandarea.html
(defun totalLengthPolyline ( s / i)
     (setq l 0.0)
     (repeat (setq i (sslength s))
         (setq e (ssname s (setq i (1- i)))
               l (+ l (vlax-curve-getdistatparam e (vlax-curve-getendparam e)))
         )
     )
  l
)

;;;;;;;;;;;;;;;;;;;;;;

(defun vat (viewport_length viewport_height overlap / obj pline total_length needle mp1 mp2 ang1 rec1 rec2 rec3 rec4)
  ;; settings
  ;;(setq viewport_length 700.0)
  ;;(setq viewport_height 400.0)
  ;;(setq overlap 50.0)
 
  ;;
  (princ "\nSelect Polytine")
  (setq pline (ssget (list (cons 0 "LWPOLYLINE,POLYLINE")) ))
  (setq obj (vlax-ename->vla-object (ssname pline 0)))
 
  (princ
    (setq total_length (totalLengthPolyline pline))
  )
 
  (setq needle 0.0)
  (while (< needle total_length)  ;; (+ total_length viewport_length)
    (setq mp1 (vlax-curve-getPointAtDist obj needle))
    (setq needle (+ needle viewport_length))
    (setq mp2 (vlax-curve-getPointAtDist obj needle))
    ;; last point, take the end of the polyline
    (if (= mp2 nil)
      (setq mp2 (vlax-curve-getPointAtDist obj total_length))
    )
    
    (setq ang1 (angle mp1 mp2))
    
    (setq rec1 (polar mp2 (+ ang1 (/ pi 2)) (/ viewport_height 2)))
    (setq rec2 (polar rec1 (+ ang1 pi) viewport_length))
    (setq rec3 (polar rec2 (+ ang1 (* pi 1.5)) viewport_height))
    (setq rec4 (polar rec3 ang1 viewport_length))
    
    ;; fill in the globals
    (setq LWPolylines_data (append LWPolylines_data (list
      (list rec1 rec2 rec3 rec4)
    )))
    (setq LWPolylines (append LWPolylines (list
      (LWPoly (list rec1 rec2 rec3 rec4) 1)
    )))
    (setq pointpairs (append pointpairs (list
      (list mp1 mp2)
    )))
    
    (setq needle (- needle overlap))
  )
  (princ)
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; c:copying-lay-out
;; It will name the layouts "Paper1", "Paper2", ...
(defun clo (pointpairs / i n layoutname )
  (if
    (and
      (setq layoutname "Layout1")
      (setq n (length pointpairs))             ;; number of new layouts
      (setq i (+ n 1))
      (member layoutname  (layoutlist))
    )
    (repeat n
      (command "layout" "Copy"  layoutname  (strcat "Paper" (rtos (setq i (- i 1)))) )
    );; repeat
    
  );; if
  (princ)
);; demo

(defun AlignView (p1 p2 / ang)
  ;;(command "ucs" "world" "\\")
  (and
    ;;(setq p1 (getpoint "\nFirst alignment point: "))
    ;;(setq p2 (getpoint p1 "\nSecond alignment point: "))
    (setq ang (- (angle (trans p1 1 0) (trans p2 1 0))))
    (command "_.dview" "" "_twist" (angtos ang (getvar 'aunits) 16) "")
  )
  (command "ucs" "view" "\\")
  (princ)
)

;; rotate view
(defun rv    (1point 2point / )
      (command "_ucs" "_w")
      (if (and 1point 2point)
        (progn
        (command "_zoom" "_c" 1point "")
        (if (= (getvar "angdir") 0)
          (command "_dview" ""  "_tw" (angtos (+ (* -1 (angle 1point 2point)) (getvar "angbase"))(getvar "aunits") 10) "")
          (command "_dview" ""  "_tw" (angtos (+ (angle 1point 2point) (getvar "angbase")) (getvar "aunits") 10) "")
        )
        (setvar "snapang" (angle 1point 2point))
      );progn
      (progn
        (command "_dview" "" "_tw" "0" "")
        (setvar "snapang" 0.0)
      );progn
      )
      (command "_ucs" "_w")
      (princ)
);end defun


;; globals
(setq pointpairs (list))
(setq LWPolylines (list))
(setq LWPolylines_data (list))


(defun ALS (viewport_length viewport_height overlap /  i pair pt1 pt2)

  ;; settings
  ;;(setq viewport_length 800.0)
  ;;(setq viewport_height 500.0)
  ;;(setq overlap 50.0)

  ;; (re) initiate globals
  (setq LWPolylines (list))
  (setq LWPolylines_data (list))
  (setq pointpairs (list))

  (vat viewport_length viewport_height overlap)
  (clo pointpairs)
 
  (princ LWPolylines_data)
 
  (setq i 0)
  (foreach pair pointpairs
 
    (setvar "ctab" (strcat "Paper" (itoa (+ i 1) )))
    
    ;; This example creates a paper space viewport and makes it active.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
 
    (setq centerPoint (vlax-3d-point (/ viewport_length 2.0) (/ viewport_height 2.0) 0)
          height viewport_height
          width viewport_length)
    
    ;; Create a paper space Viewport object
    (vla-put-ActiveSpace doc acPaperSpace)
    (setq newPViewport (vla-AddPViewport (vla-get-PaperSpace doc) centerPoint width height))
    (vla-ZoomAll acadObj)
    (vla-Display newPViewport :vlax-true)
    
    ;; Before making a pViewport active,
    ;; the mspace property needs to be True
    (vla-put-MSpace doc :vlax-true)
    (vla-put-ActivePViewport doc newPViewport)
 
    (rv (nth 0 pair) (nth 1 pair))  ;;  pt1 pt2
   
    ;zoom window
    (setq pt1 (nth 2 (nth i LWPolylines_data)))
    (setq pt2 (nth 0 (nth i LWPolylines_data)))
    
    (command "zoom" "_o" (nth i LWPolylines) "")
    
    (vla-put-MSpace doc :vlax-false)
    
    (vla-put-customscale newPViewport 1.0)
    
    ;;(command "_.PSPACE")
    ;;(command "ucs" "world" "\\")
    (setq i (+ i 1))
  )
)

;; Automatic layout setup
(defun c:ALS2 ( /  viewport_length viewport_height overlap )
  ;; settings
  (setq viewport_length 800.0)
  (setq viewport_height 500.0)
  (setq overlap 50.0)
 
  (ALS
    viewport_length
    viewport_height
    overlap
  )
)

;; Automatic layout setup
(defun c:ALS ( / )

  (ALS
    (getreal "\nViewport length: ")
    (getreal "\nViewport height: ")
    (getreal "\noverlap: ")
  )
)

viewports_along_track.dwg 61.78 kB · 99 downloads

 

Link to comment
Share on other sites

i tried and i am facing this error

 

 

Command: ALS
Viewport length: 1050
Viewport height: 500
overlap: 10
Select Polytine
Select objects: 1 found

Select objects:
43394.1; error: bad argument type: 2D/3D point: nil

Link to comment
Share on other sites

Posted (edited)

I have 2 versions walk along a pline and do grids, you make rectangs that match a layout title block, and the mview is reflected in a chosen scale. Then layouts are made a second step, the reason for 2 steps is make the rectangs and adjust them if necessary, can rotate, move and delete. 

 

A small cost beer money, I need to edit the code to match your title blocks.

 

layout1.png.9d03ab6cd7fbd5b4a128c15fbe0c31bf.png

image.png.30c99e94e8728ad799a6777955bfd2d8.png

 

 

 

 

Edited by BIGAL
Link to comment
Share on other sites

I was not able to understand the what you have mentioned 

Link to comment
Share on other sites

Posted (edited)

I have 2 version walk along a line or pline repeat as required, then make layouts to suit, the rectangs made are based on a title block and a plot scale. 

 

2nd version makes a rectang and you copy it, rotate or move to suit, again it makes the layouts matching a title block and scale.

 

A very small cost includes customising to suit your title blocks.

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...