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

select object or give keyword

12 REPLIES 12
Reply
Message 1 of 13
Thomas.l
836 Views, 12 Replies

select object or give keyword

Hi All,

 

I am working on a lisp where the user can chose between selecting an object or a point.

This is how far i came:

 

    (setq end (progn
		(initget 128)
		(getpoint "\n specify endpoint [object]")
		))
    (if (eq (type end) 'str)
      (setq end (entsel "\n specify endobject [point]")))

 But now i whant the user to be able to swich back to inserting a point in stead of selecting an object.

 

Hope this makes any sense 😄

 

Regards

 

Thomas

12 REPLIES 12
Message 2 of 13
pbejse
in reply to: Thomas.l


@Thomas.l wrote:

Hi All,

 

I am working on a lisp where the user can chose between selecting an object or a point.

This is how far i came:

 

    (setq end (progn
		(initget 128)
		(getpoint "\n specify endpoint [object]")
		))
    (if (eq (type end) 'str)
      (setq end (entsel "\n specify endobject [point]")))

 But now i whant the user to be able to swich back to inserting a point in stead of selecting an object.

 

Hope this makes any sense 😄

 

Regards

 

Thomas


Not sure what you mean by swithc back but your code is doing whats its suppose to .

 

perhaps

(setq end (progn
  (initget 7 "O")
  (getpoint "\n specify endpoint [object]")
  ))
 (setq pt (if (not (listp end))
             (cadr (entsel "\n specify endobject [point]"))
             end))

 

 


 

Message 3 of 13
Thomas.l
in reply to: pbejse

What i want to acomplis is that once the user has chosen to select an object he gets the posibility to chose for a point again.

 

So the user is first asked to give a point. Then he dicides to select an object. But it is a stupid user and hi wants to be able again to select a point.

 

What i am trying to acomplishe is to do the same thing whit the entsel as whit the getpoint. If the users decides he wants to insert a point in stead of selecting an object he gives the point command and he gets the posibility to select a point.

 

Hopes this makes any sense.

 

And thank you for the update of my code!

 

Regards

 

thomas

Message 4 of 13
_Tharwat
in reply to: Thomas.l

Try this .....

 

(progn
  (initget 7 "Object")
  (if (eq (setq p (getpoint "\n specify endpoint [Object]"))
          "Object"
      )
    (setq o (car (entsel "\n Select Object :")))
  )
)

 

Message 5 of 13
CADaSchtroumpf
in reply to: Thomas.l

An another one...

 

(defun Entsel_Getpoint ( / )
  (initget 8)
  (while (not (null (setq pt_sel (getpoint "\nSelect an object / Point in boundary / <ENTER for exit>: "))))
    (setq obj_sel (nentselp pt_sel))
    (cond
      (obj_sel
        (print (entget (car obj_sel)))
      )
      (T
        (print pt_sel)
      )
    )
    (initget 8)
  )
  (prin1)
)

 

Message 6 of 13
pbejse
in reply to: Thomas.l

sample

 

(defun c:test  (/ decided end obj)
      (setq decided nil)
      (while (and (null decided)
                  (setq end  (progn
                                   (initget 7 "O")
                                   (getpoint
                                         "\n specify endpoint [object]")
                                   ))
                  )
            (cond
                  ((listp end)
                   (setq decided T
                         pt end))
                  ((eq end "O")
                   (if (setq obj  (entsel
                                        "\n specify endobject [point]/<Enter to pick point>"))
                         (setq decided T))
                   )
                  )
            )
      )

Message 7 of 13
Thomas.l
in reply to: pbejse

Thank you all fore these solutions but it still isn't what i am looking for.

 

CADaStroumph:

your solution is realy what it should be if i where to use the program for my one. But other people ho whont have any training have to be able to work whit it. This is why i want it to look exactly like every autocad command. So i am trying to do the selection whit the selection squire. But thank you for the input!

 

pbejse:

Your solution is olmost what I would like it to be. Only one more thing would be realy great: if i would have the posibility to simply type the command. I don't know if it is possibel and if it isn't this is defenetly the best solution for my purposes.

 

Thank you all anyway for looking in to this!

 

Regards

 

Thomas

Message 8 of 13
Ian_Bryant
in reply to: Thomas.l

Maybe something like:

(defun C:TEST ( / pt loop1 loop2)
 (setq loop1 nil loop2 nil)
 (while (not loop1)
  (initget 8 "Object")
  (setq pt (getpoint "\nSpecify endpoint [Object]: "))
  (if (= pt "Object")
   (progn
    (setq loop2 nil)
    (while (not loop2)
      (setvar "ERRNO" 0)
      (initget "Point")
      (setq pt (entsel "\nSelect endobject [Point]:"))
      (cond
         ((= (getvar "ERRNO") 7)
          (princ "\n Nothing selected. Try again. ")
          (setvar "ERRNO" 0)
         )
         ((= pt "Point") (setq loop2 T))
         (T (setq loop1 T loop2 T))
       );cond
       (setvar "ERRNO" 0)
     );while
    );progn
    (setq loop1 T)
  )
 )
 (princ pt)
 (princ)
)

 

Ian

Message 9 of 13
pbejse
in reply to: Thomas.l

FWIW

 

(defun c:test  (/ end obj)
      (while (and (null obj)
                  (setq end  (progn
                                   (initget 7 "O")
                                   (getpoint
                                         "\n specify endpoint [object]")
                                   ))
                  )
            (cond ((listp end) (setq obj T) end)
                  ((eq end "O")
                   (while (not (progn (initget "Point")
                     (setq obj (entsel "\n specify endobject [Point]"))))
                          (princ "\n Nothing selected. Try again. "))
                   (setq obj (if (eq obj "Point") nil  obj))
                   )
                  )
            )
      )

Message 10 of 13
scot-65
in reply to: Thomas.l

Have a look at this geometry - similar to Tharwat's answer...

 

 (initget "New Select")
 (setq a (entsel  "Room Size \nSelect text object to update or [New/Select] <Select>: "))
 (if (not a) (setq a "Select") );if
 (cond
  ( (= a "New")
           (setq p (getpoint "\nSpecify new text location: "))(setq a nil) )
  ( (= a "Select") (setq a (entsel "\nSelect text object to update: "))
           (if (/= (cdr (assoc 0 (entget (car a)))) "TEXT")
            (progn (princ "\nInvalid object selected. ")(setq a nil) ) ) )
  ( (/= (cdr (assoc 0 (entget (car a)))) "TEXT")
           (princ "\nInvalid object selected. ")(setq a nil) )
  ( a (princ) )
 );cond

 

???


Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.


Message 11 of 13
phanaem
in reply to: Thomas.l

In cases like this, you have to decide what to do if a null response is chosen.
You have two options: to exit command or to continue prompting for an input.
An example for the second one is "txt2mtxt" routine from Express Tool. But in this case, If you decide to interrupt the command, you have to press Esc.
I prefer a clean exit on Right-Click or Enter.
Here is my variant:

(defun select_or_pick ( / choose op msg pick)
  (defun choose ()
    (setq op  (car (vl-remove  op '("Object" "Point")))
          msg (car (vl-remove msg '("\nPick a point" "\nSelect object")))
          )
    (initget op)
    ((if (eq op "Object") getpoint entsel) (strcat msg " [" op "]: "))
   )
  (while (member (setq pick (choose)) '("Object" "Point")))
  pick
  )

 


Message 12 of 13
Ian_Bryant
in reply to: phanaem

The reason I was checking the Errno sysvar after the Entsel call,

was to differentiate between the user trying to select an object, but missing,

in which case he might want to try again, and the user hitting Enter,

to end the function, which then returns nil.

Ian

Message 13 of 13
pbejse
in reply to: Ian_Bryant


@Ian_Bryant wrote:

The reason I was checking the Errno sysvar after the Entsel call,

was to differentiate between the user trying to select an object, but missing,

in which case he might want to try again, and the user hitting Enter,

to end the function, which then returns nil.

Ian


I did'nt know that. Thanks for the info Ian_Bryant  🙂

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

Post to forums  

Autodesk Design & Make Report

”Boost