Author Topic: plot every rectangle in drawing as the plot extents  (Read 4490 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 342
plot every rectangle in drawing as the plot extents
« on: December 18, 2011, 04:06:56 PM »
Hello

I'm just plotting some floorplans we are working on to take to site to add detail to.
I have drawn lots of rectangles to cover each room and now I need to plot each rectangle as the plot extents.
Wondered if anybody has a lisp already for this task that they could share (wishful thinking)?

many thanks
Pad

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: plot every rectangle in drawing as the plot extents
« Reply #1 on: December 18, 2011, 06:19:05 PM »
The following [untested] code will use the active plot settings applied to the Layout in which you are plotting:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:qplot ( / acdoc aclay acplt acsel i lst )
  2.  
  3.           aclay (vla-get-activelayout acdoc)
  4.           acplt (vla-get-plot acdoc)
  5.     )    
  6.     (if (setq acsel (ssget (list '(0 . "LWPOLYLINE") (cons 410 (getvar 'CTAB)))))
  7.         (repeat (setq i (sslength acsel))
  8.             (setq lst
  9.                 (apply 'append
  10.                     (mapcar
  11.                         (function
  12.                             (lambda ( pair )
  13.                                 (if (= 10 (car pair))
  14.                                     (list (cdr pair))
  15.                                 )
  16.                             )
  17.                         )
  18.                         (entget (ssname acsel (setq i (1- i))))
  19.                     )
  20.                 )
  21.             )
  22.             (vlax-invoke aclay 'setwindowtoplot
  23.                 (apply 'mapcar (cons 'min lst))
  24.                 (apply 'mapcar (cons 'max lst))
  25.             )
  26.             (vla-put-plottype aclay acwindow)
  27.             (vla-plottodevice acplt nil)
  28.         )
  29.     )
  30.     (princ)
  31. )

Pad

  • Bull Frog
  • Posts: 342
Re: plot every rectangle in drawing as the plot extents
« Reply #2 on: December 19, 2011, 03:52:27 PM »
thanks Lee. I'll give that a twirl.

P

Sam

  • Bull Frog
  • Posts: 201
Re: plot every rectangle in drawing as the plot extents
« Reply #3 on: December 20, 2011, 12:10:14 AM »
The following [untested] code will use the active plot settings applied to the Layout in which you are plotting:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:qplot ( / acdoc aclay acplt acsel i lst )
  2.  
  3.           aclay (vla-get-activelayout acdoc)
  4.           acplt (vla-get-plot acdoc)
  5.     )    
  6.     (if (setq acsel (ssget (list '(0 . "LWPOLYLINE") (cons 410 (getvar 'CTAB)))))
  7.         (repeat (setq i (sslength acsel))
  8.             (setq lst
  9.                 (apply 'append
  10.                     (mapcar
  11.                         (function
  12.                             (lambda ( pair )
  13.                                 (if (= 10 (car pair))
  14.                                     (list (cdr pair))
  15.                                 )
  16.                             )
  17.                         )
  18.                         (entget (ssname acsel (setq i (1- i))))
  19.                     )
  20.                 )
  21.             )
  22.             (vlax-invoke aclay 'setwindowtoplot
  23.                 (apply 'mapcar (cons 'min lst))
  24.                 (apply 'mapcar (cons 'max lst))
  25.             )
  26.             (vla-put-plottype aclay acwindow)
  27.             (vla-plottodevice acplt nil)
  28.         )
  29.     )
  30.     (princ)
  31. )

Dear sir,
this program test on acad 2012
some error area comes
Code: [Select]
Command: QPLOT

Select objects: 1 found

Select objects: 1 found, 2 total

Select objects: 1 found, 3 total

Select objects:  ; error: Automation Error. Description was not provided.
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: plot every rectangle in drawing as the plot extents
« Reply #4 on: December 20, 2011, 07:10:02 AM »
I'll look into it when I get a chance - It may need a delay between issuing the plot method.

Pad

  • Bull Frog
  • Posts: 342
Re: plot every rectangle in drawing as the plot extents
« Reply #5 on: December 20, 2011, 05:32:48 PM »
I get the same error on 2009.
The first sheet plots, but none of the others.
Thanks.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: plot every rectangle in drawing as the plot extents
« Reply #6 on: December 20, 2011, 06:00:21 PM »
Maybe this then, also untested (as don't have printer  :-P )

Code - Auto/Visual Lisp: [Select]
  1. (defun c:qplot ( / acdoc aclay acplt acsel lst )
  2.  
  3.          aclay (vla-get-activelayout acdoc)
  4.          acplt (vla-get-plot acdoc)
  5.    )
  6.    (while
  7.        (progn
  8.            (princ "\nSelect Rectangles Individually...")
  9.            (setq acsel (ssget "_+.:E:S" (list '(0 . "LWPOLYLINE") (cons 410 (getvar 'CTAB)))))
  10.        )
  11.        (setq lst
  12.            (apply 'append
  13.                (mapcar
  14.                    (function
  15.                        (lambda ( pair )
  16.                            (if (= 10 (car pair))
  17.                                (list (cdr pair))
  18.                            )
  19.                        )
  20.                    )
  21.                    (entget (ssname acsel 0))
  22.                )
  23.            )
  24.        )
  25.        (vlax-invoke aclay 'setwindowtoplot
  26.            (apply 'mapcar (cons 'min lst))
  27.            (apply 'mapcar (cons 'max lst))
  28.        )
  29.        (vla-put-plottype aclay acwindow)
  30.        (vla-plottodevice acplt nil)
  31.    )
  32.    (princ)
  33. )

Sam

  • Bull Frog
  • Posts: 201
