Author Topic: entity help  (Read 4707 times)

0 Members and 1 Guest are viewing this topic.

crowellsr

  • Guest
entity help
« on: July 29, 2007, 08:54:06 PM »
I am having a problem with entities.

I have the user select a point on an entity. It stores the selected point coordinates and the entity name in a variable. I want to get the entity typ and that is where I am havinbg problems. If the entity is a line I am going to run one section of the program and if it is an arc or circle I want it to run another section. If it is neither I want it to display a message such as "please select a line, arc or circle" (don't know how to do this part yet). What do I need to add to my code to get it to determine the entity type and store it in "typ"

(setq ent (entsel "Select point:"))
(setq typ (cdr (assoc 0 ent)))

Steve

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #1 on: July 29, 2007, 09:06:29 PM »

What is the value of ent ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

crowellsr

  • Guest
Re: entity help
« Reply #2 on: July 29, 2007, 09:15:42 PM »
The value of ent is the name of the entity selected and the coordinates of the point selected on the entity.

Steve

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #3 on: July 29, 2007, 09:19:29 PM »
ok, have a look at the ENTSEL help

At the bottom of the page
"See Also"

See anything that may help ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: entity help
« Reply #4 on: July 29, 2007, 09:30:02 PM »
Sorry to jump ahead, but have a look at this --

Code: [Select]
(defun c:MyProggy ( / ent ename data typex )

    (cond
   
        (   (setq ename (car (setq ent (entsel))))
       
            (setq
                data  (entget ename)
                typex (cdr (assoc 0 data))
            )
   
            (cond
   
                (   (member typex '( "ARC" "CIRCLE" ))
                   
                    (princ (strcat "Processing <" typex "> ...\n"))
                   
                    ;;  do ARC / CIRCLE stuff ...
                   
                )               
               
                (   (eq "LINE" typex)
   
                    (princ (strcat "Processing <" typex "> ...\n"))
   
                    ;;  do LINE stuff ...
                )
               
                (   t
   
                    (princ (strcat "DOH! No provision for <" typex "S>.\n"))
   
                )
               
            )
        )
       
        (   t   
       
            (princ "You didn't pick anything so I'm going for coffee.\n")
           
        )           
       
    )

    (princ)
   
)

Couple things to note:

The (ssget ":S" '((0 . "arc,circle,line"))) statement as coded limits selection to one entity, and the entity
must be an arc, circle or line. This statement was misleading at best.
I had the impression you'd be processing arcs and circles with the same code, thus they are both captured
by the statement (member typex '( "ARC" "CIRCLE" )). If this isn't appropriate code up separate
processing branches like detailed in the line processing (eq "LINE" typex).
Time to do some reading, it's all there in the tutorials / references.

Edit1: Sorry Kerry, sometimes I'm too impatient { shrug }.
Edit2: Revised sample code / comments per ensuing discussion.

:)
« Last Edit: July 29, 2007, 09:57:25 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #5 on: July 29, 2007, 09:33:52 PM »
Thanks Michael.

I was going to lead him on a treasure hunt to a similar answer.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #6 on: July 29, 2007, 09:37:06 PM »
Couple things to note:

The (ssget ":S" '((0 . "arc,circle,line"))) statement as coded limits selection to one entity, and the entity
must be an arc, circle or line.


This is not actually correct.
The selection is limited to a single try, not one entity.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: entity help
« Reply #7 on: July 29, 2007, 09:41:31 PM »
Thanks Michael.

I was going to lead him on a treasure hunt to a similar answer.

See footnote on last post. I hard started the example before anyone had responded and
by the time I'd finished yoiks, a couple posts:

Quote
Warning - while you were typing a new reply has been posted. You may wish to review your post.

But I was already committed (or should be) so I posted it anyway.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

crowellsr

  • Guest
Re: entity help
« Reply #8 on: July 29, 2007, 09:46:56 PM »
I looked at entsel in th VisualLISP help but it did not have a See Also at the bottom. I am still unsure of what I am doing wrong. All of the programs I have written up to now have created entities and not had to retreive info from them, so I am really new at this part of it. My program successfully stores the selected coordinates and the entity name but I can't get it to retrieve the entity type. Is it in the VisualLISP help that I should have been looking?

Steve

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: entity help
« Reply #9 on: July 29, 2007, 09:48:37 PM »
This is not actually correct.
The selection is limited to a single try, not one entity.

Actually it will kind of work if pickauto is 0, which I failed to note. I said kind of because it
doesn't prevent the user from enter "p" at the selection prompt which, as you know, would
retrieve the last selection. So yeah, half baked at best for sure.

If you don't code up a decent alternative for filtered selection of a single entity I'll do one
later, but I've got to get back to work right now.

Thanks for the heads up Kerry and your continued quest for shared knowledge / excellence.

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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #10 on: July 29, 2007, 09:50:13 PM »
Steve,
Which ACAD version are you using ?

I was leading you to ENTGET.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #11 on: July 29, 2007, 09:54:56 PM »
This is not actually correct.
The selection is limited to a single try, not one entity.

Actually it will kind of work if pickauto is 0, .........

Yes, otherwise the user can select [say] crossing and select multiple ents ..


..............
If you don't code up a decent alternative for filtered selection of a single entity I'll do one
later, but I've got to get back to work right now. .......

I think there may be a couple of samples posted here at theSwamp already.
added:
Here's one
http://www.theswamp.org/index.php?topic=6992.0

and another [included]
http://www.theswamp.org/index.php?topic=17720.msg214383#msg214383
« Last Edit: July 29, 2007, 10:01:02 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

crowellsr

  • Guest
Re: entity help
« Reply #12 on: July 29, 2007, 09:59:26 PM »
I am using Landdesktop 2007. Does entget store the coordinates of the point picked also?

Steve

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: entity help
« Reply #13 on: July 29, 2007, 10:00:10 PM »
Thanks Kerry, I revised my original post accordingly but kept comments
intact so it so it doesn't wreak havoc with the discussion continuity, like
folks who delete their posts on a regular basis.

Edit: Man I can't spell tonight. The benefits of working all weekend I suppose.
« Last Edit: July 29, 2007, 10:02:24 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #14 on: July 29, 2007, 10:04:23 PM »
I am using Landdesktop 2007. Does entget store the coordinates of the point picked also?

Steve

no.
examine each of these variables.
Code: [Select]
(SETQ ent (ENTSEL))

(SETQ ename     (CAR ent)
      pickpoint (CADR ent)
      data      (ENTGET ename)
      enttype   (CDR (ASSOC 0 data))
)
« Last Edit: July 29, 2007, 10:05:58 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: entity help
« Reply #15 on: July 29, 2007, 10:13:38 PM »
Then have a look at the results of this ..
Code: [Select]
(IF (SETQ ss (SSGET ":S:E" '((0 . "LINE,ARC,CIRCLE"))))
  (SETQ ename   (SSNAME ss 0)
        data    (ENTGET ename)
        enttype (CDR (ASSOC 0 data))
  )
)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

crowellsr

  • Guest
Re: entity help
« Reply #16 on: July 29, 2007, 10:19:41 PM »
Thanks Kerry, it now gets the picked point and the type of entity. I can now start woking on the different sections of the program that it is directed to depending on the entity type.

Steve

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: entity help
« Reply #17 on: July 29, 2007, 11:45:18 PM »
And to get the pick point with ssget.
Code: [Select]
  (if (setq ss (ssget ":S:E" '((0 . "LINE,ARC,CIRCLE"))))
    (setq ssdata  (ssnamex ss 0)
          ename   (cadar ssdata)
          elist   (entget ename)
          enttype (cdr (assoc 0 data))
          PickPt  (cadr (car (cdddar ssdata)))
    )
  )
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.