Jump to content

Lisp to create tabs from Selection Window


nlao

Recommended Posts

Hi!

 

I am attempting to speed up plotting in my practice and have introduced the use of tabs and publishing. Yup they didn't use them. Instead they placed every single plot sheet on one tab causing memory outages and crashing Some drawings have over 30 on one tab. Plotting is done by selection window.

 

I want to change these files to be tabbed so I can use publish on them, and "plot and forget".

 

Currently my method is to duplicate this multi-plot layout and delete all the pages not required to create the individual sheets per tab. Long process, especially if it crashes.

 

My question is, is there a lisp routine where i could select a layout (selection window) and the layout inside that selection is sent to a new tab and then deleted from the multi-page tab. I can then work through this multi-page tab quite quickly be selecting the layout, the lisp creates the tab, placing the info on it and off we go with the next one. No switching back and forth, copying and pasting etc.

 

I am fairly new to lisp, some of it makes no sense to me but I getting there, so please bear with my stupid questions.

 

here is my code so far, swiped from elsewhere in the forum.

 

 

;; lay = New Layout Name  (Will be Created if non-existent)  (defun CopytoLayout (lay / ss NewLay ObjLst)   (vl-load-com)   ; Lee Mac  ~  27.01.10    (setq *acad* (cond (*acad*) ((vlax-get-acad-object)))         *adoc* (cond (*adoc*) ((vla-get-ActiveDocument *acad*))))    (cond (  (not (snvalid lay)))          (  (ssget)             (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *adoc*))              (setq ObjLst (cons Obj ObjLst)))                     (vla-delete ss)             (if (vl-catch-all-error-p                  (setq NewLay (vl-catch-all-apply                                 (function vla-item)                                   (list (vla-get-Layouts *adoc*) lay))))                            (setq NewLay (vla-Add (vla-get-Layouts *adoc*) lay)))             (vla-CopyObjects *adoc*                            (vlax-make-variant                (vlax-safearray-fill                  (vlax-make-safearray vlax-vbObject                    (cons 0 (1- (length ObjLst))))                                    (reverse ObjLst)))                            (vla-get-Block NewLay)))))

Link to comment
Share on other sites

Or, here's a shortened version of the code I linked you to - this one using a selection:

 

(defun c:LayoutCutter ( / _UniqueKey acdoc aclay aclyo acpvp j nwlay objs sel )
 ;; © Lee Mac 2011

 (defun _UniqueKey ( collection seed / i key ) (setq i 0)
   (while
     (not
       (vl-catch-all-error-p
         (vl-catch-all-apply 'vla-item
           (list collection (setq key (strcat seed (itoa (setq i (1+ i))))))
         )
       )
     )
   )
   key
 )

 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
       aclyo (vla-get-layouts acdoc)
       aclay (vla-get-activelayout acdoc)
       acpvp (vla-item (vla-get-block aclay) 0)
 )
 (if (setq sel (ssget "_:L" (list (cons 410 (getvar 'CTAB)))))
   (progn
     (setq nwlay (vla-add aclyo (_UniqueKey aclyo "Layout")))
     (if (not (eq "MODEL" (strcase (vla-get-name aclay))))
       (vla-copyfrom aclay nwlay)
     )
     (repeat (setq j (sslength sel))
       (setq objs (cons (vlax-ename->vla-object (ssname sel (setq j (1- j)))) objs))
     )
     (vla-copyobjects acdoc
       (vlax-make-variant
         (vlax-safearray-fill
           (vlax-make-safearray vlax-vbobject (cons 0 (length objs))) (cons acpvp (reverse objs))
         )
       )
       (vla-get-block nwlay)
     )
     (mapcar 'vla-delete objs)
   )
 )
 (princ)
)
(vl-load-com) (princ)

Link to comment
Share on other sites

Or, here's a shortened version of the code I linked you to - this one using a selection:

 

Oh yeah! Thank you very much. This will save me a lot of time.

Link to comment
Share on other sites

Oh yeah! Thank you very much. This will save me a lot of time.

 

You're very welcome nlao :) I might consider adding this program to my site since it seems quite useful :)

Link to comment
Share on other sites

  • 1 year later...

Hello,

 

I'm trying to use this code with AutoCAD 2012. I write multisheets documents for electrical schemas and it will save a lot of time to be able to automatically produce the layout for printing a pdf.

 

Using the automated version (the one supposed to loop) I get an automation error, using the short one I don't get the result I should but the produced layout is much bigger than the selected title block.

 

Have you ever tested it with CAD 2012?

 

Thanks

 

Or, here's a shortened version of the code I linked you to - this one using a selection:

 

(defun c:LayoutCutter ( / _UniqueKey acdoc aclay aclyo acpvp j nwlay objs sel )
 ;; © Lee Mac 2011

 (defun _UniqueKey ( collection seed / i key ) (setq i 0)
   (while
     (not
       (vl-catch-all-error-p
         (vl-catch-all-apply 'vla-item
           (list collection (setq key (strcat seed (itoa (setq i (1+ i))))))
         )
       )
     )
   )
   key
 )

 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
       aclyo (vla-get-layouts acdoc)
       aclay (vla-get-activelayout acdoc)
       acpvp (vla-item (vla-get-block aclay) 0)
 )
 (if (setq sel (ssget "_:L" (list (cons 410 (getvar 'CTAB)))))
   (progn
     (setq nwlay (vla-add aclyo (_UniqueKey aclyo "Layout")))
     (if (not (eq "MODEL" (strcase (vla-get-name aclay))))
       (vla-copyfrom aclay nwlay)
     )
     (repeat (setq j (sslength sel))
       (setq objs (cons (vlax-ename->vla-object (ssname sel (setq j (1- j)))) objs))
     )
     (vla-copyobjects acdoc
       (vlax-make-variant
         (vlax-safearray-fill
           (vlax-make-safearray vlax-vbobject (cons 0 (length objs))) (cons acpvp (reverse objs))
         )
       )
       (vla-get-block nwlay)
     )
     (mapcar 'vla-delete objs)
   )
 )
 (princ)
)
(vl-load-com) (princ)

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