Author Topic: xref'd layer name  (Read 7783 times)

0 Members and 1 Guest are viewing this topic.

rude dog

  • Guest
xref'd layer name
« 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? :?:

SMadsen

  • Guest
xref'd layer name
« Reply #1 on: February 18, 2004, 09:59:07 AM »
?? Can you give an example?

rude dog

  • Guest
xref'd layer name
« Reply #2 on: February 18, 2004, 10:24:35 AM »
(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]

SMadsen

  • Guest
xref'd layer name
« Reply #3 on: February 18, 2004, 10:30:16 AM »
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.

rude dog

  • Guest
xref'd layer name
« Reply #4 on: February 18, 2004, 10:35:09 AM »
Ill check it out..thanks

SMadsen

  • Guest
xref'd layer name
« Reply #5 on: February 18, 2004, 10:53:48 AM »
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:

Code: [Select]
(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)
)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
xref'd layer name
« Reply #6 on: February 18, 2004, 11:30:46 AM »
Here's an ActiveX method. could use some more testing
Code: [Select]

(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
    )
  )
TheSwamp.org  (serving the CAD community since 2003)

rude dog

  • Guest
xref'd layer name
« Reply #7 on: February 18, 2004, 11:48:07 AM »
its really cool to see different renditions...have to study both of these for a while....my brain overflowth :)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
xref'd layer name
« Reply #8 on: February 18, 2004, 12:12:38 PM »
You'll need something like this to the layer name using my example.
Code: [Select]

(defun get-layer-name (/ obj layname)
  (if (setq obj (return-vla-object))
    (setq layname (vlax-get-property obj 'Layer)))
  )
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
xref'd layer name
« Reply #9 on: February 18, 2004, 12:35:29 PM »
Thanks Stig, I'm borrowing another  routine from you. :)

Did change it to return the layer name. OK?

Code: [Select]
;;; 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?
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.

SMadsen

  • Guest
xref'd layer name
« Reply #10 on: February 18, 2004, 01:08:05 PM »
Don't see why not, CAB .. I mean both the shortened version and replacing ient with ent should work fine.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
xref'd layer name
« Reply #11 on: February 18, 2004, 02:09:30 PM »
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
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.

SMadsen

  • Guest
xref'd layer name
« Reply #12 on: February 18, 2004, 02:43:42 PM »
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
xref'd layer name
« Reply #13 on: February 18, 2004, 03:15:20 PM »
Quote from: SMadsen
Oh, you were thinking of something like

(setq entl (entget (car (nentselp (cadr ent)))))


Exactly what I was thinking. :)



Quote
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.

Quote
Anyway, there is no reason why ient shouldn't be replaced by ent



You mean recycleing the var like this.

Code: [Select]
        (and (= "INSERT" (cdr (assoc 0 entl)))
              (setq ent (nentselp (cadr ent)))
              (setq entl (entget (car ent)))
         )


Quote
verify the ename before trying to ENTGET it because it can fail


I'm Glad I asked.


CAB
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.

JohnK

  • Administrator
  • Seagull
  • Posts: 10625
xref'd layer name
« Reply #14 on: February 18, 2004, 07:05:15 PM »
Ahh, Mark :shock: What is that? ..."getsubentity"????!!! (where did that come from?!)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org