While Break out Problem

While Break out Problem

richie_hodgson
Collaborator Collaborator
1,064 Views
7 Replies
Message 1 of 8

While Break out Problem

richie_hodgson
Collaborator
Collaborator

Having not a lot of fun trying to break out of a while loop, I have tried a couple of IF alternatives but to no avail I am probably missing something but now need a little input to get this thing moving.

 

 

(defun c:plpc (/ cursnap offset grade deltay pt1 pt2)

(setq cursnap (getvar "osmode"))

(setq pt1 (getpoint "\nPick Start Point :"))

(setvar "osmode" 0)

(setq offset 1)

(while not(= "" offset)

(setq offset (getreal "\nType Offset:"))

; (if not (= "" offset)

;(progn

(setq grade (getreal "\nType Percentage Grade:"))

(setq deltay (* offset (/ grade 100)))

(setq pt2 (mapcar '+ pt1 (List offset deltay 0)))

(command "_pline" pt1 pt2 "")

(setq pt1 pt2)

;))

)

(setvar "osmode" cursnap)

)

 

Hope you can help.

Richie
0 Likes
Accepted solutions (1)
1,065 Views
7 Replies
Replies (7)
Message 2 of 8

cadffm
Consultant
Consultant
Accepted solution
(defun c:plpc (/ offset grade deltay pt1 pt2)
  (setvar 'OSNAPCOORD 1)
  (if (setq pt1 (getpoint "\nPick Start Point :"))
      (while (and
	       (setq offset (getreal "\nType Offset: ")) ; thats not the autocad usual syntax / keyword INITGET
	       (setq grade  (getreal "\nType Percentage Grade: "))
) (setq deltay (* offset (/ grade 100))) (setq pt2 (mapcar '+ pt1 (list offset deltay 0))) (command "_.pline" pt1 pt2 "") (setq pt1 pt2) ) ) (princ) )

Sebastian

0 Likes
Message 3 of 8

john.uhden
Mentor
Mentor

It's probably just me, but I would get rid of the word "Type."

Until I saw (getreal), I thought you were asking for some type of offset, like maybe oblique, symmetric, octal, or other such terms that sound technically exotic.

John F. Uhden

0 Likes
Message 4 of 8

richie_hodgson
Collaborator
Collaborator

H John

 

The offset is in fact the horizontal distance for this example, the code could be adapted for slope distance but it suits my purpose.

 

Regards

 

RIchie

Richie
0 Likes
Message 5 of 8

ВeekeeCZ
Consultant
Consultant
Just you to know. NOT it the function and needs to be placed within parenthesis. (while (not (= ...
0 Likes
Message 6 of 8

john.uhden
Mentor
Mentor
Thank you for that explanation. My attempts at humor are often elusive.

John F. Uhden

0 Likes
Message 7 of 8

Kent1Cooper
Consultant
Consultant

Just a suggested different way, with less code and several fewer variables, and resulting in a single  Polyline profile rather than a batch of contiguous but separate single-segment ones [which, in that case, may as well just be Lines]:

 

(defun c:plpc (/ offset grade)
  (command "_pline" pause)
  (while
    (and
      (setq offset (getreal "\nOffset distance to right: "))
      (setq grade (getreal "\nPercentage Grade: "))
    ); and
    (command "_none" (mapcar '+ (getvar 'lastpoint) (list offset (* offset (/ grade 100)))))
  ); while
  (command ""); finish Pline
); defun

 

Kent Cooper, AIA
0 Likes
Message 8 of 8

richie_hodgson
Collaborator
Collaborator
Thanks very much for that. I was looking for a simple way to do this with a Pline command. I am back at work today after the Christmas break so thinking mode is not yet entirely engaged. Will look at the code a bit more closely when clever mode turns on.......

Regards

Richie
Richie
0 Likes