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

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #15 on: December 10, 2011, 10:59:14 PM »
Updated code...I'm done.

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 with project header and routine progress bar and xref paths
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun PrintXrefNestingIT (/ mainfilter   filter
   opened projectDesc  projectName
   datestring n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Function: xrefs-list
;;;Purpose: get information regarding xrefs
;;;Arguments: none
;;;Returns: rtlist - a list of lists, one for each xref, as follows:
;;; (nth 0 (car rtlist)) = filename
;;; (nth 1 (car rtlist)) = fullfilename
;;; (nth 2 (car rtlist)) = foundpath
;;; (nth 3 (car rtlist)) = ismodified - vlax:true/vlax:false
;;; (nth 4 (car rtlist)) = reference count
;;;Mike Weaver
  (defun xrefs-list (/ rtlist)
    (vl-load-com)
    (ACET-UI-PROGRESS-SAFE n)
    (setq n (+ n 1))
    (write-line (strcat "\n List Of Saved Xref Paths:") opened)
    (write-line
      (strcat
"----------------------------------------------------------------------"
      )
      opened
    )
    (vlax-for
      objFileDep
(vla-get-filedependencies
  (vla-get-activedocument
    (vlax-get-acad-object)
  )
)
      (if (= "Acad:XRef" (vla-get-feature objFileDep))
(setq
  rtlist (cons
   (cons
     (vla-get-filename objFileDep)
     ;;(list
     ;;(vla-get-fullfilename objFileDep)
     ;;(vla-get-foundpath objFileDep)
     ;;(vla-get-ismodified objFileDep)
     ;;(vla-get-referencecount objFileDep)
     ;;)
     (write-line
       (strcat " " (vla-get-fullfilename objFileDep))
       opened
     )
   )
   rtlist
)
)
      )
    )
    rtlist
  )
  ;;(foreach i rtlist (write-line (strcat " " (nth 1 (car rtlist))) opened))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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 [ ] 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"))

  (xrefs-list)

  (if Opened
    (close Opened)
  )
  (startapp "notepad.exe"
    (strcat (getvar "dwgprefix")
    FileName
    " PrintXrefNesting.txt"
    )
  )
  (ACET-UI-PROGRESS-DONE)
  (princ)
)
(vl-load-com)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)
Output file:
Code: [Select]
----------------------------------------------------------------------
        Project Name : [Lakes @ University Park]
        Directory is: [F:\Jobs\2008\080331\acad\building\BL-Profile1]
        December 10, 2011 9:59 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

 List Of Saved Xref Paths:
----------------------------------------------------------------------
 F:\Jobs\2008\080331\ACAD\building\BL-01.dwg
 F:\Jobs\2008\080331\ACAD\building\BL-02.dwg
 F:\Jobs\2008\080331\ACAD\building\BL-04.dwg
 F:\Jobs\2008\080331\ACAD\building\BL-05.dwg
 F:\Jobs\2008\080331\ACAD\building\BL-03.dwg
 F:\Jobs\2008\080331\ACAD\units\UTB2-1119.dwg
 F:\Jobs\2008\080331\ACAD\units\UTB5-1048.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA4-697.dwg
 F:\Jobs\2008\080331\ACAD\units\UTB1-969.dwg
 F:\Jobs\2008\080331\ACAD\units\UTB4-1258.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA2-692-HC.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA6-899.dwg
 F:\Jobs\2008\080331\ACAD\units\UTB2a-1119.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA2-692.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA9-697.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA7-969.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA8-697.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA5-899.dwg
 F:\Jobs\2008\080331\ACAD\units\UTB3-936.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA3-893.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA1-599b.dwg
 F:\Jobs\2008\080331\ACAD\units\UTA1-599a.dwg