Re: plot every rectangle in drawing as the plot extents
« Reply #7 on: December 21, 2011, 04:51:39 AM »
DEAR SIR,

SAME ERROR COME AT NEW VERSION OF LISP
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: plot every rectangle in drawing as the plot extents
« Reply #8 on: December 21, 2011, 05:20:02 AM »

Works for me in 2012.
Need to make sure the plot settings are valid first.

Try this

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: plot every rectangle in drawing as the plot extents
« Reply #9 on: December 21, 2011, 07:59:27 AM »
Thanks Kerry  :-)

Pad

  • Bull Frog
  • Posts: 342
Re: plot every rectangle in drawing as the plot extents
« Reply #10 on: December 21, 2011, 05:12:20 PM »
hmm damn it not working for me..

Command: qplot

Select Rectangles Individually...
Select objects:

Select Rectangles Individually...
Select objects: *Cancel*

Select objects:
Automation Error. Description was not provided.


I have done some more testing and it seems that if the plotter icon in the bottom right hand corner is busy with a 'plot job in progress' then the next rectangle will fail with 'Automation Error. Description was not provided.'.  But if I wait for the 'plot & publish job complete' pop up before clicking, then the next plot will work fine.
Is it possible instead of sending each rectangle individually, have them sent as a batch of sheets?

Thanks again Lee.

P



Sam

  • Bull Frog
  • Posts: 201
Re: plot every rectangle in drawing as the plot extents
« Reply #11 on: December 22, 2011, 02:13:44 AM »
DEAR SIR,

ERROR ON THIS SENTENCE

Code: [Select]
(vla-plottodevice acplt nil)
Every time we waste electricity, we put our planet's future in the dark. Let's turn around our attiude and start saving power and our planet, before it's too late
http://www.theswamp.org/donate.html

Lee Mac

  • Seagull
  • Posts: 12926
  • London, England
Re: plot every rectangle in drawing as the plot extents
« Reply #12 on: December 22, 2011, 01:46:07 PM »
DEAR SIR,

ERROR ON THIS SENTENCE

Code: [Select]
(vla-plottodevice acplt nil)

You will need to wait until each plot job has completed before sending another.

Pad

  • Bull Frog
  • Posts: 342
Re: plot every rectangle in drawing as the plot extents
« Reply #13 on: December 22, 2011, 04:42:42 PM »
Hi

I had quite a search and have found this lisp which works quite well, it doesn't have the waiting problem.  It expects a block instead of a rectangle which is no big deal.
The problem I'm finding though is it isn't using the plot device set up in the page setup.  I will leave a message to the author once I can remember my log on for that site.

http://forums.autodesk.com/t5/Visual-LISP-AutoLISP-and-General/automatic-plotting/m-p/3054890#M297146
Code - Auto/Visual Lisp: [Select]
  1. (defun C:PlotAll( / titleblockname titleblocknameLIST bnamefilterstring filterlist orientation sstitleblocks ctr cent tblist vl-tb pw1 pw2)
  2.  
  3.   (while (/= (setq titleblockname (getstring T "\nEnter Border and hit return: ")) "")
  4.     (setq titleblocknameLIST (append titleblocknamelist (list titleblockname)))
  5.     );while
  6.  
  7.   (setq bnamefilterstring "")
  8.   (foreach x titleblocknamelist
  9.     (setq bnamefilterstring (strcat bnamefilterstring x ","))
  10.     );foreach
  11.   (setq bnamefitlerstring (substr bnamefilterstring 1 (1- (strlen bnamefilterstring))))
  12.  
  13.   (setq filterlist (list (cons 0 "insert")))
  14.   (setq filterlist (append filterlist (list (cons 2 bnamefilterstring))))
  15.  
  16.   (setq sstitleblocks (ssget "x" filterlist))
  17.  
  18.   (if (not (> (sslength sstitleblocks) 0))
  19.     (progn
  20.       (princ "\nNo TitleBlocks Found.  Exiting")
  21.       (exit)
  22.       );progn
  23.     );if
  24.  
  25.   (setq ctr 0)
  26.   (while (setq cent (ssname sstitleblocks ctr))
  27.     (setq tblist (append tblist (list cent)))
  28.     (setq ctr (1+ ctr))
  29.     );while
  30.  
  31.  (foreach x tblist
  32.    (setq vl-tb (vlax-ename->vla-object x))
  33.    (vla-getboundingbox vl-tb 'pw1 'pw2)
  34.    (setq pw1 (vlax-safearray->list pw1)
  35.          pw2 (vlax-safearray->list pw2)
  36.          );setq
  37.  
  38.    (if (> (- (car pw2) (car pw1)) (- (cadr pw2) (cadr pw1)))
  39.      (setq orientation "Landscape")
  40.      (setq orientation "Portrait")
  41.      );if
  42.      
  43.    (command ".plot"
  44.             "Y";        detailed configuration
  45.             "" ;        current layout/model space
  46.             "default windows system printer";           PlotterName
  47.             "";         PaperSize
  48.             "";         paperUnits In MM?
  49.             orientation;                orientation Portrait Landscape
  50.             "";         Plot Upside Down
  51.             "W";        Window
  52.             pw1;        window p1
  53.             pw2;        window p2
  54.             "";         Scale Fit
  55.             "c";        Center Plot
  56.             "y";        Plot w/ Plot Styles
  57.             "";         PlotStyleTableName
  58.             "Y";        With Lineweights?
  59.             "A";        Shade Plot As Displayed
  60.             "";         Write to File
  61.             "N";        Save Changes to PSetup
  62.             "Y";        Proceed w/ plot
  63.             );plot
  64.    );foreach
  65.   (princ)
  66.   );defun

cheers
P