TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: rude dog on February 18, 2004, 09:48:33 AM
-
How would you extract out a xref'd layer name...It seems to me the dxf codes do not work with these nested layer names? :?:
-
?? Can you give an example?
-
(setq ES (car (entsel "\nPick layer to keep thawed <Enter to exit>:")))
(setq EL (cdr (assoc 8 (entget ES))));extracts out layer names
This approach does not work on layers that are contained within the xref
usually I do invoke "xlist" command and pick on the entity and it brings up a dialog box showing the nested xref layer name...I was trying to think of a universal way to pull out layer names wheter they have been xref'd in or not
any idea's[/code]
-
Ahh, now I understand. It's just like when you pick a block with ENTSEL, you won't get info about the subents but only the insert.
Try looking into NENTSEL instead of ENTSEL.
-
Ill check it out..thanks
-
you're welcome.
Of course, you can also combine the methods so that if the user hits a block, it'll dig down and get the subent's layer - otherwise it'll just return the layer name.
ENTSEL returns the picked point, which NENTSELP can use to find a subent if need be:
(defun getLayer (/ ent entl ient layer)
(cond ((setq ent (entsel))
(setq entl (entget (car ent)))
(and (= "INSERT" (cdr (assoc 0 entl)))
(setq ient (nentselp (cadr ent)))
(setq entl (entget (car ient)))
)
)
)
(if (and entl (setq layer (cdr (assoc 8 entl))))
(princ layer)
)
(princ)
)
-
Here's an ActiveX method. could use some more testing
(defun return-vla-object (/ util-obj msg just-in-case vlaobj
pt-var tran objids)
(vl-load-com)
(setq util-obj (vla-get-utility
(vla-get-activedocument (vlax-get-acad-object))
)
)
(setq msg (vlax-make-variant "Select Object: "))
(setq just-in-case
(vl-catch-all-apply
'vlax-invoke-method
(list util-obj 'GetSubEntity 'vlaobj 'pt-var 'tran
'objids msg)
)
)
(if (not (vl-catch-all-error-p just-in-case))
vlaobj
)
)
-
its really cool to see different renditions...have to study both of these for a while....my brain overflowth :)
-
You'll need something like this to the layer name using my example.
(defun get-layer-name (/ obj layname)
(if (setq obj (return-vla-object))
(setq layname (vlax-get-property obj 'Layer)))
)
-
Thanks Stig, I'm borrowing another routine from you. :)
Did change it to return the layer name. OK?
;;; Returns layer of selected object
;;; nil if nothing selected
(defun c:getLayer (/ ent entl ient)
(cond ((setq ent (entsel "\nPick object to find layer."))
(setq entl (entget (car ent)))
(and (= "INSERT" (cdr (assoc 0 entl)))
(setq ient (nentselp (cadr ent)))
(setq entl (entget (car ient)))
)
(cdr (assoc 8 entl))
)
)
)
PS could you remove ient without harm?
-
Don't see why not, CAB .. I mean both the shortened version and replacing ient with ent should work fine.
-
The reason I asked is that using AND that way is still a little
new to me and I wasn't sure if there would be a case when
(setq ient (nentselp (cadr ent)))
might fail. Leaving it wouldn't hurt either, makes it more
readable to me. I guess I get on the "Condense Everything" kick
sometimes.
Not meaning to over analyze your code, but I have found subtleties
in you code that I missed on the first go around. So if my inquiries
get bothersome please tell me.
CAB
-
Oh, you were thinking of something like
(setq entl (entget (car (nentselp (cadr ent)))))
or even shorter? Nah, that's not a good idea, considering ENTSEL accepts the "Last" keyword and ENTGET will then have a fit.
Actually there is a hidden trap in that situation because ENTSEL will return '(0.0 0.0 0.0) if "Last" was issued, making NENTSELP search in that location and, in worst case, return a wrong entity!!
Anyway, there is no reason why ient shouldn't be replaced by ent - leaving out a single local var - but you have to verify the ename before trying to ENTGET it because it can fail (or you can catch errors with VL-CATCH.... but then it gets even longer)
Analyze away. It's only good to get some discussions instead of just tossing finished code around.
-
Oh, you were thinking of something like
(setq entl (entget (car (nentselp (cadr ent)))))
Exactly what I was thinking. :)
ENTSEL accepts the "Last" keyword
That one had not occured to me, I rarely use it, don't know why.
Glad you pointed out the pit falls though.
Anyway, there is no reason why ient shouldn't be replaced by ent
You mean recycleing the var like this.
(and (= "INSERT" (cdr (assoc 0 entl)))
(setq ent (nentselp (cadr ent)))
(setq entl (entget (car ent)))
)
verify the ename before trying to ENTGET it because it can fail
I'm Glad I asked.
CAB
-
Ahh, Mark :shock: What is that? ..."getsubentity"????!!! (where did that come from?!)
-
ActiveX
object.GetSubEntity Object, PickedPoint, TransMatrix, ContextData[, Prompt]