Is An Xref Nested

Is An Xref Nested

Jason.Piercey
Advisor Advisor
2,166 Views
34 Replies
Message 1 of 35

Is An Xref Nested

Jason.Piercey
Advisor
Advisor

I currently have a need for simply knowing if an xref is nested. Looking through my toolbox functions I have code for determining that based on user selection of a nested object (nentsel) but that doesn't fit my current requirements.  Hard to believe those functions were written some 23 years ago! Wow.

 

Anyway, it's been a long time since I've written much code so I'm a wee bit rusty.  Is testing for and/or using DXF code 102 enough for a nested determination?  Seems to work in my limited testing.

 

; determine if the specified block name is a nested xref
; Arguments:
; [document] vla-object, document object
; [name] string, xref name
; Return: T or nil
(defun nestedXref-p (document name / object)
  (and
    (setq object (vla-item (vla-get-blocks document) name))
    (= :vlax-true (vla-get-isxref object))
    (not (assoc 102 (entget (vlax-vla-object->ename object))))
    )
  )

 

0 Likes
Accepted solutions (1)
2,167 Views
34 Replies
Replies (34)
Message 2 of 35

paullimapa
Mentor
Mentor
Accepted solution

Not sure about that but I’ve referred to this link for nested Xref testing 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 35

Jason.Piercey
Advisor
Advisor

Thanks, I'll take a look at that link.

0 Likes
Message 4 of 35

komondormrex
Mentor
Mentor

i am pretty sure that link from message 2 suggests same method, but nevertheless why do not you try to check owner ID of xref in the first place?

0 Likes
Message 5 of 35

Jason.Piercey
Advisor
Advisor

I was looking at a dump (vlax-dump-object) of two different xrefs, one nested. I don't see how the OwnerID property helps in this case as the dump indicates that property is the same for both xrefs.

0 Likes
Message 6 of 35

komondormrex
Mentor
Mentor

well, that is very much peculiar, because if a block is nested, its owner has to be other that modelspace block for instance. 

0 Likes
Message 7 of 35

Jason.Piercey
Advisor
Advisor

I've found my attempt at using DXF 102 is not reliable. So, scratch that.

0 Likes
Message 8 of 35

komondormrex
Mentor
Mentor

could you attach a sample with xref nested and not? 

0 Likes
Message 9 of 35

Jason.Piercey
Advisor
Advisor

See attached for a simple example

0 Likes
Message 10 of 35

CADaSchtroumpf
Advisor
Advisor

Hi,
I have this that explores Block or Xref insertions and returns information if these are nested or single.

