TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Gliderider 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?
-
Do you mean (entlast)?
-
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
-
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.
-
Thanks, but that doesn't seem to be a solution...
-
(ssname (ssget "_X" (list (cons 0 "LWPOLYLINE"))) 0)
-
Very nice VovKa..
Mine is slower.
;; 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
)
-
Thanks to both of you Vovka and Cab... there's more than one way to skin a cat.
-
thanx CAB.
it's a pity, lpseifert, but both our ways will sometimes fail when working in paperspaces :(
-
Thinking outside the cat box ...
(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:
(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.
-
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?
-
MP, never hindered by the box it would seem. 8-)
-
Try this.....
(ssget "L" '((0 . "LWPOLYLINE,POLYLINE")))
-
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 ....
-
In ACAD2000 all code worked as expected.
Must be a version specific error.