Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Select Entity W/ Options to Type in Text or Pick Point.

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
HS20EXR
1442 Views, 3 Replies

Select Entity W/ Options to Type in Text or Pick Point.

I am looking for some code that would allow me to select a MTEXT Entity - or other entity -  (as the DEFAULT option) but also to allow me to type in some text manually or to pick a point in the drawing. Something that would present the user with:

"Select an object or [P to pick a point]"  or

"Select MTEXT or [M to type].

I can write some code to type in text manually as the default option and get the second option to select entity using getstring and then write some condition of if code but I don't know how to do it having entsel as default opion.

Any help would be appreciated. Thank you.

 

3 REPLIES 3
Message 2 of 4
Lee_Mac
in reply to: HS20EXR

For fixed options, you can use an initget / getkword combination - here is a quick example:

 

(defun c:test ( / sel str )
    (while (null str)
        (setvar 'errno 0)
        (initget "Type Exit")
        (setq sel (entsel "\nSelect MText [Type/Exit] <Exit>: "))
        (cond
            (   (= 7 (getvar 'errno))
                (princ "\nMissed, try again.")
            )
            (   (or (null sel) (= "Exit" sel))
                (setq str "")
            )
            (   (= "Type" sel)
                (setq str (getstring t "\nEnter text <Exit>: "))
            )
            (   (/= "MTEXT" (cdr (assoc 0 (entget (car sel)))))
                (princ "\nThat isn't MText.")
            )
            (   (setq str (cdr (assoc 1 (entget (car sel))))))
        )
    )
    (if (/= "" str)
        (princ (strcat "\nUser input: " str))
    )
    (princ)
)

 

For more information on this technique, you may wish to read my tutorial on Prompting with a Default Option.

 

For arbitrary text input during object selection, see my 'Selection or Text' function, posted here.

 

Lee

Message 3 of 4
HS20EXR
in reply to: Lee_Mac

Thanks a lot for the useful and quick reply, Lee Mac. 

Message 4 of 4
Lee_Mac
in reply to: HS20EXR

You're welcome - ask if you are unsure of anything.

 

Lee

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost