Author Topic: Entity Selection  (Read 3262 times)

0 Members and 1 Guest are viewing this topic.

DanB

  • Bull Frog
  • Posts: 367
Entity Selection
« on: April 01, 2005, 12:47:13 PM »
I'm looking for some assistance with entity selection in LISP.

pseudo code
Code: [Select]

Prompt for Entity Selection
User Selects Entity
Object Modified
Repeat Prompt for Entity Selection
Continue Until User Stops Selecting and hits Enter/Return (OR Escape?)-think this should be part of Error trap?
Exit and return any previous settings


My dilema comes from:
Code: [Select]

(setq ent (entsel "\nSelect something: "))

If user fails to select an entity (meaning the pick box just missed the arc or line, this returns nil) This ends the user selection process and ends the code prematurely. Must I test for nil with..
Code: [Select]

(if (= ent nil)

If so how does one incorporate accepting Enter (isn't Enter seen as nil??)

Hope this is clear enough to get my point across.
Thanks,
Dan

daron

  • Guest
Entity Selection
« Reply #1 on: April 01, 2005, 12:49:24 PM »
How about this:
Code: [Select]
(while
 (not (setq endata (car (entsel "\nSelect Object: "))))
     (prompt "\nNothing selected. ")
     )

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Entity Selection
« Reply #2 on: April 01, 2005, 12:51:17 PM »
Perhaps this will suffice ...

Code: [Select]
(while (setq ename (car (entsel)))

    ;;  do good stuff with ename

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Entity Selection
« Reply #3 on: April 01, 2005, 01:01:47 PM »
Ummm, what Daron said.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

daron

  • Guest
Entity Selection
« Reply #4 on: April 01, 2005, 01:02:38 PM »
I'm glad you agree. Wow.

DanB

  • Bull Frog
  • Posts: 367
Entity Selection
« Reply #5 on: April 01, 2005, 01:12:04 PM »
Thanks Daron, this looks like it's going to work.

Code: [Select]

(while
     (not (setq endata (car (entsel "\nSelect Object: "))))
         (prompt "\nNothing selected. ")
     )

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Entity Selection
« Reply #6 on: April 01, 2005, 04:14:59 PM »
Here is another way to process the entsel.
You can have different messages and exit on the Enter key.
Just another way to skin the old cat.

Code: [Select]
(while
  (not
    (progn
      (setvar "errno" 0) ; must pre set the errno to 0
      (setq ename (car (entsel "\nSelect Object: ")))
      (cond
        ((= (getvar "errno") 52)
         (prompt "\nEnter Key Pressed, Good Bye. ")
         T
        )
        ((null ename)
         (prompt "\nNothing selected. ") ; returns nil
        )
        ((= (cdr (assoc 0 (entget ename))) "ARC")
         (prompt "\nObject is an Arc, Try again.")
        )
        ((= (cdr (assoc 0 (entget ename))) "LINE")
         (prompt "\nObject is an Line, Try again.")
        )
        ((vl-string-search "TEXT" (cdr (assoc 0 (entget ename))))
         ;;  text or Mtext or Rtext
         (prompt "\nObject is text, Try again.")
        )
        (T
         ;;   no match
         (prompt "\nYou got an something else, Good Bye. ")
         T ; allow exit from loop
        )
      )
    )
  )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SMadsen

  • Guest
Entity Selection
« Reply #7 on: April 05, 2005, 04:46:43 AM »
Very nice, CAB.

Dan's initial request also included detection of Escape. This can be added by using VL-CATCH-ALL-APPLY like below. Just remember to put the test for an error object before any test of ERRNO (Esc will cause a value of 52).

Code: [Select]
(while
  (not
    (progn
      (setvar "errno" 0)                ; must pre set the errno to 0
      (setq ename (vl-catch-all-apply 'entsel '("\nSelect Object: ")))
      (cond
        ((vl-catch-all-error-p ename)
         (prompt "\nEscape was pressed")
         T
        )
        ((= (getvar "errno") 52)
         (prompt "\nEnter Key Pressed, Good Bye. ")
         T
        )
        ((null ename)
         (prompt "\nNothing selected. ") ; returns nil
        )
        ((= (cdr (assoc 0 (entget (car ename)))) "ARC")
         (prompt "\nObject is an Arc, Try again.")
        )
        ((= (cdr (assoc 0 (entget (car ename)))) "LINE")
         (prompt "\nObject is a Line, Try again.")
        )
        ((vl-string-search "TEXT"
                           (cdr (assoc 0 (entget (car ename))))
         )
         ;;  text or Mtext or Rtext
         (prompt "\nObject is text, Try again.")
        )
        (T
         ;;   no match
         (prompt "\nYou got something else, Good Bye. ")
         T                              ; allow exit from loop
        )
      )
    )
  )
)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Entity Selection
« Reply #8 on: April 05, 2005, 08:15:59 AM »
Well I'll be, learn something every day here.
All this time I thought you couldn't catch the escape key press with lisp.
Thanks so much for that tip.

Good to see you back, you must be busy.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.