Author Topic: Seperate layout as a drawing?  (Read 7655 times)

0 Members and 1 Guest are viewing this topic.

huan_khu

  • Guest
Seperate layout as a drawing?
« on: May 05, 2014, 11:18:11 PM »
Please help me. I have a problem.

I have a CAD file with many layouts. Could you show me any LISP to do these work:

 1. Separate each layout as  a drawing.
 2. In above drawing, we keep the contents that show in layout only. Other objects outside layout will be deleted.

Thank you very much.

PS: This is the link to my file https://dl.dropboxusercontent.com/u/15038223/FVR-TEC-MST-3130-024-A-EN%20%26%20VN-LLT-S1%20%28Long%20Line%201%29.dwg


ROBBO

  • Bull Frog
  • Posts: 217
Re: Seperate layout as a drawing?
« Reply #1 on: May 06, 2014, 02:03:34 AM »
This lisp routine found in the following link will export layouts to separate DWGs:

http://www.jtbworld.com/lisp/layoutstodwgs.htm
The only thing to do with good advice is to pass it on.
It is never of any use to oneself.

Oscar Wilde
(1854-1900, Irish playwright, poet and writer)

huan_khu

  • Guest
Re: Seperate layout as a drawing?
« Reply #2 on: May 06, 2014, 02:47:59 AM »
I know this LISP but it does not delete the contents outside viewport. Thank you

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Seperate layout as a drawing?
« Reply #3 on: May 06, 2014, 05:44:27 AM »
So your lisp would then need to erase everything, but remove anything shown inside the viewports on the Layout.

If all you want is to convert each TAB to the absolute minimum linework in a single DWG ... then the simplest solution would be to use the ExportLayout command. Note though that it places everything in the new DWG's model space (i.e. even the title block) and it scales everything to suit (i.e. like you had to draw prior to acad getting a paper space).
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Seperate layout as a drawing?
« Reply #5 on: May 06, 2014, 05:58:55 PM »
My suggestion is to utilize the built in export layout command.

NOTE: This will export each layout to paper space and saves the file in the same folder as the drawing.

Code: [Select]
;Written by Chris Wade - cmwade77 at http://theswamp.org
;If file dialog boxes appear, unremark the (setvar "filedia" x) lines
(defun c:ExportAllTabs (/ Mode)
; (setvar "filedia" 0)
(foreach pair (dictsearch (namedobjdict) "ACAD_LAYOUT")
(if (= 3 (car pair))
(progn
(if (/= (strcase (cdr pair)) "MODEL")
(progn
(vl-cmdf "._layout" "set" (cdr pair))
(vl-cmdf "._explortlayout" "")
)
)
)
)
)
; (setvar "filedia" 1)
)
« Last Edit: May 08, 2014, 05:51:39 PM by cmwade77 »

huan_khu

  • Guest
Re: Seperate layout as a drawing?
« Reply #6 on: May 06, 2014, 11:03:10 PM »
Did you try this?

http://www.theswamp.org/index.php?topic=19721.msg240368#msg240368

Yes I try but it looks like the Lisp here http://www.jtbworld.com/lisp/layoutstodwgs.htm  . Thank you

My suggestion is to utilize the built in export layout command.

NOTE: This will export each layout to paper space and saves the file in the same folder as the drawing.

Code: [Select]
;Written by Chris Wade - cmwade77 at http://theswamp.org
;If file dialog boxes appear, unremark the (setvar "filedia" x) lines
(defun c:ExportAllTabs (/ Mode)
; (setvar "filedia" 0)
(foreach pair (dictsearch (namedobjdict) ""ACAD_LAYOUT"")
(if (= 3 (car pair))
(progn
(if (/= (strcase (cdr pair)) ""MODEL"")
(progn
(vl-cmdf "._layout" "set" (cdr pair))
(vl-cmdf "._explortlayout" "")
)
)
)
)
)
; (setvar "filedia" 1)
)

When running it has error "; error: too many arguments" . Thank you

ChrisCarlson

  • Guest
