Repeating command in lisp

Repeating command in lisp

hearnc843N533T
Participant Participant
918 Views
11 Replies
Message 1 of 12

Repeating command in lisp

hearnc843N533T
Participant
Participant

I am creating a command that will generate a new layer, and alert the user to select all sheets using the rectangle command with the new layer. I need help getting the rectangle command to repeat, so that the user can keep drawing rectangles until they exit the command.

 

The number of rectangles will vary per user, so I would need to make this loop indefinitely. I tried adding the while before the rectang command, but it still finishes the lisp with only 1 rectangle. 

 

I am a newbie, this is my first lisp.

 

(defun c:PL ()
	(command "-layer" "_M" "00PRINTLAYER" "_C" "1" "" "")
	(alert "Please Select All Sheets to Plot")
	(while (command "rectang"))
	
(princ)
)

 

0 Likes
Accepted solutions (1)
919 Views
11 Replies
Replies (11)
Message 2 of 12

MrJSmith
Advocate
Advocate

Try this.

(defun c:PL ()
	(command "-layer" "_M" "00PRINTLAYER" "_C" "1" "" "")
	(alert "Please Select All Sheets to Plot")
	(while 1 
		(command "rectang" (getpoint "Pick Start of Rectangle") (getpoint "Pick End of Rectangle."))
	)
	
(princ)
)	
0 Likes
Message 3 of 12

hearnc843N533T
Participant
Participant

Thank you for the response, this kind-of works.

 

The problem I ran into is that the cursor disappears from the model space after selecting the start point. As a result I am blindly selecting the end point. Any ideas as to why this happens?

0 Likes
Message 4 of 12

paullimapa
Mentor
Mentor

Any reason for drawing rectangles instead of actually selecting the objects with ssget?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 5 of 12

MrJSmith
Advocate
Advocate

I feel like I had that problem in the past as well, but for whatever reason mine seems to be staying throughout the command. Maybe it is a bug that ACAD fixed in later versions? I am currently running 2023.

 

I too was wondering about the drawing of rectangles VS just selecting the objects, but that would require more info as to what the goal of the script is.

0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@hearnc843N533T wrote:

.... alert the user to select all sheets using the rectangle command ....

(alert "Please Select All Sheets to Plot")
	(while (command "rectang"))

That seems a contradiction in terms -- drawing things is not the same as selecting things, and there's nothing in that code about selecting anything.  So I'm wondering what you're really doing.  Are you drawing rectangles around areas that you want plotted as sheets, all in Model Space, and you'll use those rectangles [Polylines] to define a window in plotting for each sheet?  If so, do you delete all those rectangles afterwards, so you won't have extraneous ones left hanging around the next time you want to run the command?  I would recommend you use Paper Space layouts to define the sheets, and Plot those.  But maybe I don't understand....

 

But if that drawing of rectangles is really what you want to do, and assuming there will ultimately be more to it, I would approach it this way [untested]:

 

(defun c:PL (/ pt)
  (command "_.layer" "_make" "00PRINTLAYER" "_color" 1 "" "")
  (alert "Outline All Sheet areas to Plot with Rectangles.")
  (while (setq pt "\nCorner of an outline Rectangle or <exit>: ")
    (command "_.rectang" pt pause)
  ); while	
  (prin1)
)

 

Hitting Enter to accept the <exit> default will set the 'pt' variable to nil, and stop the (while) loop.

 

[I would also recommend a different command name, because using PL kills that as the default command alias for PLINE.]

Kent Cooper, AIA
0 Likes
Message 7 of 12

MrJSmith
Advocate
Advocate
Accepted solution

@Kent1Cooper I think you meant to put a getpoint? Otherwise it works really well for me.

(defun c:PL (/ pt)
  (command "_.layer" "_make" "00PRINTLAYER" "_color" 1 "" "")
  (alert "Outline All Sheet areas to Plot with Rectangles.")
  (while (setq pt (getpoint "\nCorner of an outline Rectangle or <exit>: "))
    (command "rectang" pt pause)
  ); while	
  (prin1)
)

 

0 Likes
Message 8 of 12

hearnc843N533T
Participant
Participant

Yes- the drawings will not necessarily have a defined border with a specific layer name. I have another visual lisp I found that plots sheets within a rectangle, and I have modified it to specifically select the 00PRINTLAYER so there can be consistency, hence the need for this lisp I am working on. 

I intend to string the two together after I finish this one. As Kent mentioned I should change to the alert to outline, as there is another action after the plot command to select the sheets

0 Likes
Message 9 of 12

Kent1Cooper
Consultant
Consultant

@MrJSmith wrote:

@Kent1Cooper I think you meant to put a getpoint? ....


Yes, indeed -- that's what I get for not testing....

Kent Cooper, AIA
Message 10 of 12

hearnc843N533T
Participant
Participant

Thank you both for the help.

Kent- yes I do mean to outline areas to plot, I have a visual lisp that I found that later prompts the user to select the sheets to plot. The borders can stary so that they won't have to be created again if replotting is required. And good call on the PL command, forgot about that, I don't use it much.

0 Likes
Message 11 of 12

komondormrex
Mentor
Mentor

almost as original code

(defun c:PL ()
	(command "-layer" "_M" "00PRINTLAYER" "_C" "1" "" "")
	(alert "Please Select All Sheets to Plot")
	(while (null (command-s "rectang" pause pause)))
	(princ)
)
0 Likes
Message 12 of 12

Sea-Haven
Mentor
Mentor

Something like this make rectangs at selected sheet scale along a pline. Other version is just make rectangs at scale create 1 and copy. Next step is auto make layouts. Step after that is plot layouts. 

 

SeaHaven_0-1696305077722.png

 

 

 

0 Likes