Author Topic: Improving on entsel  (Read 14860 times)

0 Members and 1 Guest are viewing this topic.

Chuck Gabriel

  • Guest
Improving on entsel
« on: February 28, 2008, 08:17:38 AM »
What do you guys do when you want the user to be able to interactively select an entity?

Entsel in its raw form leaves me wanting something more.  If the user misses their pick (easy to do), they don't get any second chances.  I've tried using ssget with the ":S" option, but I wasn't really happy with that either.  I honestly can't remember any longer what it did or didn't do that I didn't like.

I've tried wrapping up entsel in various looping constructs with tests for various conditions, and I've finally come up with something I can live with.  I just wonder if there is a better way.

Code: [Select]
(defun getEntity (msg type / input ent)
  (if
    (vl-catch-all-error-p
      (vl-catch-all-apply
'(lambda ()
   (while
     (and
       (= 3 (car (setq input (grread nil (logior 2 4 8) 2))))
       (or
(null (setq ent (nentselp (cadr input))))
(and
   type
   (/= (strcase type)
       (cdr (assoc 0 (entget (car ent))))
   )
)
       )
     )
   )
)
      )
    )
     nil
     ent
  )
)

My apologies if this has already been done to death.  If it has, I'd love to see the canonical method.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Improving on entsel
« Reply #1 on: February 28, 2008, 09:21:39 AM »
Chuck will you have any problems using 'type' as an argument?

(msg type  / input ent)
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Improving on entsel
« Reply #2 on: February 28, 2008, 09:24:34 AM »
Chuck will you have any problems using 'type' as an argument?

(msg type  / input ent)

DUH .... never mind!
TheSwamp.org  (serving the CAD community since 2003)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Improving on entsel
« Reply #3 on: February 28, 2008, 09:31:23 AM »
What do you guys do when you want the user to be able to interactively select an entity?

Anted this post up in the remote chance you'll find it interesting.

If the user misses their pick (easy to do), they don't get any second chances.

Is that a bad thing?

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

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #4 on: February 28, 2008, 10:13:16 AM »
What do you guys do when you want the user to be able to interactively select an entity?

Anted this post up in the remote chance you'll find it interesting.

Thanks.  I did take some inspiration from my memories of that thread.  I actually read that the first time around, studied the code thoroughly, and archived it for future reference.  Maybe now would be a good time to revisit it.

If the user misses their pick (easy to do), they don't get any second chances.

Is that a bad thing?

:)

Speaking as a user, sometimes it frustrates the heck outta me. :-)

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #5 on: February 28, 2008, 10:15:42 AM »
While I'm at it, I noticed that the code I posted wasn't handling complex entities the way I wanted.  Here is a new attempt:

Code: [Select]
(defun getEntity (msg type / input ent)
  (if
    (vl-catch-all-error-p
      (vl-catch-all-apply
'(lambda ()
   (while
     (and
       (= 3 (car (setq input (grread nil (logior 2 4 8) 2))))
       (or
(null (setq ent (nentselp (cadr input))))
(and
   type
   (/= (strcase type)
       (if (> (length ent) 2)
(cdr (assoc 0 (entget (caar (reverse ent)))))
(cdr (assoc 0 (entget (car ent))))
       )
   )
)
       )
     )
   )
)
      )
    )
     nil
     ent
  )
)

daron

  • Guest
Re: Improving on entsel
« Reply #6 on: February 28, 2008, 10:30:41 AM »
Hmm. I'm still not getting this one. What goes in the msg and type arguments? Why isn't msg being used in the code but required as an argument? Is it because of the vl-catch-all-'s? How is the type argument being used and not returning a problem and what do you put in for its argument?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Improving on entsel
« Reply #7 on: February 28, 2008, 10:30:55 AM »
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Improving on entsel
« Reply #8 on: February 28, 2008, 11:20:45 AM »
If I understand, you want to loop entsel until the user hits enter to exit it... If so I just do it like (for selection a block for example)

Code: [Select]
(setvar 'ErrNo 0)
(while (not (equal (getvar 'ErrNo) 52))
    (if
        (and
            (setq Sel (entsel "\n Select block: "))
            (setq EntData (entget (car Sel)))
            (= (cdr (assoc 0 EntData)) "INSERT")
        )
        (progn
            (prompt "\n Got block, select again.")
        )
    )
)
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Improving on entsel
« Reply #9 on: February 28, 2008, 12:11:17 PM »
Chuck,
Do you realize that type is a function and you are using it as a variable?
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.

daron

  • Guest
Re: Improving on entsel
« Reply #10 on: February 28, 2008, 12:22:41 PM »
Chuck,
Do you realize that type is a function and you are using it as a variable?

I think that's what Mark was alluding to, but seems to have gained understanding of its usefulnes.
Chuck will you have any problems using 'type' as an argument?

(msg type  / input ent)

DUH .... never mind!
And what I am still waiting on an answer for.
Hmm. I'm still not getting this one. What goes in the msg and type arguments? Why isn't msg being used in the code but required as an argument? Is it because of the vl-catch-all-'s? How is the type argument being used and not returning a problem and what do you put in for its argument?

CAB, in case you did catch all that, I was just putting it all together for safe keeping.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Improving on entsel
« Reply #11 on: February 28, 2008, 12:36:29 PM »
Wow, jumped in the end here and missed all that.   :oops:
Guess I'll read the entire thread now. 8-)
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 #12 on: February 28, 2008, 12:41:48 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 Gabriel

  • Guest
Re: Improving on entsel
« Reply #13 on: February 28, 2008, 12:46:42 PM »
If I understand, you want to loop entsel until the user hits enter to exit it... If so I just do it like (for selection a block for example)

Code: [Select]
(setvar 'ErrNo 0)
(while (not (equal (getvar 'ErrNo) 52))
    (if
        (and
            (setq Sel (entsel "\n Select block: "))
            (setq EntData (entget (car Sel)))
            (= (cdr (assoc 0 EntData)) "INSERT")
        )
        (progn
            (prompt "\n Got block, select again.")
        )
    )
)

Interesting.  ERRNO is not documented in the AutoCAD 2000i docs.

Chuck Gabriel

  • Guest
Re: Improving on entsel
« Reply #14 on: February 28, 2008, 12:48:15 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.