Author Topic: Nested Xref Counter in Tree Format  (Read 14186 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Nested Xref Counter in Tree Format
« on: December 09, 2011, 11:06:54 AM »
Need help with modifing Tim Willey's code to add a xref counter for each nested xref and print it in a tree format as per his code.

Code can be found here:
http://www.theswamp.org/index.php?topic=34277.msg409437#msg409437

Need to list all xrefs named "BL*" found with model space of the opened drawing:
Then list and count all nested xrefs named "UT*" within each of the xrefs listed above:

Example of text screen:
Code: [Select]
Main xref: BL-02b
  |- Nested xref: UT-B2a_985hc
  |- Nested xref: UT-B2b_985
  |- Nested xref: UT-B2c_985
  |- Nested xref: UT-B2d_985
 Main xref: BL-04
  |- Nested xref: UT-A1a_760hc
  |- Nested xref: UT-A1b_760
  |- Nested xref: UT-A1c_760
  |- Nested xref: UT-A1d_760
  |- Nested xref: UT-A2a_760
  |- Nested xref: UT-A2b_760
  |- Nested xref: UT-A2c_760
  |- Nested xref: UT-A2d_760
  |- Nested xref: UT-B1b_985
  |- Nested xref: UT-B1c_985
  |- Nested xref: UT-B1d_985
  |- Nested xref: UT-B3a_985
  |- Nested xref: UT-B3b_985
  |- Nested xref: UT-B3c_985
  |- Nested xref: UT-B3d_985
  |- Nested xref: UTB-GAR
« Last Edit: December 12, 2011, 10:55:31 PM by GDF »
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #1 on: December 09, 2011, 01:27:09 PM »
Not tested, but try something like this way :
EDIT: Code tested
Code: [Select]
(defun c:PrintXrefNesting ( / mainfilter filter )
    ; Prints nested xref tree to command line, no matter how deep the nesting.
    (setq mainfilter (getstring T "\nInput prefix filter for Main Xrefs : "))
    (setq filter (getstring T "\nInput prefix filter for Nested Xrefs : "))

    (defun FilterNestedXrefs ( lst mainfilter filter / ifillst inewlst newlst )
        (foreach i lst
            (if (and (atom (car i)) (wcmatch (strcase (cdr (assoc 2 (entget (car i))))) (strcase mainfilter)))
                  (progn
                       (if (listp (cdr i))
    (progn
          (setq ifillst (filternested (cdr i) filter))
                                  (setq inewlst (cons (car i) ifillst))
                  (setq newlst (cons inewlst newlst))
    )
    (setq newlst (cons i newlst))
                       )
                  )
             )
        )
        (reverse newlst)
    )

    (defun filternested ( lst filter / newlst ii )
        (foreach i lst
    (setq ii i)
            (if (and (atom (car i)) (wcmatch (strcase (cdr (assoc 2 (entget (car i))))) (strcase filter))) () (setq ii nil))
            (cond     ((listp (cdr i)) (filternested (cdr i) filter))
                ((and (atom (cdr i)) (wcmatch (strcase (cdr (assoc 2 (entget (cdr i))))) (strcase filter))) () (setq ii nil))
              ((eq (cdr i) nil) nil)
            )
            (setq newlst (cons ii newlst))
        )
        (reverse newlst)
    )

    (defun GetXrefNesting (/ tempData tempEnt XrefList NonNestedXrefList NestedXrefList )
       
        (defun GetXrefInfo ( ent / NestList )
            (foreach i (member '(102 . "{BLKREFS") (entget ent))
                (if (equal (car i) 332)
                    (progn
                        (setq NestedList (cons (cdr i) NestedList))
                        (setq NestList
                            (cons
                                (cons
                                    (cdr i)
                                    (GetXrefInfo (cdr i))
                                )
                                NestList
                            )
                        )
                    )
                )
            )
            NestList
        )
        ;-------------------------------------
       
        (while (setq tempData (tblnext "block" (not tempData)))
            (if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
                (progn
                    (setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
                    (setq tempEnt (cdr (assoc 330 (entget tempEnt))))
                    (setq XrefList
                        (cons
                            (cons
                                tempEnt
                                (GetXrefInfo tempEnt)
                            )
                            XrefList
                        )
                    )
                )
            )
        )
        (foreach i XrefList
            (if (not (member (car i) NestedList))
                (setq NonNestedXrefList (cons i NonNestedXrefList))
            )
        )
        NonNestedXrefList
    )
    ;------------------------------------------------
    (defun PrintNestedList ( lst spc )
        (foreach
            i
            (vl-sort
                lst
                (function
                    (lambda ( a b )
                        (<
                            (strcase (cdr (assoc 2 (entget (car a)))))
                            (strcase (cdr (assoc 2 (entget (car b)))))
                        )
                    )
                )
            )
            (if (and (not (listp (car i))) (car i)) (prompt (strcat "\n" spc " Nested xref: " (cdr (assoc 2 (entget (car i)))))) (prompt (strcat "\n" spc " Nested xref: nil" )) )
            (PrintNestedList (if (cdr i) (cdr i) nil) (strcat "  " spc))
            ;(PrintNestedList (cdr i) (strcat "  |" spc)) [color=red]; second option shown below[/color]
        )
    )
    ;-----------------------------------------------------
   
    (foreach
        i
        (vl-sort
            (FilterNestedXrefs (GetXrefNesting) mainfilter filter)
            (function
                (lambda ( a b )
                    (<
                        (strcase (cdr (assoc 2 (entget (car a)))))
                        (strcase (cdr (assoc 2 (entget (car b)))))
                    )
                )
            )
        )
        (prompt (strcat "\n Main xref: " (cdr (assoc 2 (entget (car i)))) " - " (itoa (sslength (ssget "_X" (list '(0 . "INSERT") (assoc 2 (entget (car i))) (cons 410 (getvar 'ctab)))))) ))
        (PrintNestedList (if (and (/= (cadr i) nil) (cdr i)) (vl-remove nil (cdr i)) nil) "  |-")
    )
    (princ)
)

M.R.
« Last Edit: December 12, 2011, 08:50:42 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #2 on: December 09, 2011, 02:35:24 PM »
Thanks Marko. I get nil when entering the filters from your code.
The filters are not really needed, but would be nice to have.

My main question was how to add a counter for the total number for each xref and nested xref found.
Something like:
(defun C:UTC (/ ent_count)
  (setq ent_count (sslength (ssget "a" '((2 . "*UT*")(8 . "0-XREF")))))
  (alert (strcat (rtos ent_count 2 0) " Total Units"))
  (princ)
)
(defun C:BLC (/ ent_count)
  (setq ent_count (sslength (ssget "a" '((2 . "*BL*")(8 . "0-XREF")))))
  (alert (strcat (rtos ent_count 2 0) " Total Buildings"))
  (princ)
)

But in Tim's tree format code. for example:

[1]  Main xref: BL-01a                         
  [2]  |- Nested xref: UT-A1a_760hc
  [4]  |- Nested xref: UT-A1b_760
  [1]  | - Nested xref: UT-A1c_760

  ...and so on.
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #3 on: December 09, 2011, 04:37:28 PM »
;;;http://www.theswamp.org/index.php?topic=28062.msg337119#msg337119
;;;Tim Willey

In this example the main xref is counted...I want to also count the nested xrefs within the list.
So how do I modify the code below to count all xrefs, main and nested?

Code: [Select]
(defun c:test ()

(defun GetXrefs (/ tempData tempEnt XrefList)   
    (while (setq tempData (tblnext "block" (not tempData)))
        (if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
            (progn
                (setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
                (setq tempData (entget (cdr (assoc 330 (entget tempEnt)))))
                (setq XrefList
                    (cons
                        (cons
                            tempEnt
                            (
                                (lambda ( x / InsList NestList )
                                    (foreach i x
                                        (cond
                                            ((equal (car i) 331)
                                                (setq InsList (cons (cdr i) InsList))
                                            )
                                            ((equal (car i) 332)
                                                (setq NestList (cons (cdr i) NestList))
                                            )
                                        )
                                    )
                                    (list InsList NestList)
                                )
                                (member '(102 . "{BLKREFS") tempData)
                            )
                        )
                        XrefList
                    )
                )
            )
        )
    )
    XrefList
)

(foreach i (GetXrefs)
        (princ "\nXref name: ")
        (princ (cdr (assoc 2 (entget (car i)))))
        (princ "\n    Inserted amount: ")
        (princ (itoa (length (cadr i))))
        (if (caddr i)
            (progn
                (princ "\n    Nested xref names: ")
                (foreach j (caddr i)
                    (princ "\n        ")
                    (princ (cdr (assoc 2 (entget j))))
                )
            )
        )
        (princ "\n")
    )

)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Nested Xref Counter in Tree Format
« Reply #4 on: December 09, 2011, 04:47:41 PM »
Perhaps add this?

    (if   (caddr i)
      (progn (princ "\n    Nested xref names: ")
        (princ "\n    Inserted amount: ")
        (princ (itoa (length (caddr i))))

        (foreach j (caddr i) (princ "\n        ") (princ (cdr (assoc 2 (entget j)))))
      )
    )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #5 on: December 09, 2011, 04:57:58 PM »
You should try to incorporate counter into main code - I've modified it and checked and now filters work...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #6 on: December 09, 2011, 05:00:56 PM »
Thanks Ron
Xref name: BL-03a
    Inserted amount: 1
    Nested xref names:
    Inserted amount: 6
        UT-C1a_1331hc
        UTB-Gar2
        UT-C2b_1331
        UT-C1c_1331
        UT-C1b_1331
        UT-C1d_1331

Xref name: BL-04a
    Inserted amount: 1
    Nested xref names:
    Inserted amount: 16
        UT-A1a_760hc
        UT-B3d_985
        UT-B3c_985
        UT-B3b_985
        UT-B3a_985
        UT-B1c_985
        UT-B1b_985
        UT-B1d_985
        UT-A2c_760
        UT-A2b_760
        UT-A2d_760
        UT-A1d_760
        UT-A1c_760
        UT-A1b_760
        UT-A2a_760
        UTB-GAR
"\n"


But what I am looking for is the number for each individual unique nested xref.

For example "UT-A2d_760" maybe xrefed in 5 times and "UTB-GAR" only 2 times.




Xref name: BL-04a
    Inserted amount: 1
    Nested xref names:
    Inserted amount: 16  <--not needed
        UT-A1a_760hc  <--want count here
        UT-B3d_985   <--want count here
        UT-B3c_985   <--want count here

   
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #7 on: December 09, 2011, 05:23:18 PM »
You should try to incorporate counter into main code - I've modified it and checked and now filters work...

M.R.

Thanks
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #8 on: December 09, 2011, 09:31:42 PM »
We often load multiple copies of the same nested "unit plan" xrefs within the main "building plan" xref...therfore I need a count of how many times the "unit plans" are copied.

I hope this understandable:

Xref name: BL-04a
    Inserted amount: 1
    Nested xref names:
    Inserted amount: 16  <--not needed...this is the total of how many of unique files ther are
        UT-A1a_760hc  <--want count here...of total times the xrefs are copied
        UT-B3d_985   <--want count here...of total times the xrefs are copied
        UT-B3c_985   <--want count here...of total times the xrefs are copied

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #9 on: December 10, 2011, 08:27:27 AM »
For main Xrefs, its easy to find number of insertions, but for nested I still don't know how... I've updated  code with filtering xrefs to include number of main Xrefs ( I added - no. after prompting its name)...
If only there is a way to check for (ssget "_X" '((0 . "INSERT") (2 . "nested xref name") (410 . "Model"))) inside of each main xref without opening it...??? :|

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3225
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #10 on: December 10, 2011, 11:14:08 AM »
I've figured out... Only thing is that you'll have to multiply manually with number of parent xref, all to top most level - main xref to get total numbers of child nested xref... This number shows how many nested xrefs are per 1 parent xref... So here is code :

Code: [Select]
(defun c:PrintXrefNesting ( / mainfilter filter )
    ; Prints nested xref tree to command line, no matter how deep the nesting.
    (setq mainfilter (getstring T "\nInput prefix filter for Main Xrefs : "))
    (setq filter (getstring T "\nInput prefix filter for Nested Xrefs : "))

      (defun nestedxrefcount ( mainname nestedname / bl item n )
        (setq bl (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
        (vlax-for item bl
          (if (= (vla-get-name item) mainname)
            (progn   
              (setq n 0) 
              (vlax-for xr item
              (if (= (vl-catch-all-apply 'vla-get-EffectiveName (list xr)) nestedname) (setq n (1+ n)))
            )
          )
        )
      )
      n
    )

    (defun FilterNestedXrefs ( lst mainfilter filter / ifillst inewlst newlst )
        (foreach i lst
            (if (and (atom (car i)) (wcmatch (strcase (cdr (assoc 2 (entget (car i))))) (strcase mainfilter)))
                  (progn
                       (if (listp (cdr i))
    (progn
          (setq ifillst (filternested (cdr i) filter))
                                  (setq inewlst (cons (car i) ifillst))
                  (setq newlst (cons inewlst newlst))
    )
    (setq newlst (cons i newlst))
                       )
                  )
             )
        )
        (reverse newlst)
    )

    (defun filternested ( lst filter / newlst ii )
        (foreach i lst
    (setq ii i)
            (if (and (atom (car i)) (wcmatch (strcase (cdr (assoc 2 (entget (car i))))) (strcase filter))) () (setq ii nil))
            (cond     ((listp (cdr i)) (filternested (cdr i) filter))
                ((and (atom (cdr i)) (wcmatch (strcase (cdr (assoc 2 (entget (cdr i))))) (strcase filter))) () (setq ii nil))
              ((eq (cdr i) nil) nil)
            )
            (setq newlst (cons ii newlst))
        )
        (reverse newlst)
    )

    (defun GetXrefNesting (/ tempData tempEnt XrefList NonNestedXrefList NestedXrefList )
       
        (defun GetXrefInfo ( ent / NestList )
            (foreach i (member '(102 . "{BLKREFS") (entget ent))
                (if (equal (car i) 332)
                    (progn
                        (setq NestedList (cons (cdr i) NestedList))
                        (setq NestList
                            (cons
                                (cons
                                    (cdr i)
                                    (GetXrefInfo (cdr i))
                                )
                                NestList
                            )
                        )
                    )
                )
            )
            NestList
        )
        ;-------------------------------------
       
        (while (setq tempData (tblnext "block" (not tempData)))
            (if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
                (progn
                    (setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
                    (setq tempEnt (cdr (assoc 330 (entget tempEnt))))
                    (setq XrefList
                        (cons
                            (cons
                                tempEnt
                                (GetXrefInfo tempEnt)
                            )
                            XrefList
                        )
                    )
                )
            )
        )
        (foreach i XrefList
            (if (not (member (car i) NestedList))
                (setq NonNestedXrefList (cons i NonNestedXrefList))
            )
        )
        NonNestedXrefList
    )
    ;------------------------------------------------
    (defun PrintNestedList ( lst spc mainname )
        (foreach
            i
            (vl-sort
                lst
                (function
                    (lambda ( a b )
                        (<
                            (strcase (cdr (assoc 2 (entget (car a)))))
                            (strcase (cdr (assoc 2 (entget (car b)))))
                        )
                    )
                )
            )
            (if (and (not (listp (car i))) (car i)) (prompt (strcat "\n" spc " Nested xref: " (cdr (assoc 2 (entget (car i)))) " - " (itoa (nestedxrefcount mainname (cdr (assoc 2 (entget (car i)))))))) (prompt (strcat "\n" spc " Nested xref: nil" )) )
            (PrintNestedList (if (cdr i) (cdr i) nil) (strcat "  " spc) (cdr (assoc 2 (entget (car i)))))
            ;(PrintNestedList (cdr i) (strcat "  |" spc)) [color=red]; second option shown below[/color]
        )
    )
    ;-----------------------------------------------------
   
    (foreach
        i
        (vl-sort
            (FilterNestedXrefs (GetXrefNesting) mainfilter filter)
            (function
                (lambda ( a b )
                    (<
                        (strcase (cdr (assoc 2 (entget (car a)))))
                        (strcase (cdr (assoc 2 (entget (car b)))))
                    )
                )
            )
        )
        (prompt (strcat "\n Main xref: " (cdr (assoc 2 (entget (car i)))) " - " (itoa (sslength (ssget "_X" (list '(0 . "INSERT") (assoc 2 (entget (car i))) (cons 410 (getvar 'ctab)))))) ))
        (PrintNestedList (if (and (/= (cadr i) nil) (cdr i)) (vl-remove nil (cdr i)) nil) "  |-" (cdr (assoc 2 (entget (car i)))))
    )
    (princ)
)
(vl-load-com)
(princ)

Regards, M.R.
:)
« Last Edit: December 12, 2011, 08:51:15 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #11 on: December 10, 2011, 12:35:53 PM »
Marko

Saying thank you does not seem enough. Works perfectly. I tried as best I could to solve it, way out of my zip code of knowledge.

Late last night I was thinking it could only be done with objectdbx coding.




Results from your updated code:

Input prefix filter for Main Xrefs : BL*

Input prefix filter for Nested Xrefs : UT*

 Main xref: BL-01 - 2
  |- Nested xref: UTB2-1119 - 6
  |- Nested xref: UTB5-1048 - 2
 Main xref: BL-02 - 2
  |- Nested xref: UTA2-692 - 4
  |- Nested xref: UTA2-692-HC - 2
  |- Nested xref: UTA4-697 - 8
  |- Nested xref: UTA6-899 - 1
  |- Nested xref: UTA7-969 - 1
  |- Nested xref: UTA8-697 - 2
  |- Nested xref: UTA9-697 - 2
  |- Nested xref: UTB1-969 - 6
  |- Nested xref: UTB2a-1119 - 2
  |- Nested xref: UTB4-1258 - 4
 Main xref: BL-03 - 1
  |- Nested xref: UTA1-599a - 8
  |- Nested xref: UTA1-599b - 8
  |- Nested xref: UTA3-893 - 8
 Main xref: BL-04 - 1
  |- Nested xref: UTA5-899 - 8
  |- Nested xref: UTB3-936 - 12
 Main xref: BL-05 - 1
  |- Nested xref: UTA1-599a - 8
  |- Nested xref: UTA1-599b - 8
  |- Nested xref: UTA3-893 - 8


Thank you  Thank you
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #12 on: December 10, 2011, 02:24:23 PM »
Having trouble with printing to a file:

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Print Xref Nesting ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;http://www.theswamp.org/index.php?topic=28062.msg337119#msg337119
;;;Tim Willey
;;;Marko Ribar

(defun PrintXrefNestingIT ( / mainfilter filter )
    ;;Prints nested xref tree to command line, no matter how deep the nesting.
    (setq mainfilter (getstring T "\n* Input prefix filter for Main Xrefs: [BL*] "))
    (if (= mainfilter "")(setq mainfilter "BL*"))
    (setq filter (getstring T "\n* Input prefix filter for Nested Xrefs: [UT*]"))
    (if (= filter "")(setq filter "UT*"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      (defun nestedxrefcount ( mainname nestedname / bl item )
        (setq bl (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))))
        (vlax-for item bl
          (if (= (vla-get-name item) mainname)
            (progn   
              (setq n 0) 
              (vlax-for xr item
              (if (= (vl-catch-all-apply 'vla-get-EffectiveName (list xr)) nestedname) (setq n (1+ n)))
            )
          )
        )
      )
      n
    )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun FilterNestedXrefs ( lst mainfilter filter / ifillst inewlst newlst )
        (foreach i lst
            (if (and (atom (car i)) (wcmatch (strcase (cdr (assoc 2 (entget (car i))))) (strcase mainfilter)))
                  (progn
                       (if (listp (cdr i))
    (progn
          (setq ifillst (filternested (cdr i) filter))
                                  (setq inewlst (cons (car i) ifillst))
                  (setq newlst (cons inewlst newlst))
    )
    (setq newlst (cons i newlst))
                       )
                  )
             )
        )
        (reverse newlst)
    )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun filternested ( lst filter / newlst ii )
        (foreach i lst
    (setq ii i)
            (if (and (atom (car i)) (wcmatch (strcase (cdr (assoc 2 (entget (car i))))) (strcase filter))) () (setq ii nil))
            (cond     ((listp (cdr i)) (filternested (cdr i) filter))
                ((and (atom (cdr i)) (wcmatch (strcase (cdr (assoc 2 (entget (cdr i))))) (strcase filter))) () (setq ii nil))
              ((eq (cdr i) nil) nil)
            )
            (setq newlst (cons ii newlst))
        )
        (reverse newlst)
    )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (defun GetXrefNesting (/ tempData tempEnt XrefList NonNestedXrefList NestedXrefList )       
        (defun GetXrefInfo ( ent / NestList )
            (foreach i (member '(102 . "{BLKREFS") (entget ent))
                (if (equal (car i) 332)
                    (progn
                        (setq NestedList (cons (cdr i) NestedList))
                        (setq NestList
                            (cons
                                (cons
                                    (cdr i)
                                    (GetXrefInfo (cdr i))
                                )
                                NestList
                            )
                        )
                    )
                )
            )
            NestList
        )               
        (while (setq tempData (tblnext "block" (not tempData)))
            (if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
                (progn
                    (setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
                    (setq tempEnt (cdr (assoc 330 (entget tempEnt))))
                    (setq XrefList
                        (cons
                            (cons
                                tempEnt
                                (GetXrefInfo tempEnt)
                            )
                            XrefList
                        )
                    )
                )
            )
        )
        (foreach i XrefList
            (if (not (member (car i) NestedList))
                (setq NonNestedXrefList (cons i NonNestedXrefList))
            )
        )
        NonNestedXrefList
    )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (setq FileName (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))
    (startapp "notepad.exe" (strcat (getvar "dwgprefix") FileName " PrintXrefNesting.txt"))
    (setq Opened (open (strcat (getvar "dwgprefix") FileName " PrintXrefNesting.txt") "w")) 
 
    (defun PrintNestedList ( lst spc mainname )       
        (foreach
            i
            (vl-sort
                lst
                (function
                    (lambda ( a b )
                        (<
                            (strcase (cdr (assoc 2 (entget (car a)))))
                            (strcase (cdr (assoc 2 (entget (car b)))))
                        )
                    )
                )
            )
            (if (and (not (listp (car i))) (car i)) (write-line (strcat "\n" spc " Nested xref: " (cdr (assoc 2 (entget (car i)))) " - " (itoa (nestedxrefcount mainname (cdr (assoc 2 (entget (car i))))) Opened)    ) )
            (write-line (strcat "\n" spc " Nested xref: nil") Opened))
            (PrintNestedList (if (cdr i) (cdr i) nil) (strcat "  " spc) (cdr (assoc 2 (entget (car i)))))           
        )
    )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
    (foreach
        i
        (vl-sort
            (FilterNestedXrefs (GetXrefNesting) mainfilter filter)
            (function
                (lambda ( a b )
                    (<
                        (strcase (cdr (assoc 2 (entget (car a)))))
                        (strcase (cdr (assoc 2 (entget (car b)))))
                    )
                )
            )
        )
        (write-line (strcat "\n\n[ ]  Main xref: " (cdr (assoc 2 (entget (car i)))) " - " (itoa (sslength (ssget "_X" (list '(0 . "INSERT") (assoc 2 (entget (car i))) (cons 410 (getvar 'ctab)))))) Opened))
        (PrintNestedList (if (cdr i) (cdr i) nil) "\t\t>" (cdr (assoc 2 (entget (car i)))))
    )

    ;;
    ;;(vl-filename-base (getvar "dwgname"))
    ;;(setq FileName (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))
    ;;(startapp "notepad.exe" (strcat "\\Arch " ARCH#PROJ FileName " PrintXrefNesting.txt"))

    ;;(startapp "notepad.exe" (strcat (getvar "dwgprefix") FileName " PrintXrefNesting.txt"))
    (if Opened (close Opened))
    (princ)
)
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)

Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #13 on: December 10, 2011, 08:18:54 PM »
Got it working...here is my final routine:
Special thanks to Tim Willey and Marko Ribar.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Print Xref Nesting ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;http://www.theswamp.org/index.php?topic=28062.msg337119#msg337119
;;; Tim Willey
;;; Marko Ribar
;;; Prints nested xref tree to command line, no matter how deep the nesting.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun PrintXrefNestingIT (/ mainfilter    filter
   opened projectDesc   projectName
   datestring
  )
  (defun ARCH:ProjectName ()
    (setq DirPath (getvar "dwgprefix"))
    (setq ProjectNum (substr DirPath 14 6))
    (setq ARCH#PROJ (substr DirPath 14 6))
    (cond ((/= (atoi ProjectNum) 0) (setvar "users1" ProjectNum)))
    (cond ((/= (getvar "users1") 0)
   (setq ProjectName
  (dos_getini
    "PROJECTS"
    (getvar "users1")
    (strcat ARCH#CUSF "FILE/ARCH_Projects.ini")
  )
   )
  )
    )
    (cond ((= ProjectName nil) (setq ProjectDesc ""))
  ((/= ProjectName nil)
   (setq projectDesc
  (strcat "        Project Name : [" ProjectName "]")
   )
  )
    )
    (princ)
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun ARCH:DATE2 (/ DATST MON DAY YEAR HRS)
    (setq DATST (rtos (getvar "CDATE") 2 16)
  MON (substr DATST 5 2)
  DAY (substr DATST 7 2)
  YEAR (substr DATST 1 4)
  HRS (atoi (substr DATST 10 2))
    )
    (cond ((= MON "01") (setq MON2 "January"))
  ((= MON "02") (setq MON2 "Feburary"))
  ((= MON "03") (setq MON2 "March"))
  ((= MON "04") (setq MON2 "April"))
  ((= MON "05") (setq MON2 "May"))
  ((= MON "06") (setq MON2 "June"))
  ((= MON "07") (setq MON2 "July"))
  ((= MON "08") (setq MON2 "August"))
  ((= MON "09") (setq MON2 "September"))
  ((= MON "10") (setq MON2 "October"))
  ((= MON "11") (setq MON2 "November"))
  ((= MON "12") (setq MON2 "December"))
    )
    (cond ((= HRS 00) (setq NHRS (itoa (+ HRS 12))) (setq XTR "a.m."))
  ((< HRS 12) (setq NHRS (itoa HRS)) (setq XTR "a.m."))
  ((= HRS 12) (setq NHRS (itoa HRS)) (setq XTR "p.m."))
  ((> HRS 12) (setq NHRS (itoa (- HRS 12))) (setq XTR "p.m."))
    )
    (setq datestring
   (strcat MON2
   " "
   DAY
   ", "
   YEAR
   " "
   NHRS
   ":"
   (substr DATST 12 2)
   " "
   XTR
   )
    )
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  (setq mainfilter
(getstring
   T
   "\n* Input prefix filter for Main Xrefs: [BL*] "
)
  )
  (if (= mainfilter "")
    (setq mainfilter "BL*")
  )
  (setq filter
(getstring T
    "\n* Input prefix filter for Nested Xrefs: [UT*]"
)
  )
  (if (= filter "")
    (setq filter "UT*")
  )
  (prompt "* Please Wait while the Program is Running...")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun nestedxrefcount (mainname nestedname / bl item)
    (setq bl (vla-get-blocks
       (vla-get-activedocument (vlax-get-acad-object))
     )
    )
    (vlax-for item bl
      (if (= (vla-get-name item) mainname)
(progn
  (setq n 0)
  (vlax-for xr item
    (if
      (= (vl-catch-all-apply 'vla-get-EffectiveName (list xr))
nestedname
      )
       (setq n (1+ n))
    )
  )
)
      )
    )
    n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun FilterNestedXrefs
(lst mainfilter filter / ifillst inewlst newlst)
    (foreach i lst
      (if (and (atom (car i))
       (wcmatch (strcase (cdr (assoc 2 (entget (car i)))))
(strcase mainfilter)
       )
  )
(progn
  (if (listp (cdr i))
    (progn
      (setq ifillst (filternested (cdr i) filter))
      (setq inewlst (cons (car i) ifillst))
      (setq newlst (cons inewlst newlst))
    )
    (setq newlst (cons i newlst))
  )
)
      )
    )
    (reverse newlst)
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun filternested (lst filter / newlst ii)
    (foreach i lst
      (setq ii i)
      (if (and (atom (car i))
       (wcmatch (strcase (cdr (assoc 2 (entget (car i)))))
(strcase filter)
       )
  )
()
(setq ii nil)
      )
      (cond ((listp (cdr i)) (filternested (cdr i) filter))
    ((and (atom (cdr i))
  (wcmatch (strcase (cdr (assoc 2 (entget (cdr i)))))
   (strcase filter)
  )
     )
     ()
     (setq ii nil)
    )
    ((eq (cdr i) nil) nil)
      )
      (setq newlst (cons ii newlst))
    )
    (reverse newlst)
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun GetXrefNesting (/ tempData
tempEnt XrefList
NonNestedXrefList
NestedXrefList
)
    (defun GetXrefInfo (ent / NestList)
      (foreach i (member '(102 . "{BLKREFS") (entget ent))
(if (equal (car i) 332)
  (progn
    (setq NestedList (cons (cdr i) NestedList))
    (setq NestList
   (cons
     (cons
       (cdr i)
       (GetXrefInfo (cdr i))
     )
     NestList
   )
    )
  )
)
      )
      NestList
    )
    (while (setq tempData (tblnext "block" (not tempData)))
      (if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
(progn
  (setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
  (setq tempEnt (cdr (assoc 330 (entget tempEnt))))
  (setq XrefList
(cons
   (cons
     tempEnt
     (GetXrefInfo tempEnt)
   )
   XrefList
)
  )
)
      )
    )
    (foreach i XrefList
      (if (not (member (car i) NestedList))
(setq NonNestedXrefList (cons i NonNestedXrefList))
      )
    )
    NonNestedXrefList
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (ARCH:DATE2)
  (ARCH:ProjectName)
  (setq FileName (substr (getvar "dwgname")
1
(- (strlen (getvar "dwgname")) 4)
)
  )
  (setq Opened (open (strcat (getvar "dwgprefix")
     FileName
     " PrintXrefNesting.txt"
     )
     "w"
       )
  )
  (write-line
    "----------------------------------------------------------------------"
    opened
  )
  (write-line projectDesc opened)
  (write-line
    (strcat "        Directory is: ["
    (getvar "dwgprefix")
    FileName
    "]"
    )
    opened
  )
  (write-line (strcat "        " datestring) opened)

  (write-line
    "----------------------------------------------------------------------"
    opened
  )

  (defun PrintNestedList (lst spc mainname)
    (foreach
      i
       (vl-sort
lst
(function
   (lambda (a b)
     (<
       (strcase (cdr (assoc 2 (entget (car a)))))
       (strcase (cdr (assoc 2 (entget (car b)))))
     )
   )
)
       )
      (if (and (not (listp (car i))) (car i))
(write-line
  (strcat ""
  spc
  " Nested xref: "
  (cdr (assoc 2 (entget (car i))))
  " - "
  (itoa (nestedxrefcount
  mainname
  (cdr (assoc 2 (entget (car i))))
)
  )
  )
  opened
)
(prompt (strcat "\n" spc " Nested xref: nil"))
      )
      (PrintNestedList
(if (cdr i)
  (cdr i)
  nil
)
(strcat "" spc)
(cdr (assoc 2 (entget (car i))))
      )
    )
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  (foreach
    i
     (vl-sort
       (FilterNestedXrefs (GetXrefNesting) mainfilter filter)
       (function
(lambda (a b)
   (<
     (strcase (cdr (assoc 2 (entget (car a)))))
     (strcase (cdr (assoc 2 (entget (car b)))))
   )
)
       )
     )
    (write-line
      (strcat "\n\n [ ] Main xref: "
      (cdr (assoc 2 (entget (car i))))
      " - "
      (itoa (sslength (ssget "_X"
     (list '(0 . "INSERT")
   (assoc 2 (entget (car i)))
   (cons 410 (getvar 'ctab))
     )
      )
    )
      )
      )
      opened
    )
    (PrintNestedList
      (if (cdr i)
(cdr i)
nil
      )
      "     >"
      (cdr (assoc 2 (entget (car i))))
    )
  )

  ;;(vl-filename-base (getvar "dwgname"))
  ;;(setq FileName (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))
  ;;(startapp "notepad.exe" (strcat "\\Arch " ARCH#PROJ FileName " PrintXrefNesting.txt"))
  ;;(startapp "notepad.exe" (strcat (getvar "dwgprefix") FileName " PrintXrefNesting.txt"))

  (if Opened
    (close Opened)
  )
  (startapp "notepad.exe"
    (strcat (getvar "dwgprefix")
    FileName
    " PrintXrefNesting.txt"
    )
  )
  (princ)
)
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)
Example of output file:
Code: [Select]
----------------------------------------------------------------------
        Project Name : [Lakes @ University Park]
        Directory is: [F:\Jobs\2008\080331\acad\building\BL-Profile1]
        December 10, 2011 7:17 p.m.
----------------------------------------------------------------------


 [ ] Main xref: BL-01 - 2
     > Nested xref: UTB2-1119 - 6
     > Nested xref: UTB5-1048 - 2


 [ ] Main xref: BL-02 - 2
     > Nested xref: UTA2-692 - 4
     > Nested xref: UTA2-692-HC - 2
     > Nested xref: UTA4-697 - 8
     > Nested xref: UTA6-899 - 1
     > Nested xref: UTA7-969 - 1
     > Nested xref: UTA8-697 - 2
     > Nested xref: UTA9-697 - 2
     > Nested xref: UTB1-969 - 6
     > Nested xref: UTB2a-1119 - 2
     > Nested xref: UTB4-1258 - 4


 [ ] Main xref: BL-03 - 1
     > Nested xref: UTA1-599a - 8
     > Nested xref: UTA1-599b - 8
     > Nested xref: UTA3-893 - 8


 [ ] Main xref: BL-04 - 1
     > Nested xref: UTA5-899 - 8
     > Nested xref: UTB3-936 - 12


 [ ] Main xref: BL-05 - 1
     > Nested xref: UTA1-599a - 8
     > Nested xref: UTA1-599b - 8
     > Nested xref: UTA3-893 - 8
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #14 on: December 10, 2011, 09:01:07 PM »
Minor twicks

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Print Xref Nesting ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;http://www.theswamp.org/index.php?topic=28062.msg337119#msg337119
;;; original routine by Tim Willey
;;; major editing by Marko Ribar
;;; Prints nested xref tree to command line, no matter how deep the nesting.
;;; edited by Gary Fowler
;;; Added output file project header and routine progress bar
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun PrintXrefNestingIT (/ mainfilter    filter
   opened projectDesc   projectName
   datestring n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun ARCH:ProjectName ()
    (setq DirPath (getvar "dwgprefix"))
    (setq ProjectNum (substr DirPath 14 6))
    (setq ARCH#PROJ (substr DirPath 14 6))
    (cond ((/= (atoi ProjectNum) 0) (setvar "users1" ProjectNum)))
    (cond ((/= (getvar "users1") 0)
   (setq ProjectName
  (dos_getini
    "PROJECTS"
    (getvar "users1")
    (strcat ARCH#CUSF "FILE/ARCH_Projects.ini")
  )
   )
  )
    )
    (cond ((= ProjectName nil) (setq ProjectDesc ""))
  ((/= ProjectName nil)
   (setq projectDesc
  (strcat "        Project Name : [" ProjectName "]")
   )
  )
    )
    (princ)
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun ARCH:DATE2 (/ DATST MON DAY YEAR HRS)
    (setq DATST (rtos (getvar "CDATE") 2 16)
  MON (substr DATST 5 2)
  DAY (substr DATST 7 2)
  YEAR (substr DATST 1 4)
  HRS (atoi (substr DATST 10 2))
    )
    (cond ((= MON "01") (setq MON2 "January"))
  ((= MON "02") (setq MON2 "Feburary"))
  ((= MON "03") (setq MON2 "March"))
  ((= MON "04") (setq MON2 "April"))
  ((= MON "05") (setq MON2 "May"))
  ((= MON "06") (setq MON2 "June"))
  ((= MON "07") (setq MON2 "July"))
  ((= MON "08") (setq MON2 "August"))
  ((= MON "09") (setq MON2 "September"))
  ((= MON "10") (setq MON2 "October"))
  ((= MON "11") (setq MON2 "November"))
  ((= MON "12") (setq MON2 "December"))
    )
    (cond ((= HRS 00) (setq NHRS (itoa (+ HRS 12))) (setq XTR "a.m."))
  ((< HRS 12) (setq NHRS (itoa HRS)) (setq XTR "a.m."))
  ((= HRS 12) (setq NHRS (itoa HRS)) (setq XTR "p.m."))
  ((> HRS 12) (setq NHRS (itoa (- HRS 12))) (setq XTR "p.m."))
    )
    (setq datestring
   (strcat MON2
   " "
   DAY
   ", "
   YEAR
   " "
   NHRS
   ":"
   (substr DATST 12 2)
   " "
   XTR
   )
    )
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  (setq mainfilter
(getstring
   T
   "\n* Input prefix filter for Main Xrefs: [BL*] "
)
  )
  (if (= mainfilter "")
    (setq mainfilter "BL*")
  )
  (setq filter
(getstring T
    "\n* Input prefix filter for Nested Xrefs: [UT*]"
)
  )
  (if (= filter "")
    (setq filter "UT*")
  )
  (prompt "* Please Wait while the Program is Running...")
  (setq n 1)
  (ACET-UI-PROGRESS-INIT
    "Please Wait while the Program is Running"
    (length rtnList))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun nestedxrefcount (mainname nestedname / bl item)
    (setq bl (vla-get-blocks
       (vla-get-activedocument (vlax-get-acad-object))
     )
    )
    (vlax-for item bl
      (if (= (vla-get-name item) mainname)
(progn
  (setq n 0)
  (vlax-for xr item
    (if
      (= (vl-catch-all-apply 'vla-get-EffectiveName (list xr))
nestedname
      )
       (setq n (1+ n))
    )
  )
)
      )
    )
    n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun FilterNestedXrefs
(lst mainfilter filter / ifillst inewlst newlst)
    (foreach i lst
      (if (and (atom (car i))
       (wcmatch (strcase (cdr (assoc 2 (entget (car i)))))
(strcase mainfilter)
       )
  )
(progn
  (if (listp (cdr i))
    (progn
      (setq ifillst (filternested (cdr i) filter))
      (setq inewlst (cons (car i) ifillst))
      (setq newlst (cons inewlst newlst))
    )
    (setq newlst (cons i newlst))
  )
)
      )
      (ACET-UI-PROGRESS-SAFE n)
      (setq n (+ n 1))
    )   
    (reverse newlst)
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun filternested (lst filter / newlst ii)
    (foreach i lst
      (setq ii i)
      (if (and (atom (car i))
       (wcmatch (strcase (cdr (assoc 2 (entget (car i)))))
(strcase filter)
       )
  )
()
(setq ii nil)
      )
      (cond ((listp (cdr i)) (filternested (cdr i) filter))
    ((and (atom (cdr i))
  (wcmatch (strcase (cdr (assoc 2 (entget (cdr i)))))
   (strcase filter)
  )
     )
     ()
     (setq ii nil)
    )
    ((eq (cdr i) nil) nil)
      )
      (setq newlst (cons ii newlst))   
      (ACET-UI-PROGRESS-SAFE n)
      (setq n (+ n 1))   
    )
    (reverse newlst)
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (defun GetXrefNesting (/ tempData
tempEnt XrefList
NonNestedXrefList
NestedXrefList
)
    (defun GetXrefInfo (ent / NestList)     
      (foreach i (member '(102 . "{BLKREFS") (entget ent))
(if (equal (car i) 332)
  (progn
    (setq NestedList (cons (cdr i) NestedList))
    (setq NestList
   (cons
     (cons
       (cdr i)
       (GetXrefInfo (cdr i))
     )
     NestList
   )
    )
  )

        (ACET-UI-PROGRESS-SAFE n)
        (setq n (+ n 1))     
      )
      NestList
    )
    (while (setq tempData (tblnext "block" (not tempData)))
      (if (equal (logand (cdr (assoc 70 tempData)) 4) 4)
(progn
  (setq tempEnt (tblobjname "block" (cdr (assoc 2 tempData))))
  (setq tempEnt (cdr (assoc 330 (entget tempEnt))))
  (setq XrefList
(cons
   (cons
     tempEnt
     (GetXrefInfo tempEnt)
   )
   XrefList
)
  )
)
      )
    )
    (foreach i XrefList
      (if (not (member (car i) NestedList))
(setq NonNestedXrefList (cons i NonNestedXrefList))
      )
      (ACET-UI-PROGRESS-SAFE n)
      (setq n (+ n 1))
    )
    NonNestedXrefList
  ) 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (ARCH:DATE2)
  (ARCH:ProjectName)
  (setq FileName (substr (getvar "dwgname")
1
(- (strlen (getvar "dwgname")) 4)
)
  )
  (setq Opened (open (strcat (getvar "dwgprefix")
     FileName
     " PrintXrefNesting.txt"
     )
     "w"
       )
  )
  (write-line
    "----------------------------------------------------------------------"
    opened
  )
  (write-line projectDesc opened)
  (write-line
    (strcat "        Directory is: ["
    (getvar "dwgprefix")
    FileName
    "]"
    )
    opened
  )
  (write-line (strcat "        " datestring) opened)
  (write-line
    "----------------------------------------------------------------------"
    opened
  )

  (defun PrintNestedList (lst spc mainname)
    (foreach
      i
       (vl-sort
lst
(function
   (lambda (a b)
     (<
       (strcase (cdr (assoc 2 (entget (car a)))))
       (strcase (cdr (assoc 2 (entget (car b)))))
     )
   )
)
       )
      (if (and (not (listp (car i))) (car i))
(write-line
  (strcat ""
  spc
  " Nested xref: "
  (cdr (assoc 2 (entget (car i))))
  " - "
  (itoa (nestedxrefcount
  mainname
  (cdr (assoc 2 (entget (car i))))
)
  )
  )
  opened
)
(prompt (strcat "\n" spc " Nested xref: nil"))
      )
      (PrintNestedList
(if (cdr i)
  (cdr i)
  nil
)
(strcat "" spc)
(cdr (assoc 2 (entget (car i))))
      )
    )
    (ACET-UI-PROGRESS-SAFE n)
    (setq n (+ n 1))
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  (foreach
    i
     (vl-sort
       (FilterNestedXrefs (GetXrefNesting) mainfilter filter)
       (function
(lambda (a b)
   (<
     (strcase (cdr (assoc 2 (entget (car a)))))
     (strcase (cdr (assoc 2 (entget (car b)))))
   )
)
       )
     )
    (write-line
      (strcat "\n\n [ ] Main xref: "
      (cdr (assoc 2 (entget (car i))))
      " - "
      (itoa (sslength (ssget "_X"
     (list '(0 . "INSERT")
   (assoc 2 (entget (car i)))
   (cons 410 (getvar 'ctab))
     )
      )
    )
      )
      )
      opened
    )
    (PrintNestedList
      (if (cdr i)
(cdr i)
nil
      )
      "     >"
      (cdr (assoc 2 (entget (car i))))
    )
  )

  ;;(vl-filename-base (getvar "dwgname"))
  ;;(setq FileName (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))
  ;;(startapp "notepad.exe" (strcat "\\Arch " ARCH#PROJ FileName " PrintXrefNesting.txt"))
  ;;(startapp "notepad.exe" (strcat (getvar "dwgprefix") FileName " PrintXrefNesting.txt"))

  (if Opened
    (close Opened)
  )
  (startapp "notepad.exe"
    (strcat (getvar "dwgprefix")
    FileName
    " PrintXrefNesting.txt"
    )
  )
  (ACET-UI-PROGRESS-DONE)
  (princ)
)
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64