while loop help

while loop help

Anonymous
Not applicable
1,230 Views
12 Replies
Message 1 of 13

while loop help

Anonymous
Not applicable

So currently I am attempting to create a routine to allow the user to automatically draw the walls for a floorplan with the option of after every wall drawn the user can choose to draw another one and this will continue until the user says no. I have started the routine, but am a little stuck as i cannot find anywhere what the arguments for the offset command are. I also cannot figure out how I get the line to draw the direction i want it to go

I have the bare bones of the routine (Yes I know I have arguments missing from command line) (at some point in the routine i'm going to add a fillet command for the inner walls)

thanks in advanceSmiley Wink

 

; The purpose of this program is to allow the user to enter/pick dimensions of  a floor plan
; and have it drawn for them

(defun C:wall(/ choice ip Lwall ang off)
	(setq choice "Yes")
	(while (= choice "Yes")
		(setq ip (getpoint "\nPlease select an insertion point: "))
		(setq Lwall (getdist "\nPlease enter/choose the distance for the wall: "))
		(setq ang (getangle "\nWhat angle would you like the wall to be at?: "))
		(command "Line" )
		(setq off (getdist "\nHow thick is this wall?: "))
		(command "_offset" off ) 

		(initget 1 "Yes No")
		(setq choice (getkword "\nWould you like to draw another wall? [Yes/No]: "))
	)

)

 

0 Likes
Accepted solutions (1)
1,231 Views
12 Replies
Replies (12)
Message 2 of 13

Ranjit_Singh
Advisor
Advisor

One option for example.

(defun c:wall  (/ choice ip lwall ang off)
 (setq choice "Yes")
 (while (= choice "Yes")
  (setq ip (getpoint "\nPlease select an insertion point: "))
  (setq lwall (getdist "\nPlease enter/choose the distance for the wall: ")); don't think this is needed since you draw the line anways
  (setq ang (getangle "\nWhat angle would you like the wall to be at?: "))
  (command "Line" pause pause "") ; no need to get distance at line 5 because you draw the line here
  (command "_offset")
  (while (> (getvar 'cmdactive) 0) (command pause))
  (initget 1 "Yes No")
  (setq choice (getkword "\nWould you like to draw another wall? [Yes/No]: "))))

Another option to pick the point. You can play with nomutt and cmdecho to suppress any prompts

 

(defun c:somefunc ()
(command "._line" pause pause "")
(command "._offset" (getreal "\nSpecify offset distance: ") (entlast) pause ""))
Message 3 of 13

Anonymous
Not applicable

Thankyou so much i always forget that when i do command "line" that it runs it like it would in cad and it already has user dialogue. Is there a way that I can make it ask How long do you desire the wall to be or something similar instead of the normal line prompt? I wouldn't need the angle prompt either since that is part of the line command correct? Also what is the purpose of the second while loop? (just for knowledge sake)

0 Likes
Message 4 of 13

Anonymous
Not applicable

weird i had a reply and it got deleted. in theory i wouldn't need the getangle either then correct? also is there a way to modify the line and offset command window prompts to say what i have in my code? lastly what is the second while loop for? (still learning)

0 Likes
Message 5 of 13

ВeekeeCZ
Consultant
Consultant

Make it user friendly...

 

;don't do this
(setq choice "Yes")
(while (= choice "Yes")
  (setq ip (getpoint "\nPlease select an insertion point: "))
  ; stuff
  (initget 1 "Yes No")
  (setq choice (getkword "\nWould you like to draw another wall? [Yes/No]: ")))


; do this, natural way
(while (setq ip (getpoint "\nPlease select an insertion point <no more walls>: "))
   ; stuff
  )
0 Likes
Message 6 of 13

Anonymous
Not applicable

wouldn't the second option be stuck in an infinite loop unless you hit esc?

0 Likes
Message 7 of 13

ВeekeeCZ
Consultant
Consultant

Try to type (getpoint "Now hit <enter>: ") into command line and hit ENTER.

0 Likes
Message 8 of 13

Anonymous
Not applicable

"Point or option keyword required." 

^^^ My code goes to this after it hits the offset command section

 

0 Likes
Message 9 of 13

Ranjit_Singh
Advisor
Advisor

If you have specified any option keywords calling initget before the getpoint function, then it throws that error unless you pass a point or one of the keywords.

0 Likes
Message 10 of 13

Anonymous
Not applicable

This is what I currently have, also the typical command window prompts for line and offset are non-existent. also the offset command does not run

 

; Garrett Ford 6/22/17

; The purpose of this program is to allow the user to enter/pick dimensions of  a floor plan
; and have it drawn for them

(defun C:fp(/ choice)
	(setq choice "Yes")
	(while (= choice "Yes")
		(princ "\nPick Points/Enter Length of the wall: ")
		(command "Line" pause pause)
		(princ "\nOffset your Wall: ")
		(command "_offset")
		(setvar 'cmdactive 0)

		(initget 1 "Yes No")
		(setq choice (getkword "\nWould you like to draw another wall? [Yes/No]: "))
	)

)
0 Likes
Message 11 of 13

Ranjit_Singh
Advisor
Advisor
Accepted solution

@Anonymous wrote:

This is what I currently have, also the typical command window prompts for line and offset are non-existent. also the offset command does not run

 

; Garrett Ford 6/22/17

; The purpose of this program is to allow the user to enter/pick dimensions of  a floor plan
; and have it drawn for them

(defun C:fp(/ choice)
	(setq choice "Yes")
	(while (= choice "Yes")
		(princ "\nPick Points/Enter Length of the wall: ")
		(command "Line" pause pause ""); "" needed to end the command
		(princ "\nOffset your Wall: ")
		(command "_offset")
		(setvar 'cmdactive 0);cmdactive is a read-only variable. Cannot use setvar. You don't need this line anyways

		(initget 1 "Yes No")
		(setq choice (getkword "\nWould you like to draw another wall? [Yes/No]: "))
	)

)


Try below

(defun C:fp(/ choice)
 (setq choice "Yes")
 (while (= choice "Yes")
 (princ "\nPick Points/Enter Length of the wall: ")
 (command "Line" pause pause "")
 (princ "\nOffset your Wall: ")
 (command "._offset" (getreal "\nSpecify offset distance: ") (entlast) pause "")
 (initget 1 "Yes No")
 (setq choice (getkword "\nWould you like to draw another wall? [Yes/No]: "))))
Message 12 of 13

Anonymous
Not applicable

Thankyou so much Smiley Very Happy

0 Likes
Message 13 of 13

ВeekeeCZ
Consultant
Consultant

This is what I've meant. Finish by enter.

 

(defun c:Wall (/ ip off)

  (initget 6)
  (setq off (getreal "\nWall offset: "))

  (while (setq ip (getpoint (strcat "\nStart draw a wall with offset of " (rtos off 2 1) (if ip " <done>" "") ": ")))
    (command "_.LINE" "_none" ip PAUSE ""
             "_.OFFSET" off (entlast) "_none" PAUSE ""))
  (princ)
 )