Jump to content
Ament

Ask user for input and use it as symbol

Recommended Posts

Ament

Hi everyone. I hope this time I hava an easy one:

 

I want to ask the user to put in the name of a selection set during my lisp and call it later to highlight the elements inside.

 

Unfortunately I'm not that sure how to get the user input into work. See code below:

 

(setq ct -1)
   (setq ans (getstring "Please enter name of selection set. "))
   (setq ans (read ans))
   (repeat (sslength ans)
           (setq obX (ssname ans (setq ct (1+ ct))))
           (redraw obX 3)
    )

The issue is that I can't transfer the string from user to a (not sure, but I guess I need) symbol.

 

can someone give me a hint how to convert it.

 

Best regards,

 

Ament

Share this post


Link to post
Share on other sites
rlx

 (set (read "A") 5) 

 

 

 

 

note difference between set and setq

 

 

(princ a) -> 5

 

 

other symbol functions are vl-symbol-name & vl-symbol-value

 

 

gr.Rlx

Share this post


Link to post
Share on other sites
marko_ribar

(setq ans (getstring "\nSpecify name of sel. set : ")) ;;; you type selsetxxx
(set (read ans) (ssget)) ;;; to select entities and store them in selsetxxx

;;; to highlight it

(sssetfirst nil selsetxxx)

;;; or eventually if ans is not localized

(sssetfirst nil (vl-symbol-value (read ans)))

HTH., M.R.

Share this post


Link to post
Share on other sites
Ament

I checked it but if I'm not wrong it allows me to evaluate first argument too. But that won't work for me (I think).

 

(I updated the code to be able to clarify it easier as I used the same variable several times)

 

(defun c:MHI ( / )
   (setq ct -1)
   (setq ans (getstring "Please enter name of selection set. "))
   (setq hl (read ans))
   (repeat (sslength hl)
           (setq obX (ssname hl (setq ct (1+ ct))))
           (redraw obX 3)
   )
   (princ)
)

I have a selection set named tbe in my memory, so the user enters the name and I get the string "tbe" set as value for the variable ans

Now I want to have the same entry's of the selection set tbe in a new set hl.

 

(Edit)

 

Or just use the answer ("tbe") in my colde instead of hl. But it went wrong because it is not expecting a string there.

(Edit end)

 

 

Maybe I just don't see the forrest for the trees..

Share this post


Link to post
Share on other sites
marko_ribar

Maybe :

(setq hl (vl-symbol-value (read ans)))

Share this post


Link to post
Share on other sites
Lee Mac
(setq hl (eval (read ans)))

Share this post


Link to post
Share on other sites
Ament
Maybe :

(setq hl (vl-symbol-value (read ans)))

 

 

That's it.. Wasn't thinking far enough.. Thank you!!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×