Author Topic: Improving on entsel  (Read 14861 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Improving on entsel
« Reply #15 on: February 28, 2008, 12:50:47 PM »
Chuck will you have any problems using 'type' as an argument?

(msg type  / input ent)

DUH .... never mind!

No.  It was a good point.  I forgot that type is a reserved word.  I'll change it to etype.

Now I'm really confused. Second time today, I'm on a roll!! :-)
TheSwamp.org  (serving the CAD community since 2003)

daron

  • Guest
Re: Improving on entsel
« Reply #16 on: February 28, 2008, 12:52:45 PM »
Hmm. I'm still not getting this one. What goes in the msg and type arguments?

Msg is supposed to be a prompt.  See below.  The type parameter allows you to filter for specific entity types.

Why isn't msg being used in the code but required as an argument? Is it because of the vl-catch-all-'s?

That would be an error.  It's supposed to be a prompt, but I changed some things around and forgot to put the prompt back in.  Thanks for pointing that out.  I need to fix it.

Chuck will you have any problems using 'type' as an argument?

(msg type  / input ent)

DUH .... never mind!

No.  It was a good point.  I forgot that type is a reserved word.  I'll change it to etype.
That's what we were getting at. I was just confused by Marks revelation that seems to have been cleared up. See post above.

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #17 on: February 28, 2008, 12:58:59 PM »
That's what we were getting at. I was just confused by Marks revelation that seems to have been cleared up. See post above.

He was so convincing, he had me believing it wasn't a problem too. :D

The reason it wasn't causing me any problems is probably because I have the warning for "setq to protected symbols" turned off.

CAB - I haven't quite gotten to your version yet.  I plan to study right after I post this.

Thanks for all the input everybody.  This has been really enlightening for me.

daron

  • Guest
Re: Improving on entsel
« Reply #18 on: February 28, 2008, 01:03:44 PM »
He was so convincing, he had me believing it wasn't a problem too. :D
Likewise, but the more I looked at it, the more confused I became trying to figure out how it could be used like that.  :pissed: Mark, I needed that braincell. :ugly:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Improving on entsel
« Reply #19 on: February 28, 2008, 01:20:36 PM »
After reading the entire thread, here is my version.
Code: [Select]
(defun getEntity (msg enttype / picked ent1 ent2 return)
  (setvar "ErrNo" 0) ; reset variable
  (while
    (not
      (cond
        ((and (null (setq picked (nentsel msg)))
              (/= 52 (getvar "ErrNo")) ; <Enter> was not hit
         )
         (prompt "\nMissed, Try Again.")
        )
        ((null picked) t) ; exit loop
        ((progn
           (setq ent1 (car picked))
           (if (> (length picked) 2)
             (setq ent2 (caar (reverse picked)))
             (setq ent2 nil)
           )
           (cond
             ((null enttype)
              (setq return (if ent2 ent2 ent1))
             )
             ((and ent2 (= (strcase enttype)(cdr (assoc 0 (entget ent2)))))
              (setq return ent2)
             )
             ((= (strcase enttype) (cdr (assoc 0 (entget ent1))))
              (setq return ent1)
             )
             (t (prompt "\nWrong entity type, Try Again."))
           )
         )
        )
      )
    )
  )
  return
)


Code: [Select]
(defun c:test ()
  (getEntity "\nSelect a circle object." "CIRCLE")
)
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.

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #20 on: February 28, 2008, 01:23:30 PM »
Wow!  Information overload!

I came up with this after T.Willey educated me about the ERRNO system variable (how did that one slip under the radar?):

Code: [Select]
(defun getEntity (msg etype / ent)
  (setvar "ERRNO" 0)
  (if
    (vl-catch-all-error-p
      (vl-catch-all-apply
'(lambda ()
   (while
     (and
       (/= 52 (getvar "ERRNO"))
       (or
(null (setq ent (entsel msg)))
(/= (strcase etype) (cdr (assoc 0 (entget (car ent)))))
       )
     )
   )
)
      )
    )
     nil
     ent
  )
)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Improving on entsel
« Reply #21 on: February 28, 2008, 01:25:45 PM »
Glad I could help illuminate.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #22 on: February 28, 2008, 01:39:34 PM »
CAB - The only reason I was using nentselp before was so I could convert the picked point from grread into an entity.  I was never actually interested in the complex entity data.  That introduced the requirement to get the "parent" object when a complex entity was selected.