Re: Seperate layout as a drawing?
« Reply #7 on: May 07, 2014, 07:53:35 AM »
So find the error....

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: Seperate layout as a drawing?
« Reply #8 on: May 08, 2014, 05:52:13 PM »
I fixed the error and edited the code in my post, please try again.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Seperate layout as a drawing?
« Reply #9 on: May 08, 2014, 07:29:26 PM »
So find the error....
Really ? At least try to help a little bit.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Seperate layout as a drawing?
« Reply #10 on: May 11, 2014, 01:09:55 PM »
I have made list file which deletes all objects in MODEL space which are not present in any of the viewports. Please see if it works for you.

Also I have used various custom functions made by other people and I thank them for the same. I have mentioned the source of the same.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:DelObjectsNotOnAnyViewport ()
  2.   (setq ssview (ssadd))
  3.   (setvar 'ctab "MODEL")
  4.   (vlax-for lay                         ; for each layout
  5.     (setq id1 nil)                      ; ignore the first vp
  6.     (if (eq :vlax-false (vla-get-modeltype lay))
  7.       (progn (vlax-for obj (vla-get-block lay) ; for each obj in layout
  8.                (if (and (= (vla-get-objectname obj) "AcDbViewport")
  9.                         (or id1 (not (setq id1 t))) ; ignore first viewport because that is the viewport tab itself
  10.                    )
  11.                  (progn (vla-GetBoundingBox obj 'LPVP 'UPVP)
  12.                         (setq LPVP (vlax-safearray->list LPVP))
  13.                         (setq UPVP (vlax-safearray->list UPVP))
  14.                         (setq LPMODEL (PCS2WCS LPVP (vlax-vla-object->ename obj)))
  15.                         (setq UPMODEL (PCS2WCS UPVP (vlax-vla-object->ename obj)))
  16.                         (setq minx (car LPMODEL))
  17.                         (setq maxx (car UPMODEL))
  18.                         (setq miny (cadr LPMODEL))
  19.                         (setq maxy (cadr UPMODEL))
  20.                         (setq pt1 (list minx miny))
  21.                         (setq pt2 (list maxx miny))
  22.                         (setq pt3 (list maxx maxy))
  23.                         (setq pt4 (list minx maxy))
  24.                         (vla-zoomwindow app (vlax-3d-point pt1) (vlax-3d-point pt3))
  25.                         (if (setq ss (ssget "_CP" (list pt1 pt2 pt3 pt4) (list (cons 410 "MODEL"))))
  26.                           (setq ssview (kdub:ssunion ssview ss))
  27.                         )
  28.                  )
  29.                )
  30.              )
  31.       )
  32.     )
  33.   )
  34.   (setq ssall (ssget "_X" (list (cons 410 "MODEL"))))
  35.   (setq sstodel (kdub:sssubtract ssall ssview))
  36.   (repeat (setq n (sslength sstodel)) (setq ent (ssname sstodel (setq n (1- n)))) (entdel ent))
  37. )
  38.  
  39.  
  40. ;;; Union of two selection sets
  41. (defun kdub:ssunion (ss1 ss2 / ss index)
  42. ;;; Source : http://www.theswamp.org/index.php?topic=46652.0
  43.   (setq ss (ssadd))
  44.   (cond ((and ss1 ss2)
  45.          (setq index -1)
  46.          (repeat (sslength ss1) (ssadd (ssname ss1 (setq index (1+ index))) ss))
  47.          (setq index -1)
  48.          (repeat (sslength ss2) (ssadd (ssname ss2 (setq index (1+ index))) ss))
  49.         )
  50.         (ss1 (setq ss ss1))
  51.         (ss2 (setq ss ss2))
  52.         (t (setq ss nil))
  53.   )
  54.   ss
  55. )
  56.  
  57. ;; Subtracts one selection set from another and returns their difference
  58. ;; NOT optimal because it changes the previous/last selection set.
  59. (defun kdub:sssubtract (ss1 ss2 / ss)
  60. ;;; Source : http://www.theswamp.org/index.php?topic=46652.0
  61.   (cond ((and ss1 ss2) (vl-cmdf "._Select" ss1 "_Remove" ss2 "") (setq ss (ssget "_P")))
  62.         (ss1 (setq ss ss1))
  63.         (t (setq ss nil))
  64.   )
  65.   ss
  66. )
  67.  
  68. (defun PCS2WCS (pnt ent / ang enx mat nor scl)
  69. ;;; Source : http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Auto-Update-of-XY-coord-in-Model-Space-onto-Paper-Space-Layout/td-p/4591789/page/2
  70.   (setq pnt (trans pnt 0 0)
  71.         enx (entget ent)
  72.         ang (- (cdr (assoc 51 enx)))
  73.         nor (cdr (assoc 16 enx))
  74.         scl (/ (cdr (assoc 45 enx)) (cdr (assoc 41 enx)))
  75.         mat (mxm (mapcar (function (lambda (v) (trans v 0 nor t))) '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0)))
  76.                  (list (list (cos ang) (- (sin ang)) 0.0) (list (sin ang) (cos ang) 0.0) '(0.0 0.0 1.0))
  77.             )
  78.   )
  79.   (mapcar '+
  80.           (mxv mat (mapcar '+ (vxs pnt scl) (vxs (cdr (assoc 10 enx)) (- scl)) (cdr (assoc 12 enx))))
  81.           (cdr (assoc 17 enx))
  82.   )
  83. )
  84.  
  85. ;; Matrix Transpose  -  Doug Wilson
  86. ;; Args: m - nxn matrix
  87.  
  88. (defun trp (m) (apply 'mapcar (cons 'list m)))
  89.  
  90. ;; Matrix x Matrix  -  Vladimir Nesterovsky
  91. ;; Args: m,n - nxn matrices
  92.  
  93. (defun mxm (m n) ((lambda (a) (mapcar '(lambda (r) (mxv a r)) m)) (trp n)))
  94.  
  95. ;; Matrix x Vector  -  Vladimir Nesterovsky
  96. ;; Args: m - nxn matrix, v - vector in R^n
  97.  
  98. (defun mxv (m v) (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))
  99.  
  100. ;; Vector x Scalar  -  Lee Mac
  101. ;; Args: v - vector in R^n, s - real scalar
  102.  
  103. (defun vxs (v s) (mapcar '(lambda (n) (* n s)) v))
  104.  
  105.  

huan_khu

  • Guest
Re: Seperate layout as a drawing?
« Reply #11 on: May 13, 2014, 03:46:48 AM »
I have made list file which deletes all objects in MODEL space which are not present in any of the viewports. Please see if it works for you.

Also I have used various custom functions made by other people and I thank them for the same. I have mentioned the source of the same.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:DelObjectsNotOnAnyViewport ()
  2.   (setq ssview (ssadd))
  3.   (setvar 'ctab "MODEL")
  4.   (vlax-for lay                         ; for each layout
  5.     (setq id1 nil)                      ; ignore the first vp
  6.     (if (eq :vlax-false (vla-get-modeltype lay))
  7.       (progn (vlax-for obj (vla-get-block lay) ; for each obj in layout
  8.                (if (and (= (vla-get-objectname obj) "AcDbViewport")
  9.                         (or id1 (not (setq id1 t))) ; ignore first viewport because that is the viewport tab itself
  10.                    )
  11.                  (progn (vla-GetBoundingBox obj 'LPVP 'UPVP)
  12.                         (setq LPVP (vlax-safearray->list LPVP))
  13.                         (setq UPVP (vlax-safearray->list UPVP))
  14.                         (setq LPMODEL (PCS2WCS LPVP (vlax-vla-object->ename obj)))
  15.                         (setq UPMODEL (PCS2WCS UPVP (vlax-vla-object->ename obj)))
  16.                         (setq minx (car LPMODEL))
  17.                         (setq maxx (car UPMODEL))
  18.                         (setq miny (cadr LPMODEL))
  19.                         (setq maxy (cadr UPMODEL))
  20.                         (setq pt1 (list minx miny))
  21.                         (setq pt2 (list maxx miny))
  22.                         (setq pt3 (list maxx maxy))
  23.                         (setq pt4 (list minx maxy))
  24.                         (vla-zoomwindow app (vlax-3d-point pt1) (vlax-3d-point pt3))
  25.                         (if (setq ss (ssget "_CP" (list pt1 pt2 pt3 pt4) (list (cons 410 "MODEL"))))
  26.                           (setq ssview (kdub:ssunion ssview ss))
  27.                         )
  28.                  )
  29.                )
  30.              )
  31.       )
  32.     )
  33.   )
  34.   (setq ssall (ssget "_X" (list (cons 410 "MODEL"))))
  35.   (setq sstodel (kdub:sssubtract ssall ssview))
  36.   (repeat (setq n (sslength sstodel)) (setq ent (ssname sstodel (setq n (1- n)))) (entdel ent))
  37. )
  38.  
  39.  
  40. ;;; Union of two selection sets
  41. (defun kdub:ssunion (ss1 ss2 / ss index)
  42. ;;; Source : http://www.theswamp.org/index.php?topic=46652.0
  43.   (setq ss (ssadd))
  44.   (cond ((and ss1 ss2)
  45.          (setq index -1)
  46.          (repeat (sslength ss1) (ssadd (ssname ss1 (setq index (1+ index))) ss))
  47.          (setq index -1)
  48.          (repeat (sslength ss2) (ssadd (ssname ss2 (setq index (1+ index))) ss))
  49.         )
  50.         (ss1 (setq ss ss1))
  51.         (ss2 (setq ss ss2))
  52.         (t (setq ss nil))
  53.   )
  54.   ss
  55. )
  56.  
  57. ;; Subtracts one selection set from another and returns their difference
  58. ;; NOT optimal because it changes the previous/last selection set.
  59. (defun kdub:sssubtract (ss1 ss2 / ss)
  60. ;;; Source : http://www.theswamp.org/index.php?topic=46652.0
  61.   (cond ((and ss1 ss2) (vl-cmdf "._Select" ss1 "_Remove" ss2 "") (setq ss (ssget "_P")))
  62.         (ss1 (setq ss ss1))
  63.         (t (setq ss nil))
  64.   )
  65.   ss
  66. )
  67.  
  68. (defun PCS2WCS (pnt ent / ang enx mat nor scl)
  69. ;;; Source : http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/Auto-Update-of-XY-coord-in-Model-Space-onto-Paper-Space-Layout/td-p/4591789/page/2
  70.   (setq pnt (trans pnt 0 0)
  71.         enx (entget ent)
  72.         ang (- (cdr (assoc 51 enx)))
  73.         nor (cdr (assoc 16 enx))
  74.         scl (/ (cdr (assoc 45 enx)) (cdr (assoc 41 enx)))
  75.         mat (mxm (mapcar (function (lambda (v) (trans v 0 nor t))) '((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0)))
  76.                  (list (list (cos ang) (- (sin ang)) 0.0) (list (sin ang) (cos ang) 0.0) '(0.0 0.0 1.0))
  77.             )
  78.   )
  79.   (mapcar '+
  80.           (mxv mat (mapcar '+ (vxs pnt scl) (vxs (cdr (assoc 10 enx)) (- scl)) (cdr (assoc 12 enx))))
  81.           (cdr (assoc 17 enx))
  82.   )
  83. )
  84.  
  85. ;; Matrix Transpose  -  Doug Wilson
  86. ;; Args: m - nxn matrix
  87.  
  88. (defun trp (m) (apply 'mapcar (cons 'list m)))
  89.  
  90. ;; Matrix x Matrix  -  Vladimir Nesterovsky
  91. ;; Args: m,n - nxn matrices
  92.  
  93. (defun mxm (m n) ((lambda (a) (mapcar '(lambda (r) (mxv a r)) m)) (trp n)))
  94.  
  95. ;; Matrix x Vector  -  Vladimir Nesterovsky
  96. ;; Args: m - nxn matrix, v - vector in R^n
  97.  
  98. (defun mxv (m v) (mapcar '(lambda (r) (apply '+ (mapcar '* r v))) m))
  99.  
  100. ;; Vector x Scalar  -  Lee Mac
  101. ;; Args: v - vector in R^n, s - real scalar
  102.  
  103. (defun vxs (v s) (mapcar '(lambda (n) (* n s)) v))
  104.  
  105.  

It works like a charm. Could you add more feature like separate layouts as the drawing?? Thank you. Anyway, this Lisp help me save time too much :)

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Seperate layout as a drawing?
« Reply #12 on: May 13, 2014, 08:09:57 AM »
It works like a charm. Could you add more feature like separate layouts as the drawing?? Thank you. Anyway, this Lisp help me save time too much :)

I am happy that I could help you.
For separate layouts as drawings, you can use the LISP given by cmwade.

huan_khu

  • Guest
Re: Seperate layout as a drawing?
« Reply #13 on: May 13, 2014, 10:12:21 PM »
It works like a charm. Could you add more feature like separate layouts as the drawing?? Thank you. Anyway, this Lisp help me save time too much :)

I am happy that I could help you.
For separate layouts as drawings, you can use the LISP given by cmwade.


I know that LISP but if I use that LISP first, I will open one by one drawing and use your LISP again. I meant that if I can separate layout and delete objects not on any viewport at the same time? Thank you very much

Edit: I found that if I only have object in viewport, running LISP again, and it will delete all objects viewpoint.  Say another way, if I run the LISP 2 times, it will delete all objects on model space. Could you revise this? Thank you @mailmaverick
« Last Edit: May 14, 2014, 10:57:16 PM by huan_khu »

mailmaverick

  • Bull Frog
  • Posts: 493
Re: Seperate layout as a drawing?
« Reply #14 on: May 15, 2014, 07:15:43 AM »
I know that LISP but if I use that LISP first, I will open one by one drawing and use your LISP again. I meant that if I can separate layout and delete objects not on any viewport at the same time? Thank you very much

You need to first run my LISP to delete all objects which are not in any viewport. Then you should seperate each layout as drawing.

Edit: I found that if I only have object in viewport, running LISP again, and it will delete all objects viewpoint.  Say another way, if I run the LISP 2 times, it will delete all objects on model space. Could you revise this? Thank you @mailmaverick

If I run this LISP 2 times, it will not delete all objects in Model Space but delete all those objects which are not included in any viewport. If you have already exported your viewports as seperate layouts and no viewports exist, then probably, all objects in Model Space would be deleted.

huan_khu

  • Guest
Re: Seperate layout as a drawing?
« Reply #15 on: May 16, 2014, 03:37:59 AM »
You need to first run my LISP to delete all objects which are not in any viewport. Then you should seperate each layout as drawing.

Say I have 2 layouts with 2 viewports on it.

     1. Run your LISP, it delete objects not on any view port
     2. Run separate layout LISP, it creates 2 drawings with one view port on it. So Drawing 1 still remains objects on viewport 2 and drawing 1 remains objects on viewpor t1. These objects are not on any wiewport and I need to delete. 

Quote

If I run this LISP 2 times, it will not delete all objects in Model Space but delete all those objects which are not included in any viewport. If you have already exported your viewports as seperate layouts and no viewports exist, then probably, all objects in Model Space would be deleted.

I have checked again and the LISP also delete all objects in Model Space  ( I don't exported my viewports as seperate layouts). I tested on Autocad 2013 and Autocad 2015. Maybe because of my CAD version.

Thank you very much.
« Last Edit: May 16, 2014, 03:44:51 AM by huan_khu »

WHOSAGOOFBALL

  • Guest
Re: Seperate layout as a drawing?
« Reply #16 on: October 16, 2014, 02:51:25 PM »
sorry for hopping on to this thread but i've run this lsp from jtbworld in the past and it worked perfectly. since we've gone to 2015 it no longer works. this is what i get:

Command: LAYOUTSTODWGS
Enter filename prefix:
Regenerating model.
Regenerating layout.
Regenerating model.

Block "_Y" not found.

Invalid option keyword.

Error:  Function cancelled
Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.Include AutoCAD Map information in the export? [Yes/No] <Y>:


any thoughts? thanks.

RC

  • Guest
Re: Seperate layout as a drawing?
« Reply #17 on: October 16, 2014, 03:56:57 PM »
expLortlayouts??

Code: [Select]
(vl-cmdf "._explortlayout" "")