Jump to content

Select Entity or Enter Value


Steven P

Recommended Posts

Just putting this up here as something I wanted for a while and had 10 minutes to think last night.

 

 

I'd been wanting a routine "Select an entity or enter a value". Been doing it with initget which gives discrete values and not every possibility. So made up the following.

 

All good so far, haven't found out where it is broken yet.

 

Just to get your brains working then, trying to figure out how to change the mouse pointer as it hovers over an entity and not select it? Using grread and it's options you either get mouse pointer change and it selects automatically or no mouse pointer change and select with a mouse click as far as I can see. Any ideas?

 

Thanks

 

(defun c:EntOrValue ( / msg MyResult)
  (setq msg "\nSelect an Entity or enter a value: \n")
  (setq MyResult (EntorValue msg)
) ; end defun


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun EntorValue ( MSG / EndLoop sel MyEnt MyValue enta entb pt)
  (setq MyValue "")
  (setq MyEnt (list))
  (setq EndLoop "No")
  (princ MSG)
  (while (= EndLoop "No") ; start loop
    (setq sel (nth 1 (grread nil 0 2))) ; read keyboard / mouse inputs. Ignore mouse position, only if clicked
    (if (= (type sel) 'LIST)
      (progn ; if sel is a LIST,... ie. a mouse click, a point returned
        (setq MyEnt (nentselp sel)) ; select entity from point
        (if (= nil MyEnt)
          (Princ "\nMissed! Try again. Select text or enter a value: ") ; entity not selected
          (setq EndLoop "Yes") ; entity selected, end while loop
        ) ; end if
      ) ; end progn
      (progn ; if sel is not a LIST, i.e. a single keyboard entry
        (if (or (and (> sel 47)(< sel 57))(= sel 46)) ; numbers only
          (progn
            (princ (chr sel))
            (setq MyValue (strcat MyValue (chr sel) ))
          )
        )
        (if (= sel 45) ; -ve ; make negative number
          (progn
            (setq MyValue (strcat (chr sel) MyValue ))
            (princ " Making -ve\n")(princ MyValue)
          ) ; end progn
        ) ; end if

        (if (= sel 13) ; enter - end number input, end loop
          (progn
            (setq EndLoop "Yes")
          ) ; end progn
        ) ; end if
      ) ; end progn
    ) ; end if list
  ) ; end while


  (if ( = (length MyEnt) 0) ; if entity not selected
    (progn
      MyValue ; return number entered
    ) ; end progn
    (progn
      ;;GetEnt code
      (setq enta (car MyEnt))
      (setq pt (cdr (assoc 10 (entget enta))) )
      ;;fix for nenset or entsel requirements
      (setq entb (last (last (nentselp pt)))) ;; use sel?
      (if (and (/= entb nil) (/= (type entb) 'real) )
        (progn
          (if (wcmatch (cdr (assoc 0 (entget entb))) "ACAD_TABLE,*DIMENSION,*LEADER")(setq enta entb))
        )
      )
      (setq MyEnt enta)
      MyEnt ; return entity name, including nested say text from dimensions
    ) ; end progn
  ) ; end if
)

 

Edited by Steven P
  • Like 1
Link to comment
Share on other sites

Thanks for the link, I am happy with this code for now:

 

(defun EntorValue ( MSG / EndLoop sel MyEnt MyValue enta entb pt)
  (princ MSG) ; message
  (setq MyValue "")
  (setq MyEnt (list))
  (setq EndLoop "No")
  (while (= EndLoop "No")
    (setq grsel (grread nil 4 2)) ; Read from mouse or keyboard entry
    (setq sela (car grsel)) ; type of entry
    (if (or (= sela 2)(= sela 3) ) ; text entry or mouse click
      (setq sel (nth 1 grsel)) ; what was entered, a point, or text
    )
    (if (= (type sel) 'LIST)
      (progn
        (setq MyEnt (nentselp sel)) ; if mouse entry selected en entity
        (if (= nil MyEnt)
          (Princ "\nMissed! Try again: ")
          (setq EndLoop "Yes")
        ) ; end if
      ) ; end progn
      (progn
        (if (or (and (> sel 47)(< sel 57))(= sel 46)) ; if keyboard entry is a number
          (progn
            (princ (chr sel))
            (setq MyValue (strcat MyValue (chr sel) ))
          )
        )
        (if (= sel 45) ; -ve ; if keyboead entry is '-' add '-' to beginning of string
        ;;Future check to be done if using A-Z keyboard entry, not just numbers
        ;;Future check in case number is allready -ve
          (progn
            (setq MyValue (strcat (chr sel) MyValue ))
            (princ " Making -ve\n")(princ MyValue)
          ) ; end progn
        ) ; end if

        (if (= sel 13) ; enter ; end keyboard entry. Note mouse selection cancels keyboard entry
          (progn
            (setq EndLoop "Yes")
          ) ; end progn
        ) ; end if
      ) ; end progn
    ) ; end if list
  ) ; end while


  (if ( = (length MyEnt) 0)
    (progn
      MyValue ; return MyValue
    ) ; end progn
    (progn ; entget for nested entities ; Also see Lee Mac CTX for alternative method
      ;;GetEnt code
      (setq enta (car MyEnt))
      (setq pt (cdr (assoc 10 (entget enta))) )
      ;;fix for nenset or entsel requirements
      (setq entb (last (last (nentselp pt)))) ;; use sel?
      (if (and (/= entb nil) (/= (type entb) 'real) )
        (progn
          (if (wcmatch (cdr (assoc 0 (entget entb))) "ACAD_TABLE,*DIMENSION,*LEADER")(setq enta entb))
        )
      )
      (setq MyEnt enta)
      MyEnt ; return entity name
    ) ; end progn
  ) ; end if
)

 

Link to comment
Share on other sites

  • 10 months later...
Posted (edited)

The problem with both Steven P and Lee Mac versions is it doesn't highlight entity on hover and doesn't allow select overlapping entities individually (via popup)

Edited by vanowm
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...