Author Topic: Entity name of last drawn entity type  (Read 4859 times)

0 Members and 1 Guest are viewing this topic.

Gliderider

  • Guest
Entity name of last drawn entity type
« on: September 17, 2008, 07:43:13 AM »
How can I get the entity name of the last drawn entity type? e.g... The entity name of the last drawn polyline, even if there have been circles and arcs drawn since?

kpblc

  • Bull Frog
  • Posts: 396
Re: Entity name of last drawn entity type
« Reply #1 on: September 17, 2008, 08:05:54 AM »
Do you mean (entlast)?
Sorry for my English.

Gliderider

  • Guest
Re: Entity name of last drawn entity type
« Reply #2 on: September 17, 2008, 08:12:43 AM »
Entlast returns the last created entity, I'm looking to find the last created entity of a certain type.
I tried (ssget "L" '((0 . "LWPOLYLINE"))) but that didn't work, returned nil

Alan Cullen

  • Guest
Re: Entity name of last drawn entity type
« Reply #3 on: September 17, 2008, 08:42:45 AM »
Not to get too carried away here...but there are two types of polylines here...L and LW...depends on a variable setting...

Maybe......

(ssget "L" '((0 . "LWPOLYLINE" "POLYLINE")))

Just my two bobs worth.

Gliderider

  • Guest
Re: Entity name of last drawn entity type
« Reply #4 on: September 17, 2008, 08:57:10 AM »
Thanks, but that doesn't seem to be a solution...

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Entity name of last drawn entity type
« Reply #5 on: September 17, 2008, 10:16:24 AM »
Code: [Select]
(ssname (ssget "_X" (list (cons 0 "LWPOLYLINE"))) 0)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Entity name of last drawn entity type
« Reply #6 on: September 17, 2008, 10:27:07 AM »
Very nice VovKa..

Mine is slower.
Code: [Select]
;;  CAB - get last entity of a type in datatbase
(defun GetLastType (typ / e1 result )
  (and
    (setq e1 (entnext))
    (while (setq e1 (entnext e1))
      (if (= typ (cdr (assoc 0 (entget e1))))
        (setq result e1)
      )
    )
  )
  result
)
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.

Gliderider

  • Guest
Re: Entity name of last drawn entity type
« Reply #7 on: September 17, 2008, 10:37:51 AM »
Thanks to both of you Vovka and Cab... there's more than one way to skin a cat.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Entity name of last drawn entity type
« Reply #8 on: September 17, 2008, 10:54:34 AM »
thanx CAB.
it's a pity, lpseifert, but both our ways will sometimes fail when working in paperspaces :(

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Entity name of last drawn entity type
« Reply #9 on: September 17, 2008, 10:55:36 AM »
Thinking outside the cat box ...

Code: [Select]
(defun _Sort_SS_By_ObjectID ( ss )
    ;;  returns the selection set as a list
    ;;  of objects, ordered by objectid
    (vl-sort
        (if (eq 'pickset (type ss))
            (mapcar
               '(lambda ( x ) (vlax-ename->vla-object (cadr x)))
                (vl-remove-if '(lambda ( x ) (minusp (car x))) (ssnamex ss))
            )
        )
       '(lambda ( a b ) (< (vla-get-objectid a) (vla-get-objectid b)))
    )
)

Example:

Code: [Select]
(last (_Sort_SS_By_ObjectID (ssget "x" '((0 . "LwPolyline")))))
Once you get the desired object you could then turn it back into an ename if that's what you need.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Entity name of last drawn entity type
« Reply #10 on: September 17, 2008, 11:02:49 AM »
thanx CAB.
it's a pity, lpseifert, but both our ways will sometimes fail when working in paperspaces :(
Are you implying that the user may want only Current Space & then there would be a bad result?
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Entity name of last drawn entity type
« Reply #11 on: September 17, 2008, 11:03:40 AM »
MP, never hindered by the box it would seem. 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.

Alan Cullen

  • Guest
Re: Entity name of last drawn entity type
« Reply #12 on: September 17, 2008, 11:06:44 AM »
Try this.....

(ssget "L" '((0 . "LWPOLYLINE,POLYLINE")))

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Entity name of last drawn entity type
« Reply #13 on: September 17, 2008, 11:27:10 AM »

Are you implying that the user may want only Current Space & then there would be a bad result?

create a layout "layout1"
draw a polyline there
create another layout "layout2"
and draw a polyline there
now activate "Model"
run your code and note the result
now activate "layout1" and then activate back "Model"
run your code and see that results are different (at least it is so in acad 2005)

this is all because of the specific bahavior of (entnext) which steps through model first and then through last active layout.

ssget does a like error

we should both add some kind of (= (getvar "CTAB") (cdr (assoc 410 ....

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Entity name of last drawn entity type
« Reply #14 on: September 17, 2008, 12:37:22 PM »
In ACAD2000 all code worked as expected.
Must be a version specific error.
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.