Add looping to this lisp

Add looping to this lisp

anton_chmidt
Advocate Advocate
1,872 Views
13 Replies
Message 1 of 14

Add looping to this lisp

anton_chmidt
Advocate
Advocate

Hello can someone please help me with this code:

This is lisp for plotting.
#1. it ask user to select text object that contains filename for plotting pdf

#2. It ask to pick two opposite corners for plot window

#3. plot pdf.

 

My question: Is it possible for it to loop #1 and #2 untill "T"-key is pressed after #2, ending the loop and proceedeng to to #3 = plotting as many pdf´s as I have looped. 

Also I think it would be neccesary/awsome for it to check that user dont pick same name nor corners twice

Currently working code:

(defun c:PlotLS (/ FirstCorner SecondCorner Filename ) 

(setq Filename (cdr (assoc 1 (entget (car (entsel "\nSelect filename: "))))))



(setq FirstCorner (getpoint "
Pick a point or type coordinate: ")) ;this will ask for user input
(setq SecondCorner (getpoint "
Pick a point or type coordinate: ")) ;this will ask for user input

(command "-plot"
           "yes" ; Detailed plot configuration? [Yes/No] <No>:
           "" ; Enter a layout name or [?] <Model>:
           "DWG TO PDF.PC3" ; Enter an output device name or [?] <None>:
           "ISO full bleed A4 (210.00 X 297.00 mm)" ; Enter paper size or [?] <ISO A4 (210.00 x 297.00 MM)>:
           "Millimeters" ; Enter paper units [Inches/Millimeters] <Millimeters>:
           "Landscape" ; Enter drawing orientation [Portrait/Landscape] <Portrait>:
           "No" ; Plot upside down? [Yes/No] <No>:
           "Window" ; Enter plot area [Display/Extents/Limits/View/Window] <Display>:
			FirstCorner;
			SecondCorner;
           "Fit" ; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] <Fit>:
           "Center" ; Enter plot offset (x,y) or [Center] <11.00,11.00>:
           "yes" ; Plot with plot styles? [Yes/No] <Yes>:
           "monochrome.ctb" ; Enter plot style table name or [?] (enter . for none) <>:
           "yes" ; Plot with lineweights? [Yes/No] <Yes>:
           "As displayed" ; Enter shade plot setting [As displayed/Wireframe/Hidden/Visual styles/Rendered] <As displayed>:
           (strcat (getvar 'DWGPREFIX) Filename ".pdf")
           "no" ; Save changes to page setup [Yes/No]? <N>
           "Yes" ; Proceed with plot [Yes/No] <Y>:
  )

)


 

0 Likes
Accepted solutions (1)
1,873 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant

Just hit enter when you're done.

 

(defun c:PlotLS (/ FirstCorner SecondCorner Filename l)
  
  (while (and (setq Filename (entsel "\nSelect filename <plot>: "))
	      (setq Filename (cdr (assoc 1 (entget (car filename)))))
	      (setq FirstCorner (getpoint "Pick a point or type coordinate: ")) ;this will ask for user input
	      (setq SecondCorner (getpoint "Pick a point or type coordinate: ")) ;this will ask for user input
	      )
    (setq l (cons (list Filename FirstCorner SecondCorner) l)))
  
  (foreach e l
    (command "-plot"
	     "yes" ; Detailed plot configuration? [Yes/No] :
	     "" ; Enter a layout name or [?] :
	     "DWG TO PDF.PC3" ; Enter an output device name or [?] :
	     "ISO full bleed A4 (210.00 X 297.00 mm)" ; Enter paper size or [?] :
	     "Millimeters" ; Enter paper units [Inches/Millimeters] :
	     "Landscape" ; Enter drawing orientation [Portrait/Landscape] :
	     "No" ; Plot upside down? [Yes/No] :
	     "Window" ; Enter plot area [Display/Extents/Limits/View/Window] :
	     "_non" (cadr e);
	     "_non" (last e);
	     "Fit" ; Enter plot scale (Plotted Millimeters=Drawing Units) or [Fit] :
	     "Center" ; Enter plot offset (x,y) or [Center] <11.00,11.00>:
	     "yes" ; Plot with plot styles? [Yes/No] :
	     "monochrome.ctb" ; Enter plot style table name or [?] (enter . for none) <>:
	     "yes" ; Plot with lineweights? [Yes/No] :
	     "As displayed" ; Enter shade plot setting [As displayed/Wireframe/Hidden/Visual styles/Rendered] :
	     (strcat (getvar 'DWGPREFIX) (car e) ".pdf")
	     "no" ; Save changes to page setup [Yes/No]?
	     "Yes" ; Proceed with plot [Yes/No] :
	     ))
  (princ)
  )

 

0 Likes
Message 3 of 14

anton_chmidt
Advocate
Advocate
Just quick clarify, does this ask everything first and plot aftert, because the plotting itself is slow and I would rather pick everything and then go grab a coffee while it plots everything.

0 Likes
Message 4 of 14

ВeekeeCZ
Consultant
Consultant

Now it should. But you know what, normal people do a coffee break when PUBLISHing. 

0 Likes
Message 5 of 14

anton_chmidt
Advocate
Advocate

Thank you very much once again! 

Yes I know about Publish & coffee. Publish was part of my routine at previous workplace. I remember even hitting 255 layout tab limit once, and then add +100 on another .dwg, someone should try to plot those one by one. 

I actually was shocked to some extent at first that here we dont use layouts. Untill I realized that indeed they are not effective here. I think 10 pages has been my most pages on single .dwg and usually it is at lower end of 1-5 pages. Would you agree that layouts would be a bit waste of time here? 

0 Likes
Message 6 of 14

anton_chmidt
Advocate
Advocate

Actually not working, it work exactly as original. I even tested creating new lisp just with your code and still asks and plot only one page as before. Neather am I pressing enter eather, after I click for second corner it plots and ends the lisp.
EDIT:
I should have mention before that plotting path is same as the dwg path + file name that comes from selected text object + .pdf

0 Likes
Message 7 of 14

ВeekeeCZ
Consultant
Consultant

Of course, it does not... how could, if the was no loop func. 

 

Without knowing the circumstances am I in no position to recommend anything. Personally, I do layouts almost for everything. 

0 Likes
Message 8 of 14

anton_chmidt
Advocate
Advocate

Hi again, this lisp has worked perfectly, it has helped so much on a daily basis, but now there is a risk that we wont store Filename like we used to. I am talking about filename from line: 

(while (and (setq Filename (entsel "\nSelect filename <plot>: "))

For now it is in  text object but in future it will possibly be in block attribute value. I am shocked by this change. So please tell me there is away to get filenames by selecting a blocks instead of text objects? The Attribute Tag is PIIR.NRO prompt is Piir.Nro and it is always on ninth row in Enchanced Attribute Editor. The block name/ id will be different and since you made this looping, user would point to multiple blocks in order to plot multiple files.

If this is possible to do the best solution would be that if user pick text or mtext it would work as before, but if user pick block it would take Attribute value from PIIR.NRO. Is this possible and could you help me with this? 

0 Likes
Message 9 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

Is this attribute visible to select from a drawing? If so, you can just use nentsel instead of entsel, and you're good to go.

0 Likes
Message 10 of 14

anton_chmidt
Advocate
Advocate

It is visible. I will try it out tomorrow. Thanks. Will nensel work for both possibilities? I mean eather block attribute or text content? If not is I possible to male work for both?

0 Likes
Message 11 of 14

Sea-Haven
Mentor
Mentor

Can you use layouts would make life easier as can do for me plot range it auto reads the layout name as the pdf name. I read you did comment about layouts.

 

There is lots of pick point in model space enter scale make a layout with company title block. Mview matches picked point. For 10 layouts would be very fast.

 

Like wise if must work in model set up a rectang block if no title block and read its size for the fit option again can do 10 in one go.

0 Likes
Message 12 of 14

anton_chmidt
Advocate
Advocate
Perfect! Thank you so much!
0 Likes
Message 13 of 14

anton_chmidt
Advocate
Advocate

Is it hard to add last selected filename as part of text entsel "\nSelect filename <plot>: "

Example: entsel "\n(Prev: Xxx01) Select next filename <plot>: "


Because sometimes when the list gets long there is a chance to mess up the selection. Would be nice to know which one was the last one already selected.

 

Also the printing happens inverted from the back of the list, this is not critical since I just can now select the plots from the back but if this is super simple to fix ( invert the list) that would be nice

0 Likes
Message 14 of 14

annoisscary
Advocate
Advocate

@anton_chmidt wrote:

is super simple to fix ( invert the list) that would be nice


There is a function for that, just Reverse the list.

0 Likes