Jump to content

Ask user for input and use it as symbol


Ament

Recommended Posts

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

Link to comment
Share on other sites

 (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

Link to comment
Share on other sites

(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.

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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...