In fact, I started out with this:

Code: [Select]
(defun cci:getEntity (msg type / ent)
  (if (vl-catch-all-error-p
(vl-catch-all-apply
  '(lambda ()
     (while
       (or
(null (setq ent (entsel msg)))
(/= type (cdr (assoc 0 (entget (car ent)))))
       )
     )
   )
)
      )
    nil
    ent
  )
)

However, the only way the user could get out of the loop was by selecting an appropriate entity or pressing the escape key.  I switched to using grread instead of entsel so that I could differentiate between a missed pick and the user pressing return.

I'm probably on about the twentieth iteration of this thing now.  It keeps evolving bit by bit.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Improving on entsel
« Reply #23 on: February 28, 2008, 01:48:11 PM »
One more then.  :-)
Code: [Select]
(defun getEntity (msg enttype / picked ent return)
  (setvar "ErrNo" 0) ; reset variable
  (while
    (not
      (cond
        ((and (null (setq picked (entsel msg)))
              (/= 52 (getvar "ErrNo")) ; <Enter> was not hit
         )
         (prompt "\nMissed, Try Again.")
        )
        ((null picked) t) ; exit loop
        ((progn
           (setq ent (car picked))
           (cond
             ((null enttype) (setq return ent))
             ((= (strcase enttype) (cdr (assoc 0 (entget ent))))
              (setq return ent)
             )
             (t (prompt "\nWrong entity type, Try Again."))
           )
         )
        )
      )
    )
  )
  return
)
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.

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #24 on: February 28, 2008, 01:57:45 PM »
Thanks again everybody.

CAB - I noticed you allowed for non-filtered selection.  I had forgotten to do that in the last version I posted.  Good catch!

Here is what I think I have settled on:

Code: [Select]
(defun getEntity (msg etype / ent)
  (setvar "ERRNO" 0)
  (if
    (vl-catch-all-error-p
      (vl-catch-all-apply
'(lambda ()
   (while
     (and
       (/= 52 (getvar "ERRNO"))
       (or
(null (setq ent (entsel msg)))
(and
   etype
   (/= (strcase etype)
       (cdr (assoc 0 (entget (car ent))))
   )
)
       )
     )
   )
)
      )
    )
     nil
     ent
  )
)


daron

  • Guest
Re: Improving on entsel
« Reply #25 on: February 28, 2008, 02:39:29 PM »
Any thoughts on *polylines, so you don't have to differentiate between different types?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Improving on entsel
« Reply #26 on: February 28, 2008, 03:01:32 PM »
Any thoughts on *polylines, so you don't have to differentiate between different types?

Possibly:

Code: [Select]
(defun getEntity (msg etype / ent)
  (setvar "ERRNO" 0)
  (if
    (vl-catch-all-error-p
      (vl-catch-all-apply
'(lambda ()
   (while
     (and
       (/= 52 (getvar "ERRNO"))
       (or
(null (setq ent (entsel msg)))
(and
   (not (wcmatch (cdr (assoc 0 (entget (car ent))))
(strcase etype)
)
   )
)
       )
     )
   )
)
      )
    )
     nil
     ent
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

daron

  • Guest
Re: Improving on entsel
« Reply #27 on: February 28, 2008, 03:11:34 PM »
Hmm. You know, I tried that, but couldn't get it to work.

daron

  • Guest
Re: Improving on entsel
« Reply #28 on: February 28, 2008, 03:13:57 PM »
Don't know what I was doing wrong, but that works nice, Ron. Thanks.

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #29 on: February 28, 2008, 03:21:45 PM »
Good suggestion Daron and nice solution ronjonp.