« Last Edit: December 10, 2011, 11:19:40 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: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #16 on: December 11, 2011, 01:50:40 AM »
I see that you didn't noticed that I forgot to localize n variable in :
(defun nestedxrefcount (mainname nestedname / bl item)

and seeing that you uses n later on in your bigger code I suggest that you modify :
(defun nestedxrefcount (mainname nestedname / bl item n)

also I don't know ab this line :
    "Please Wait while the Program is Running"
    (length rtnList)

variable rtnList is global and is called from your session...
maybe I am wrong, but I thought you wanted
    (length (xrefs-list))

and finally, I would consider showing in your report Nested from Nested Xrefs (notice space characters in between "" (strcat "   " spc)) :
Code: [Select]
      (PrintNestedList
(if (cdr i)
  (cdr i)
  nil
)
(strcat "  " spc)
(cdr (assoc 2 (entget (car i))))
      )
Regards, M.R.
« Last Edit: December 11, 2011, 04:23:43 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #17 on: December 11, 2011, 05:07:26 AM »
So this final version should give you no errors after execution on text screen... Still you should check for progress - does it ends at 100%... Test it once with ;(acet-ui-progress-done) and if it all OK (100% and no errors on text screen), then put it back without ;

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 with project header and routine progress bar and xref paths
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:PrintXrefNestingIT (/ mainfilter   filter
   opened projectDesc  projectName
   datestring n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Function: xrefs-list
;;;Purpose: get information regarding xrefs
;;;Arguments: none
;;;Returns: rtlist - a list of lists, one for each xref, as follows:
;;; (nth 0 (car rtlist)) = filename
;;; (nth 1 (car rtlist)) = fullfilename
;;; (nth 2 (car rtlist)) = foundpath
;;; (nth 3 (car rtlist)) = ismodified - vlax:true/vlax:false
;;; (nth 4 (car rtlist)) = reference count
;;;Mike Weaver

  (defun Flatten ( l )
    (if (atom l) (list l)
      (append (Flatten (car l)) (if (cdr l) (Flatten (cdr l))))
    )
  )

  (defun xrefs-list (/ rtlist)
    (vl-load-com)
    (write-line (strcat "\n List Of Saved Xref Paths:") opened)
    (write-line
      (strcat
"----------------------------------------------------------------------"
      )
      opened
    )
    (vlax-for
      objFileDep
(vla-get-filedependencies
  (vla-get-activedocument
    (vlax-get-acad-object)
  )
)
      (if (= "Acad:XRef" (vla-get-feature objFileDep))
(setq
  rtlist (cons
   (cons
     (vla-get-filename objFileDep)
     ;;(list
     ;;(vla-get-fullfilename objFileDep)
     ;;(vla-get-foundpath objFileDep)
     ;;(vla-get-ismodified objFileDep)
     ;;(vla-get-referencecount objFileDep)
     ;;)
     (write-line
       (strcat " " (vla-get-fullfilename objFileDep))
       opened
     )
   )
   rtlist
)
)
      )
    )
    rtlist
  )
  ;;(foreach i rtlist (write-line (strcat " " (nth 1 (car rtlist))) opened))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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: [*] "
)
  )
  (if (= mainfilter "")
    (setq mainfilter "*")
  )
  (setq filter
(getstring T
    "\n* Input prefix filter for Nested Xrefs: [*] "
)
  )
  (if (= filter "")
    (setq filter "*")
  )
  (prompt "* Please Wait while the Program is Running...")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq n 1)
  (ACET-UI-PROGRESS-INIT
    "Please Wait while the Program is Running"
    (length (Flatten (FilterNestedXrefs (GetXrefNesting) mainfilter filter)))
  )
  (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 [ ] 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
    )
    (ACET-UI-PROGRESS-SAFE n)
    (setq n (+ n 1))

    (PrintNestedList
      (if (and (/= (cadr i) nil) (cdr i))
(vl-remove nil (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"))

  (xrefs-list)

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

Regards, M.R.
:)
« Last Edit: December 12, 2011, 08:49:08 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 #18 on: December 11, 2011, 04:41:30 PM »
Marko

Thanks for the feedback, I still need to some error and var checking. It works smoothly with no errors. I'm sure to break it later on. Thanks for the corrections! I have since added the word "Total" after the count.

I like your YouTube videos.

Thanks again for your help.

Gary
« Last Edit: December 11, 2011, 04:49:35 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

GDF

  • Water Moccasin
  • Posts: 2081
Re: Nested Xref Counter in Tree Format
« Reply #19 on: December 11, 2011, 10:14:02 PM »
Marko, If your looking for another challenge, what about adding a total count per each of the Nested xrefs per each of the Main xrefs?
Will this require another function to count up the total of all Nested xrefs per each Main xref?

Modifing the "PrintNestedList" function to include this totaling up process?

Can you point me in the right direction.

----------------------------------------------------------------------
        Project Name : [Merritt Lakeside Sr Village]
        Directory is: [F:\Jobs\2009\091138\acad\building\BL-Profile2]
        December 11, 2011 8:18 p.m.
----------------------------------------------------------------------

 [ ] Main xref: BL-01 - 2 Total
     > Nested xref: UTA2 - 7 Total
     > Nested xref: UTA3 - 6 Total
     > Nested xref: UTA5 - 3 Total
     > Nested xref: UTB1 - 3 Total
     > Nested xref: UTB3b - 6 Total
     > Nested xref: UTB3c - 6 Total
     > Nested xref: UTB4a - 6 Total
     > Nested xref: UTB4b - 6 Total
        Total Count (2 x 37 = 74 Grand Total)  <-- new output

       (2 Main xrefs) x (Nested xref total) = Grand Total

 
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: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #20 on: December 12, 2011, 06:22:45 AM »
All I can do is to count Xrefs per branch, and in format like this :
----------------------------------------------------------------------
        Directory is: [C:\Documents and Settings\Marica\Desktop\xrefs\xrefss]
        December 12, 2011 2:28 p.m.
----------------------------------------------------------------------

 [ ] Main xref: xrefs2 - 1
     > Nested xref: Drawing2 - 1
       > Nested xref: ex2 - 3
         > Nested xref: ex4 - 2
---------- Total count per branch : 2 ----------
---------- Total count per branch : 3 ----------
     > Nested xref: Drawing3 - 1
     > Nested xref: Drawing4 - 1
---------- Total count per branch : 3 ----------

 [ ] Main xref: xrefs3 - 1
     > Nested xref: Drawing1 - 2
       > Nested xref: ex1 - 2
         > Nested xref: ex3 - 1
         > Nested xref: ex4 - 1
---------- Total count per branch : 2 ----------
       > Nested xref: ex2 - 1
         > Nested xref: ex4 - 2
---------- Total count per branch : 2 ----------
---------- Total count per branch : 3 ----------
     > Nested xref: Drawing2 - 1
       > Nested xref: ex2 - 3
         > Nested xref: ex4 - 2
---------- Total count per branch : 2 ----------
---------- Total count per branch : 3 ----------
     > Nested xref: Drawing3 - 1
     > Nested xref: Drawing4 - 1
---------- Total count per branch : 5 ----------

 List Of Saved Xref Paths:
----------------------------------------------------------------------
 C:\Documents and Settings\Marica\Desktop\xrefs\xrefs3.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\Drawing1.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\Drawing3.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\Drawing4.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\Drawing2.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\ex1.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\ex2.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\ex3.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\ex4.dwg
 C:\Documents and Settings\Marica\Desktop\xrefs\xrefs2.dwg

You can see that firstly it counts last branch, and when needed to separate results it prints counts from previous branch... So if you have only 1 branch like in your case it will do fine, but you must multiply branch with number of main xref count manually...

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 with project header and routine progress bar and xref paths
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:PrintXrefNestingIT (/ mainfilter   filter
   opened projectDesc  projectName
   datestring n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Function: xrefs-list
;;;Purpose: get information regarding xrefs
;;;Arguments: none
;;;Returns: rtlist - a list of lists, one for each xref, as follows:
;;; (nth 0 (car rtlist)) = filename
;;; (nth 1 (car rtlist)) = fullfilename
;;; (nth 2 (car rtlist)) = foundpath
;;; (nth 3 (car rtlist)) = ismodified - vlax:true/vlax:false
;;; (nth 4 (car rtlist)) = reference count
;;;Mike Weaver

  (defun Flatten ( l )
    (if (atom l) (list l)
      (append (Flatten (car l)) (if (cdr l) (Flatten (cdr l))))
    )
  )

  (defun xrefs-list (/ rtlist)
    (vl-load-com)
    (write-line (strcat "\n List Of Saved Xref Paths:") opened)
    (write-line
      (strcat
"----------------------------------------------------------------------"
      )
      opened
    )
    (vlax-for
      objFileDep
(vla-get-filedependencies
  (vla-get-activedocument
    (vlax-get-acad-object)
  )
)
      (if (= "Acad:XRef" (vla-get-feature objFileDep))
(setq
  rtlist (cons
   (cons
     (vla-get-filename objFileDep)
     ;;(list
     ;;(vla-get-fullfilename objFileDep)
     ;;(vla-get-foundpath objFileDep)
     ;;(vla-get-ismodified objFileDep)
     ;;(vla-get-referencecount objFileDep)
     ;;)
     (write-line
       (strcat " " (vla-get-fullfilename objFileDep))
       opened
     )
   )
   rtlist
)
)
      )
    )
    rtlist
  )
  ;;(foreach i rtlist (write-line (strcat " " (nth 1 (car rtlist))) opened))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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: [*] "
)
  )
  (if (= mainfilter "")
    (setq mainfilter "*")
  )
  (setq filter
(getstring T
    "\n* Input prefix filter for Nested Xrefs: [*] "
)
  )
  (if (= filter "")
    (setq filter "*")
  )
  (prompt "* Please Wait while the Program is Running...")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (setq n 1)
  (ACET-UI-PROGRESS-INIT
    "Please Wait while the Program is Running"
    (length (Flatten (FilterNestedXrefs (GetXrefNesting) mainfilter filter)))
  )
  (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 / lstn k)
    (foreach
      i
       (setq lstn (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))
    )
(setq k 0)
(foreach i lstn
  (setq k (+ k (nestedxrefcount mainname (cdr (assoc 2 (entget (car i))))) ))
    )
(if lstn (write-line (strcat "---------- Total count per branch : " (itoa k) " ----------") opened))
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  (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 [ ] 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
    )
    (ACET-UI-PROGRESS-SAFE n)
    (setq n (+ n 1))

    (PrintNestedList
      (if (and (/= (cadr i) nil) (cdr i))
(vl-remove nil (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"))

  (xrefs-list)

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

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

:)

M.R. on Youtube

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #21 on: December 12, 2011, 08:55:21 AM »
I've changed to this :

Code: [Select]
    (PrintNestedList
      (if (and (/= (cadr i) nil) (cdr i))
(vl-remove nil (cdr i))
nil
      )
      "     >"
      (cdr (assoc 2 (entget (car i))))
    )

I think that only with this intervention filters work OK as they should...

Marko

Thanks for the feedback, I still need to some error and var checking. It works smoothly with no errors. I'm sure to break it later on. Thanks for the corrections! I have since added the word "Total" after the count.

I like your YouTube videos.

Thanks again for your help.

Gary

You're welcome...
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 #22 on: December 12, 2011, 11:17:40 AM »
Marko

Thanks again.

One last question. Had been working at home, so this in the office this morning, I ran the previous routine.
 
I get this error on some drawing files that has a nested xref that does not match the filter entered.
One of the nested xrefs starts with "E" for example. I think this is happening because of the filted counting of a nested xref that does not exist. Can't do the math with nil? I don't know.

* Input prefix filter for Main Xrefs:
  • BL*

* Input prefix filter for Nested Xrefs:
  • UT*

* Please Wait while the Program is Running...; error: bad argument type:
lentityp nil

Gary
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 #23 on: December 12, 2011, 12:04:17 PM »
Marko

Thanks again.

One last question. Had been working at home, so this in the office this morning, I ran the previous routine.
 
I get this error on some drawing files that has a nested xref that does not match the filter entered.
One of the nested xrefs starts with "E" for example. I think this is happening because of the filted counting of a nested xref that does not exist. Can't do the math with nil? I don't know.

* Input prefix filter for Main Xrefs:
  • BL*

* Input prefix filter for Nested Xrefs:
  • UT*

* Please Wait while the Program is Running...; error: bad argument type:
lentityp nil

Gary


I disabled the acet progress abr and it fixed the error, but no nested xrefs were listed in the main xref that did not match the filter:

 [ ] Main xref: BL-01 - 1 Total

    Missing nested xrefs, because xref name was filtered out

 [ ] Main xref: BL-02 - 1 Total
     > Nested xref: UTA20750-HC - 3 Total
     > Nested xref: uta20781 - 9 Total
     > Nested xref: UTB10950-a - 3 Total
     > Nested xref: UTB10950-hc - 3 Total
     > Nested xref: utb31032 - 12 Total
       Total Count = 30





[ ] Main xref: BL-01 - 1 Total
     > Nested xref: ElevLobby1 - 1 Total   
     > Nested xref: UTA20750-HCa - 3 Total
     > Nested xref: uta20781 - 9 Total
     > Nested xref: UTA2a-MEN - 1 Total
     > Nested xref: UTA2a-STORAGE - 1 Total
     > Nested xref: UTA2a-WOMEN - 1 Total
     > Nested xref: utb31032 - 15 Total
       Total Count = 31

 
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: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #24 on: December 12, 2011, 12:12:32 PM »
* Please Wait while the Program is Running...; error: bad argument type:
lentityp nil

Gary

Gary, that's wright it doesn't show data for nested xrefs that do not match filter, and that means also for main xref filter...
Tell me is this error happening with my latest intervention on code?
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 #25 on: December 12, 2011, 12:23:40 PM »
Marko

I tried it on both codes. Same problem with in the same drawing.

The nested xref starts with an E and is filtered out. This occurs here:
[ ] Main xref: BL-01 - 1 Total (here it does not work)

And again here: (but here it works and is filtered out)
[ ] Main xref: BL-02 - 1 Total
     > Nested xref: UTA20750-HC - 3 Total
     > Nested xref: uta20781 - 9 Total
     > Nested xref: UTB10950-a - 3 Total
     > Nested xref: UTB10950-hc - 3 Total
     > Nested xref: utb31032 - 12 Total
       Total Count = 30
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: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #26 on: December 12, 2011, 01:25:15 PM »
Gary, as far as I know, you don't have nested Xrefs that starts with E in all your main Xrefs, and this is why it don't shows any of them... You must have E* nested xrefs within all of your main Xrefs to recognize them and show them... Tell me though, does error occurs?

M.R.

Look, this filter I've made isn't really as expected, but this is as much near to what it should be. I would created real list from Tim's list of xrefs if that wasn't so complex, so I just excluded all possible next nested filter matches if not occur in all parent element associations of original list, and parent element association is referenced only on main xrefs and filter only on first nested branch of xrefs...
« Last Edit: December 12, 2011, 02:15:47 PM 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 #27 on: December 12, 2011, 03:30:00 PM »
Marko

I do have nested Xrefs that starts with "E" and "O" in some of Nested Xrefs, but not all. I can not get the filter input prefix to work, for any condition. I am just trying to understand what is wrong. You have been very nice to help me (even doing the work). My programming abilities are limited.


I can't even get this to work: testing --> (setq mainfilter "*" filter "UT*")
Result:
 [ ] Main xref: BL-01 = 2 Count

 [ ] Main xref: BL-02 = 2 Count

 [ ] Main xref: BL-CLUB = 1 Count





Testing ---> (setq mainfilter "*" filter "*")
Result:
 [ ] Main xref: BL-01 = 2 Count
     > Nested xref: ElevLobby1 = 1 Count    <--filter out
     > Nested xref: Outine = 5 Count   <-- filter out
     > Nested xref: UTA10780 = 5 Count
     > Nested xref: UTA10780r = 2 Count
     > Nested xref: UTA20780 = 1 Count
     > Nested xref: UTA20780-HC = 1 Count
     > Nested xref: UTA20780r = 1 Count
     > Nested xref: UTB21028 = 8 Count
     > Nested xref: UTB21028-HC = 2 Count
     > Nested xref: UTB21028r = 4 Count
     > Nested xref: UTB21028r-HC = 1 Count
       Total Count = 31/Main Xref

 [ ] Main xref: BL-02 = 2 Count
     > Nested xref: ElevLobby2 = 1 Count   <-- filter out
     > Nested xref: Outine = 5 Count   <-- filter out
     > Nested xref: UTA10780 = 4 Count
     > Nested xref: UTA10780r = 2 Count
     > Nested xref: UTA20780 = 2 Count
     > Nested xref: UTA20780r = 1 Count
     > Nested xref: UTB21028 = 8 Count
     > Nested xref: UTB21028r = 4 Count
     > Nested xref: UTB21028rx = 1 Count
     > Nested xref: UTB21028x = 2 Count
       Total Count = 30/Main Xref

 [ ] Main xref: BL-CLUB = 1 Count
     > Nested xref: BL-Dormer6 = 1 Count   <-- filter out
     > Nested xref: KeyPlan = 2 Count   <-- filter out
     > Nested xref: Outine = 5 Count   <-- filter out
     Total Count = 8/Main Xref


Anyway you have done WAY more than I could ever have expected. Thanks.

Gary



« Last Edit: December 12, 2011, 03:39:04 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: 3274
  • Marko Ribar, architect
Re: Nested Xref Counter in Tree Format
« Reply #28 on: December 12, 2011, 07:17:47 PM »
Here I revised my code for the last time... Now filters work as they really expected... Still I am not sure why do you have wrong results with mainfilter * and filter *... But I fixed issue of showing nested xrefs if they exist in main xref (no matter if exist in all xrefs)... So here is code :

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 with project header and routine progress bar and xref paths
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun c:PrintXrefNestingIT (/ mainfilter   filter
   opened projectDesc  projectName
   datestring n
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Function: xrefs-list
;;;Purpose: get information regarding xrefs
;;;Arguments: none
;;;Returns: rtlist - a list of lists, one for each xref, as follows:
;;; (nth 0 (car rtlist)) = filename
;;; (nth 1 (car rtlist)) = fullfilename
;;; (nth 2 (car rtlist)) = foundpath
;;; (nth 3 (car rtlist)) = ismodified - vlax:true/vlax:false
;;; (nth 4 (car rtlist)) = reference count
;;;Mike Weaver

  (defun Flatten ( l )
    (if (atom l) (list l)
      (append (Flatten (car l)) (if (cdr l) (Flatten (cdr l))))
    )
  )

  (defun xrefs-list (/ rtlist)
    (vl-load-com)
    (write-line (strcat "\n List Of Saved Xref Paths:") opened)
    (write-line
      (strcat
"----------------------------------------------------------------------"
      )
      opened
    )
    (vlax-for
      objFileDep
(vla-get-filedependencies
  (vla-get-activedocument
    (vlax-get-acad-object)
  )
)
      (if (= "Acad:XRef" (vla-get-feature objFileDep))
(setq
  rtlist (cons
   (cons
     (vla-get-filename objFileDep)
     ;;(list
     ;;(vla-get-fullfilename objFileDep)
     ;;(vla-get-foundpath objFileDep)
     ;;(vla-get-ismodified objFileDep)
     ;;(vla-get-referencecount objFileDep)
     ;;)
     (write-line
       (strcat " " (vla-get-fullfilename objFileDep))
       opened
     )
   )
   rtlist
)
)
      )
    )
    rtlist
  )
  ;;(foreach i rtlist (write-line (strcat " " (nth 1 (car rtlist))) opened))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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: [*] "
)
  )
  (if (= mainfilter "")
    (setq mainfilter "*")
  )
  (setq filter
(getstring T
    "\n* Input prefix filter for Nested Xrefs: [*] "
)
  )
  (if (= filter "")
    (setq filter "*")
  )
  (prompt "* Please Wait while the Program is Running...")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  (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 ((if (and (listp (cdr i)) (member (car i) ii)) (filternested (cdr i) filter) (setq ii nil)))
    ((and (atom (cdr i))
  (not (eq (cdr i) 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 n 1)
  (ACET-UI-PROGRESS-INIT
    "Please Wait while the Program is Running"
    (length (Flatten (progn
               (setq kk nil)
       (foreach k (vl-remove nil (FilterNestedXrefs (GetXrefNesting) mainfilter filter))
(setq k (vl-remove nil k))
(setq kk (cons k kk))
               )
       (reverse kk)
       )))
  )
  (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 / lstn k kk )
    (foreach
      i
       (setq lstn (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))
    )
(setq k 0)
(foreach i lstn
  (setq k (+ k (nestedxrefcount mainname (cdr (assoc 2 (entget (car i))))) ))
    )
(if lstn (write-line (strcat spc " *** Total count per branch : " (itoa k) " *** ") opened))
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   
  (foreach
    i
     (vl-sort
       (progn
               (setq kk nil)
       (foreach k (vl-remove nil (FilterNestedXrefs (GetXrefNesting) mainfilter filter))
(setq k (vl-remove nil k))
(setq kk (cons k kk))
               )
       (reverse kk)
       )
       (function
(lambda (a b)
   (<
     (strcase (cdr (assoc 2 (entget (car a)))))
     (strcase (cdr (assoc 2 (entget (car b)))))
   )
)
       )
     )
    (write-line
      (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))
     )
      )
    )
      )
      )
      opened
    )
    (ACET-UI-PROGRESS-SAFE n)
    (setq n (+ n 1))

    (PrintNestedList
      (if (and (/= (cadr i) nil) (cdr i))
(vl-remove nil (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"))

  (xrefs-list)

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

Regards, M.R.
« Last Edit: December 14, 2011, 06:11:03 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 #29 on: December 12, 2011, 10:53:55 PM »
Marko

Thanks again. Tried it here at home and your new code has solved the problem. Will try it at the office on more files tomorrow.

I see where you updated the code...I'm totally lost in how it works. Thanks again for you hard work and patience. This routine will be a great time saver in reviewing our project files with nested xrefs.

Gary

Updated Output File:

----------------------------------------------------------------------
        Project Name : [Merritt Lakeside Sr Village]
        Directory is: [F:\Jobs\2009\091138\acad\building\BL-Profile2]
        December 12, 2011 10:52 p.m.
----------------------------------------------------------------------

 [X] Parent Drawing: BL-Profile2

    [ ] Main Xref: BL-01 = 2 Count

       [ ] Nested Xref: UTA2 = 6 Count
       [ ] Nested Xref: UTA3 = 6 Count
       [ ] Nested Xref: UTA5 = 3 Count
       [ ] Nested Xref: UTB1 = 3 Count
       [ ] Nested Xref: UTB3b = 6 Count
       [ ] Nested Xref: UTB3c = 6 Count
       [ ] Nested Xref: UTB4a = 6 Count
       [ ] Nested Xref: UTB4b = 6 Count
           Total Count = 42 Nested/Main

    [ ] Main Xref: BL-02 = 2 Count

       [ ] Nested Xref: UTA3 = 6 Count
       [ ] Nested Xref: UTA5 = 3 Count
       [ ] Nested Xref: UTB1 = 3 Count
       [ ] Nested Xref: UTB3a = 6 Count
       [ ] Nested Xref: UTB4b = 6 Count
       [ ] Nested Xref: UTB4c = 6 Count
           Total Count = 30 Nested/Main

    [ ] Main Xref: BL-CLUB = 1 Count


 List Of Saved Xref Paths:
----------------------------------------------------------------------
 F:\Jobs\2009\091138\ACAD\building\BL-01.dwg
 F:\Jobs\2009\091138\ACAD\building\BL-02.dwg
 F:\Jobs\2009\091138\ACAD\club\BL-CLUB.dwg
 F:\Jobs\2009\091138\ACAD\units\UTA2.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB1.dwg
 F:\Jobs\2009\091138\ACAD\units\UTA5.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB3b.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB4b.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB4a.dwg
 F:\Jobs\2009\091138\ACAD\units\UTA3.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB3c.dwg
 F:\Jobs\2009\091138\acad\building\Key.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB4c.dwg
 F:\Jobs\2009\091138\ACAD\units\UTB3a.dwg







« Last Edit: December 12, 2011, 11:55:34 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