+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Full Member
    Discipline
    Architectural
    Using
    AutoCAD 2016
    Join Date
    Sep 2017
    Posts
    37

    Default Ask user for input and use it as symbol

    Registered forum members do not see this ad.

    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:

    Code:
    (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

  2. #2
    Super Member rlx's Avatar
    Computer Details
    rlx's Computer Details
    Operating System:
    W10
    Computer:
    i74ghz/ssd500/2tbhdd
    Discipline
    Electrical
    rlx's Discipline Details
    Occupation
    electrical designer dragon
    Discipline
    Electrical
    Details
    I dont excel in anything but I rearly give up
    Using
    AutoCAD 2016
    Join Date
    Nov 2014
    Location
    Bergen op Zoom , Netherlands
    Posts
    1,057

    Default

    Code:
     (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

  3. #3
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    1,290

    Default

    Code:
    (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
    Code:
    (sssetfirst nil selsetxxx)
    ;;; or eventually if ans is not localized
    Code:
    (sssetfirst nil (vl-symbol-value (read ans)))
    HTH., M.R.

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  4. #4
    Full Member
    Discipline
    Architectural
    Using
    AutoCAD 2016
    Join Date
    Sep 2017
    Posts
    37

    Default

    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)

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

  5. #5
    Super Member marko_ribar's Avatar
    Computer Details
    marko_ribar's Computer Details
    Operating System:
    Windows 7 Ultimate X64
    Computer:
    Intel quad core CPU 4x2.66GHz, 8GB RAM
    Motherboard:
    INTEL compatibile
    CPU:
    quad core 4x2.66GHz
    RAM:
    8GB
    Graphics:
    NVIDIA GeForce 6600 GT
    Primary Storage:
    250 GB
    Secondary Storage:
    500 GB
    Monitor:
    Samsung 17''
    Discipline
    Architectural
    marko_ribar's Discipline Details
    Occupation
    Architecture, project designer, project visualisation
    Discipline
    Architectural
    Details
    space design - modeling and animations
    Using
    AutoCAD 2014
    Join Date
    Feb 2010
    Location
    Belgrade, Serbia, Europe
    Posts
    1,290

    Default

    Maybe :
    Code:
    (setq hl (vl-symbol-value (read ans)))

    Marko Ribar, d.i.a. (graduated engineer of architecture)
    M.R. on YouTube

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Win 7 Pro / Win 10 Pro / Linux Mint
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2018
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,590

    Default

    Code:
    (setq hl (eval (read ans)))
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  7. #7
    Full Member
    Discipline
    Architectural
    Using
    AutoCAD 2016
    Join Date
    Sep 2017
    Posts
    37

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by marko_ribar View Post
    Maybe :
    Code:
    (setq hl (vl-symbol-value (read ans)))

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

Similar Threads

  1. ESC User Input
    By Lee Chu Chu in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 14th Jul 2014, 01:46 am
  2. Looking for user input
    By Skilbride in forum AutoCAD General
    Replies: 13
    Last Post: 23rd May 2011, 08:28 pm
  3. Looking for user input
    By Skilbride in forum Autodesk Inventor
    Replies: 0
    Last Post: 20th May 2011, 07:28 pm
  4. user input
    By salman in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 13th May 2010, 04:33 pm
  5. User Input:
    By tzframpton in forum AutoLISP, Visual LISP & DCL
    Replies: 4
    Last Post: 10th May 2007, 07:12 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts