Jump to content

trying to mimic autocad "Point or option keyword required" in command line


Recommended Posts

Posted

I'm working on a lisp that that would have some options. I'd like the user to either start picking points or enter a keyword to access other options. So I need to get a point or string.

 

for this I found I could use initget bit code 128 along with "getpoint". The user can pick a point or enter a keyword. Unfortunately, the user can also enter any other string.

 

So then I thought, maybe I could use "While" and a Not/OR statement to filter out wrong values. The Not/Or evaluates to nil in the console so I'm not sure why it won't break the loop. Also when getting back to the loop I"m only allowed to enter a point. The INITGET is no longer valid. I tried grouping that into the WHILE statement that made things worse.

 

I'm not that strong with loops so I may be approaching this all wrong.

 

 

(defun C:test (/ ans )

 (initget 128 "Rectangular Polygonal reV")  
 
 (while
   (setq Ans (getpoint (strcat "\nSpecify first corner point or [Rectangular/Polygonal/reV]: ")))
   (not
     (or (= ans "Rectangular")
  (= ans "Polygonal")
  (= ans "reV")
  (= ans "")
  (= (type Ans) 'LIST)
  )
     )
   )
   
 (princ (strcat "\n" ans))

 (princ)
 
 );end defun

Posted

I think I know what I did wrong. I'll check later

Posted

alert output example

((lambda (/ p $ ret)
  ([color="blue"]while[/color] (not p)
    (initget 1 "Rectangular Polygonal reV")
    (setq p (getpoint (strcat "\nSpecify first corner point or [Rectangular/Polygonal/reV]: ")))
    (cond ((vl-consp p)
           (setq ret (cons (cond ($)
                                 ("Rectangular")
                                 )
                           (mapcar 'rtos p)
                           )
                 )
           )
          ((vl-some ''((x) (= p x)) '("Rectangular" "Polygonal" "reV"))
           (princ (strcat "\nYou have choosen "p" ? " ))
           (setq $ p
                 p nil
                 )
           )
          )
    )
  (alert
    (apply 'strcat (mapcar ''((a b) (strcat a b)) '("TYPE: " " X= " " Y= " " Z= ") ret))
    )
  )
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...