(defun xplore (l / ent cnt msg)
  (princ
    (strcat "\nExplores \"" (cdr (assoc 2 l)) "\" the block that is "
      (if (ssget "_X" (list '(0 . "INSERT") (assoc 2 l)))
        "inserted into the drawing."
        "not inserted into the drawing."
      )
    )
  )
  (setq ent (entget (cdr (assoc -2 l))) cnt 0)
  (cond
    ((eq (cdr (assoc 0 ent)) "INSERT")
      (princ (strcat "\n Contains the \"" (cdr (assoc 2 ent)) "\" block"))
      (while (setq ent (entnext (cdar ent)))
        (setq ent (entget ent))
        (if (eq (cdr (assoc 0 ent)) "INSERT")
          (progn
            (setq cnt (1+ cnt) msg "")
            (princ (strcat "\n Contains the \"" (cdr (assoc 2 ent)) "\" " (repeat cnt (setq msg (strcat "sub-" msg))) "block\n"))
          )
        )
      )
    )
  )
)
(defun c:list_blk_children ( / flag n_blk l_blk dxf_ent dxf_blk dxf)
  (setq flag T)
  (while (setq n_blk (tblnext "BLOCK" flag))
    (setq l_blk (cons n_blk l_blk) flag nil)
  )
  (cond
    (l_blk
      (foreach n l_blk
        (if (= (logand (cdr (assoc 70 n)) 4) 4)
          (progn
            (princ (strcat "\n\t\tXref found ---> \"" (cdr (assoc 1 n)) "\"\n"))
            (setq dxf_ent (entget (cdr (assoc 330 (entget (tblobjname "BLOCK" (cdr (assoc 2 n))))))))
            (if (setq dxf_blk (cdr (member '(102 . "{BLKREFS") dxf_ent)))
              (while (not (equal (car dxf_blk) '(102 . "}")))
                (setq dxf (entget (cdar dxf_blk)))
                (cond
                  ((eq (cdr (assoc 0 dxf)) "INSERT")
                    (princ (strcat "\n\t\twhich is a nested \"XREF\" named: \"" (cdr (assoc 2 dxf)) "\""))
                  )
                  ((eq (cdr (assoc 0 dxf)) "BLOCK_RECORD")
                    (princ (strcat "\n\t\twhich is a simple \"XREF\" named: \"" (cdr (assoc 2 dxf)) "\""))
                  )
                )
                (setq dxf_blk (cdr dxf_blk))
              )
            )
          )
          (if (/= (logand (cdr (assoc 70 n)) 16) 16)
            (xplore n)
          )
        )
        (textpage)
      )
    )
    (T
      (princ "\nNo block defined!")
    )
  )
  (prin1)
)
0 Likes
Message 11 of 35

paullimapa
Mentor
Mentor

what is the "l" argument to feed to function xplore?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 12 of 35

CADaSchtroumpf
Advisor
Advisor

@paullimapa  a écrit :

what is the "l" argument to feed to function xplore?


Is for exemple (xplore (tblsearch "BLOCK" "your_name block"))

In my code, I search all block with (tblnext "BLOCK") where I construct a list and (foreach el  list  I use xplore  for each element

 

0 Likes
Message 13 of 35

paullimapa
Mentor
Mentor

not working for me...with MASTER.dwg opened, I load xplore and enter:

(xplore (tblsearch "BLOCK" "your_name block")) in my case it's XREF_B or XREF_A I get:

paullimapa_0-1682445707823.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 14 of 35

paullimapa
Mentor
Mentor

Oh, and I just ran the list_blk_children command and I got the reverse answer:

paullimapa_0-1682445941204.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 15 of 35

CADaSchtroumpf
Advisor
Advisor

For me work's in MASTER.dwg


Commande: LIST_BLK_CHILDREN

Xref found ---> "C:\Autodesk\XREF_B.dwg"

Xref found ---> "C:\Autodesk\XREF_A.dwg"

which is a nested "XREF" named: "XREF_A"
which is a simple "XREF" named: "XREF_B"

 


(xplore) is for only ""INSERT" -> block not XRef

Block can be have other block nested

Exemple with this dwg

0 Likes
Message 16 of 35

paullimapa
Mentor
Mentor

ok, but should it not show that:

"

XREF_A" is the simple xref 

"XREF_B" is the nested one instead of showing it like this?

Commande: LIST_BLK_CHILDREN

Xref found ---> "C:\Autodesk\XREF_B.dwg"

Xref found ---> "C:\Autodesk\XREF_A.dwg"

which is a nested "XREF" named: "XREF_A"
which is a simple "XREF" named: "XREF_B"

paullimapa_0-1682446649303.png

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 17 of 35

komondormrex
Mentor
Mentor

I don't see how the OwnerID property helps in this case as the dump indicates that property is the same for both xrefs.

truly it is the same for block-xref definition and points to blocks collection. this may differ for block references. but in your example you have only one xref as block reference and it is 'not nested'. at the same time references palette shows two xrefs of which the second is 'nested' and it nested in 'not nested' xref. in that particular scenario nested xref may be found by nil ssgetting block reference named 'nested'. if ssget gives nil result, but block definition of 'nested' block is in database then it is obviously nested.

0 Likes
Message 18 of 35

ronjonp
Mentor
Mentor

@komondormrex About the SSGET method read HERE from the link above.

0 Likes
Message 19 of 35

komondormrex
Mentor
Mentor

well, thank you. it is function btw)

 

komondormrex_0-1682520477576.pngkomondormrex_1-1682520524294.png

 

0 Likes
Message 20 of 35

ronjonp
Mentor
Mentor

@komondormrex wrote:

well, thank you. it is function btw)


Yes, I know SSGET is a function. I was referring to your method🤓

 

See below in green .. that was what I was referring to:

ronjonp_0-1682520710874.png

 

0 Likes