Author Topic: nested ename list  (Read 7759 times)

0 Members and 1 Guest are viewing this topic.

Joe Burke

  • Guest
nested ename list
« on: October 07, 2008, 08:49:26 AM »
I've been banging my head on this.

(setq elst (nentsel "\nSelect nested object: "))
(setq nestlst (last elst))

Can nestlst be determined without using nentsel or nentselp?
IOW, a function which takes a nested ename argument and returns
the same list as nestlst.

My research on this question has not turned up a solution so far.
My attempts to code it looking at DXF codes 330 and 331 have failed.

TIA for any help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: nested ename list
« Reply #1 on: October 07, 2008, 10:58:47 AM »
In ACAD2000
Code: [Select]
_$ (setq elst (nentsel "\nSelect nested object: "))
(setq nestlst (last elst))
(<Entity name: 1c9ae10> (792.505 94.0832 0.0) ((1.0 0.0 0.0) (0.0 1.0 0.0) (0.0 0.0 1.0) (777.399 89.6897 0.0)) (<Entity name: 1c9ae40>))
(<Entity name: 1c9ae40>)

_$ (setq e1 (car elst))
<Entity name: 1c9ae10>
_$ (setq el1 (entget e1))
((-1 . <Entity name: 1c9ae10>) (0 . "LINE") (330 . <Entity name: 1c9ad90>) (5 . "A1A2") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbLine") (39 . -0.76) (10 17.2207 3.86134 0.0) (11 13.0833 5.78647 0.0) (210 0.0 0.0 1.0))
_$ (setq e2 (cdr (assoc 330 el1)))
<Entity name: 1c9ad90>
_$ (setq el2 (entget e2))
((-1 . <Entity name: 1c9ad90>) (0 . "BLOCK_RECORD") (330 . <Entity name: 1c89008>) (5 . "A192") (100 . "AcDbSymbolTableRecord") (100 . "AcDbBlockTableRecord") (2 . "blk1") (360 . <Entity name: 1c9ad98>) (340 . <Entity name: 0>) (310 . "2800000020000000200000000100080000000000000400000000000000000000000000000000000000000000000080000080000000808000800000008000800080800000C0C0C000C0DCC000F0CAA6000020400000206000002080000020A0000020C0000020E00000400000004020000040400000406000004080000040A0") (310 . "000040C0000040E00000600000006020000060400000606000006080000060A0000060C0000060E00000800000008020000080400000806000008080000080A0000080C0000080E00000A0000000A0200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0200000C0400000C0600000C0800000C0") (310 . "A00000C0C00000C0E00000E0000000E0200000E0400000E0600000E0800000E0A00000E0C00000E0E00040000000400020004000400040006000400080004000A0004000C0004000E00040200000402020004020400040206000402080004020A0004020C0004020E000404000004040200040404000404060004040800040") (310 . "40A0004040C0004040E00040600000406020004060400040606000406080004060A0004060C0004060E00040800000408020004080400040806000408080004080A0004080C0004080E00040A0000040A0200040A0400040A0600040A0800040A0A00040A0C00040A0E00040C0000040C0200040C0400040C0600040C08000") (310 . "40C0A00040C0C00040C0E00040E0000040E0200040E0400040E0600040E0800040E0A00040E0C00040E0E00080000000800020008000400080006000800080008000A0008000C0008000E00080200000802020008020400080206000802080008020A0008020C0008020E00080400000804020008040400080406000804080") (310 . "008040A0008040C0008040E00080600000806020008060400080606000806080008060A0008060C0008060E00080800000808020008080400080806000808080008080A0008080C0008080E00080A0000080A0200080A0400080A0600080A0800080A0A00080A0C00080A0E00080C0000080C0200080C0400080C0600080C0") (310 . "800080C0A00080C0C00080C0E00080E0000080E0200080E0400080E0600080E0800080E0A00080E0C00080E0E000C0000000C0002000C0004000C0006000C0008000C000A000C000C000C000E000C0200000C0202000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C0402000C0404000C0406000C0") (310 . "408000C040A000C040C000C040E000C0600000C0602000C0604000C0606000C0608000C060A000C060C000C060E000C0800000C0802000C0804000C0806000C0808000C080A000C080C000C080E000C0A00000C0A02000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C02000C0C04000C0C06000") (310 . "C0C08000C0C0A000F0FBFF00A4A0A000808080000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFFFFFF00000000000000000000000000000000000000000000000000000000FF") (310 . "FFFFFF00000000000000000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000FFFF00000000000000FFFFFFFF00000000000000FFFF00000000000000000000FFFF00000000000000") (310 . "0000FFFF00000000000000FFFF00000000000000000000FFFF00000000000000FFFF000000000000000000FFFF00000000000000000000FFFF000000000000000000FFFF00000000000000FFFF00000000000000000000FFFF0000000000000000FFFF0000000000000000FFFF00000000000000000000FFFFFFFFFFFFFFFF") (310 . "FFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000FFFFFF0000000000FF00FFFF00FF000000000000FFFF00000000000000000000FFFFFF0000000000FFFFFFFFFFFF000000000000FFFF00000000000000000000FFFFFF0000000000FFFFFFFF00FF000000000000FFFF00000000000000000000FFFFFF00000000") (310 . "00FF00FFFFFFFF000000000000FFFF00000000000000000000FFFFFF0000000000FFFFFFFF00FF000000000000FFFF00000000000000000000FFFFFF0000000000FFFFFFFFFFFF000000000000FFFF00000000000000000000FFFFFF0000000000FFFF0000FFFF000000000000FFFF00000000000000000000FFFFFF000000") (310 . "0000FFFF0000FFFF000000000000FFFF00000000000000000000FFFFFF0000000000FFFF0000FFFF000000000000FFFF00000000000000000000FFFFFF0000000000FFFF0000FFFF000000000000FFFF00000000000000000000FFFFFF0000000000FFFF0000FFFF000000000000FFFF00000000000000000000FFFFFF0000") (310 . "000000FFFF0000FFFF000000000000FFFF00000000000000000000FFFFFFFFFFFFFFFFFFFF0000FFFFFFFFFFFFFFFFFFFF00000000000000000000FFFF00000000000000FF0000FF00000000000000FFFF00000000000000000000FFFF00000000000000FF0000FF00000000000000FFFF00000000000000000000FFFF0000") (310 . "0000000000FF0000FF00000000000000FFFF00000000000000000000FFFF00000000000000FF0000FF00000000000000FFFF00000000000000000000FFFF00000000000000FFFFFFFF00000000000000FFFF00000000000000000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000FFFFFF") (310 . "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF00000000000000000000000000000000000000000000000000000000000000000000000000") (102 . "{BLKREFS") (331 . <Entity name: 1c9ae40>) (102 . "}"))
_$ (assoc 331 el2)
(331 . <Entity name: 1c9ae40>)
_$
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: nested ename list
« Reply #2 on: October 07, 2008, 11:16:23 AM »
I don't think there is an easy way, and the way that comes to mind isn't the most secure.  If you could pass the ename and a point, then you can kind of search for it, but if blocks are on top of each other, then you could come up with the wrong block.  I was thinking that you could search each block reference of the block table record, and see if the point falls within the bounding box of the block, then that will tell you which insert you want.

I don't see how a nested ename is associated with the insert, only the block definition, so that is why I'm thinking this way.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: nested ename list
« Reply #3 on: October 07, 2008, 11:39:39 AM »
Doesn't dxf 331 point to the INSERT?
Or am I missing something here?  :? <wouldn't be the first time> 8-)
Code: [Select]
Select entity to list.((-1 . <Entity name: 1c9ae40>) (0 . "INSERT") (330 .
<Entity name: 1c89010>) (5 . "A1A8") (100 . "AcDbEntity") (67 . 0) (410 .
"Model") (8 . "Duct") (100 . "AcDbBlockReference") (2 . "blk1") (10 777.399
89.6897 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44
. 0.0) (45 . 0.0) (210 0.0 0.0 1.0))
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: nested ename list
« Reply #4 on: October 07, 2008, 12:04:10 PM »
In '06 there is no 331 of the nested entity.  The code 331 is with the block record, and that will lead you to inserts, but if you select a line within the insert, and then test the dxf codes returned, there isn't a 331, at least not on my test.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: nested ename list
« Reply #5 on: October 07, 2008, 01:34:59 PM »
Here's a quick stab that appears  to work under '08:

Code: [Select]
(defun GetGuardians ( ename / foo result )

    (defun foo ( ename / data owner )
        ;;  variable result is a lexical global
        (if (eq "BLOCK_RECORD" (cdr (assoc 0 (setq data (entget ename)))))
            (if (setq owner (cdr (assoc 331 (reverse data))))
                (foo owner)
                (setq result (cons (cdr (assoc 360 data)) result))
            )
            (if (setq result (cons ename result))
                (foo (cdr (assoc 330 data)))
            )
        )
    )

    (foo ename)

    (cdr (reverse (cdr result)))

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: nested ename list
« Reply #6 on: October 07, 2008, 01:47:57 PM »
Here's a quick stab that appears  to work under '08:

Code: [Select]
(defun GetGuardians ( ename / foo result )

    (defun foo ( ename / data owner )
        ;;  variable result is a lexical global
        (if (eq "BLOCK_RECORD" (cdr (assoc 0 (setq data (entget ename)))))
            (if (setq owner (cdr (assoc 331 (reverse data))))
                (foo owner)
                (setq result (cons (cdr (assoc 360 data)) result))
            )
            (if (setq result (cons ename result))
                (foo (cdr (assoc 330 data)))
            )
        )
    )

    (foo ename)

    (cdr (reverse (cdr result)))

)
Try this with copying the block many times, and selecting different blocks.  It will always return the last one in the list of block references.
Quote
Command: (getguardians (car (nentsel)))

Select object: (<Entity name: 7ed2d2b0>)

Command: (getguardians (car (nentsel)))

Select object: (<Entity name: 7ed2d2b0>)

Command: (getguardians (car (nentsel)))

Select object: (<Entity name: 7ed2d2b0>)

Command: (getguardians (car (nentsel)))

Select object: (<Entity name: 7ed2d2b0>)

Quote
(-1 . <Entity name: 7ed2d098>)
(0 . "BLOCK_RECORD")
(330 . <Entity name: 7ed10c08>)
(5 . "C3")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbBlockTableRecord")
(2 . "Det-Bub")
(360 . <Entity name: 7ed2d0c0>)
(340 . <Entity name: 0>)
(102 . "{BLKREFS")
(331 . <Entity name: 7ed2d0f0>)
(331 . <Entity name: 7ed2d130>)
(331 . <Entity name: 7ed2d150>)
(331 . <Entity name: 7ed2d170>)
(331 . <Entity name: 7ed2d190>)
(331 . <Entity name: 7ed2d1b0>)
(331 . <Entity name: 7ed2d1d0>)
(331 . <Entity name: 7ed2d1f0>)
(331 . <Entity name: 7ed2d210>)
(331 . <Entity name: 7ed2d230>)
(331 . <Entity name: 7ed2d250>)
(331 . <Entity name: 7ed2d270>)
(331 . <Entity name: 7ed2d290>)
(331 . <Entity name: 7ed2d2b0>)
(102 . "}")
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: nested ename list
« Reply #7 on: October 07, 2008, 01:57:58 PM »
Oh well. Conceptually it may contribute towards a solution. Or not. I unfortunately don't have time to play. I know you folks will pen a solid solution and I look forward to seeing it. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

T.Willey

  • Needs a day job
  • Posts: 5251
Re: nested ename list
« Reply #8 on: October 07, 2008, 02:13:19 PM »
Oh well. Conceptually it may contribute towards a solution. Or not. I unfortunately don't have time to play. I know you folks will pen a solid solution and I look forward to seeing it. :)
I don't think I will unless an epiphanyhits me with some new knowledge.  The nested ename will only lead you to what owns it, and that is the block record.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: nested ename list
« Reply #9 on: October 07, 2008, 02:55:21 PM »
I'm scratching my head on this one so help me out.
This works in 2006 as well as 2000.
Is it not returning the correct entity?
Or have I missed the question entirely?  :-o
Code: [Select]
(defun GetInsert (ent / e1 e2 e3 el2)
  (and
  (setq e1 (entget ent))
  (setq e2 (cdr (assoc 330 e1)))
  (setq el2 (entget e2))
  (setq e3 (cdr (assoc 331 el2)))
  )
  e3
  )

(defun c:test(/ e)
  (setq e (car (nentselp)))
  (GetInsert e)
)
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: nested ename list
« Reply #10 on: October 07, 2008, 03:07:04 PM »
I'm scratching my head on this one so help me out.
This works in 2006 as well as 2000.
Is it not returning the correct entity?
Or have I missed the question entirely?  :-o
Code: [Select]
(defun GetInsert (ent / e1 e2 e3 el2)
  (and
  (setq e1 (entget ent))
  (setq e2 (cdr (assoc 330 e1)))
  (setq el2 (entget e2))
  (setq e3 (cdr (assoc 331 el2)))
  )
  e3
  )

(defun c:test(/ e)
  (setq e (car (nentselp)))
  (GetInsert e)
)
Same as Michaels, except that you get the first instead of the last.

Quote
Command: TEST

Select object: <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select object: <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select object: <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select object: <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select object: <Entity name: 7ed2d0e0>

Quote
(-1 . <Entity name: 7ed2d088>)
(0 . "BLOCK_RECORD")
(330 . <Entity name: 7ed10c08>)
(5 . "C1")
(100 . "AcDbSymbolTableRecord")
(100 . "AcDbBlockTableRecord")
(2 . "Det-Bub")
(360 . <Entity name: 7ed2d0b0>)
(340 . <Entity name: 0>)
(102 . "{BLKREFS")
(331 . <Entity name: 7ed2d0e0>)
(331 . <Entity name: 7ed2d100>)
(331 . <Entity name: 7ed2d120>)
(331 . <Entity name: 7ed2d140>)
(331 . <Entity name: 7ed2d160>)
(331 . <Entity name: 7ed2d180>)
(331 . <Entity name: 7ed2d1a0>)
(331 . <Entity name: 7ed2d1c0>)
(331 . <Entity name: 7ed2d1e0>)
(331 . <Entity name: 7ed2d200>)
(331 . <Entity name: 7ed2d220>)
(331 . <Entity name: 7ed2d240>)
(331 . <Entity name: 7ed2d260>)
(331 . <Entity name: 7ed2d280>)
(331 . <Entity name: 7ed2d2a0>)
(331 . <Entity name: 7ed2d2c0>)
(102 . "}")
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: nested ename list
« Reply #11 on: October 07, 2008, 03:18:01 PM »
Added some reporting to the test function.
Code: [Select]
(defun GetInsert (ent / e1 e2 e3 el2)
  (and
    (setq e1 (entget ent))
    (setq e2 (cdr (assoc 330 e1)))
    (setq el2 (entget e2))
    (setq e3 (cdr (assoc 331 el2)))
  )
  e3
)

(defun c:test (/ e)
  (setq nlist (nentselp "\nSelect nested object: "))
  (setq e (car nlist))
  (print "Nested entity : ")
  (princ e)
  (print "Insert entity : ")
  (princ (last nlist))
  (print "Start subfunction--------")
  (print "Insert entity found : ")
  (princ (GetInsert e))
  (princ)
)
This is my result in acad2006, what is yours?
Code: [Select]
Select nested object:
"Nested entity : " <Entity name: 7ef7e218>
"Insert entity : " (<Entity name: 7ef7e240>)
"Start subfunction--------"
"Insert entity found : " <Entity name: 7ef7e240>
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: nested ename list
« Reply #12 on: October 07, 2008, 03:20:50 PM »
You will notice that the last one is correct, but all the rest are wrong.  I have inserted the object ~10 times, which will be a better test for you next time.

Quote
Command: test

Select nested object:
"Nested entity : " <Entity name: 7ed2d0a8>
"Insert entity : " (<Entity name: 7ed2d200>)
"Start subfunction--------"
"Insert entity found : " <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select nested object:
"Nested entity : " <Entity name: 7ed2d0a8>
"Insert entity : " (<Entity name: 7ed2d1e0>)
"Start subfunction--------"
"Insert entity found : " <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select nested object:
"Nested entity : " <Entity name: 7ed2d0a8>
"Insert entity : " (<Entity name: 7ed2d1c0>)
"Start subfunction--------"
"Insert entity found : " <Entity name: 7ed2d0e0>

Command:
Command:
TEST
Select nested object:
"Nested entity : " <Entity name: 7ed2d0a8>
"Insert entity : " (<Entity name: 7ed2d0e0>)
"Start subfunction--------"
"Insert entity found : " <Entity name: 7ed2d0e0>
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: nested ename list
« Reply #13 on: October 07, 2008, 03:26:45 PM »
I forgot to ask ... what's wrong with nentselp?
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: nested ename list
« Reply #14 on: October 07, 2008, 03:50:15 PM »
Hi,

My 2 cents, if I do understand the request (not deeply tested).

Code: [Select]
(defun nested-list (child / parent)
  (if (setq
parent (cdr (last (vl-remove-if-not
    '(lambda (p) (= (car p) 331))
    (entget (cdr (assoc 330 (entget child))))
  )
    )
       )
      )
    (cons child (nested-list parent))
    (list child)
  )
)
Speaking English as a French Frog