Author Topic: Make Sheet Index using obectDBX  (Read 68004 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Make Sheet Index using obectDBX
« Reply #15 on: February 09, 2006, 06:29:34 PM »
Thanks, Gary! I knew about being able to add a description to that dialog, but it never even crossed my mind to make it like that.

* Jeff_M is off to update dozens of functions that utilize that......

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make Sheet Index using obectDBX
« Reply #16 on: February 10, 2006, 08:58:35 AM »
Jeff

I still can't thank you enough. Hope you don't mind, I've added to you routine the following:

 added BrowseForFolder title and info
 added AutoCAD's progress bar while routine runs
 modified with my title block attribute "2436TBA" with values "A-01" "SHT_TTL"
 added reconstruct list coding
 added open notepad with sheet list

My next goal is to use excel in lieu of notepad, and fill in cells within the excel file. There are probably some examples out there.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;     This original Copyrighted routine has been modified...
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;function to extract 2 attribute values from a specific block in the drawings of a specified folder
;;;by Jeff Mishler Feb. 9, 2006
;;;
;;;added BrowseForFolder title and info
;;;added AutoCAD's progress bar while routine runs
;;;modified with my title block attribute "2436TBA" with values "A-01" "SHT_TTL"
;;;added reconstruct list coding
;;;added open notepad with sheet list
;;;by Gary Fowler
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun getindex (blkname attname1 attname2 / *acad atts dwgs f folder layouts masterlist name odbx val1 val2 n)
  (defun BrowseForFolder (/ sh folder parentfolder folderobject result)
    ;;as posted the autodesk discussion customization group by Tony Tanzillo
    (vl-load-com)
    (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
     "Shell.Application"
   )
    )   
    (setq folder
   (vlax-invoke-method
     sh 'BrowseForFolder 0 (strcat " SHEET INDEX" "\tSelect drawing location for ''Sheet Files''\n\t\tCreates index of all drawings in folder.\n\t\tBy: Jeff Mishler ©2006") 0)
    ) ;;added BrowseForFolder title and info
    (vlax-release-object sh)

    (if folder
      (progn
(setq parentfolder
       (vlax-get-property folder 'ParentFolder)
)
(setq FolderObject
       (vlax-invoke-method
ParentFolder
'ParseName
(vlax-get-property Folder 'Title)
       )
)
(setq result
       (vlax-get-property FolderObject 'Path)
)
(mapcar 'vlax-release-object
(list folder parentfolder folderobject)
)
result
      )
    )
  )
  (defun getdwglist (folderlist)
    (apply 'append
   (mapcar '(lambda (f)
      (mapcar '(lambda (name)
(strcat f "\\" name)
       )
      (vl-directory-files f "*.dwg" 1)
      )
    )
   folderlist
   )
    )
  )
  (if (and (setq *acad (vlax-get-acad-object))
   (setq folder (browseforfolder))
   (setq dwgs (getdwglist (list folder)))
      )
    (progn
      (setq n 1) ;;added progress bar count marker
      (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-INIT "Please Wait while the Program is Running" (length dwg))) ;;added progress bar start 
      (setq
odbx (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
       (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
       (vla-GetInterfaceObject
*acad
"ObjectDBX.AxDbDocument.16"
       )
     )
      )
      (foreach dwg dwgs
        ;;(ARCH:WORKING) ;;spinner test not used
        (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-SAFE n)) ;;added progress bar running
        (setq n (+ n 1)) ;;added progress bar count marker
(if
  (and
    (not (vl-catch-all-error-p
   (vl-catch-all-apply
     '(lambda ()
(vla-open odbx dwg)
      )
   )
)
    )
;see if the block is even in the drawing
    (not
      (vl-catch-all-error-p
(vl-catch-all-apply
  '(lambda ()
     (setq blk (vla-item (vla-get-blocks odbx) blkname))
   )
)
      )
    )
  )
   (progn
     ;;it is...carry on
     (setq layouts (vla-get-layouts odbx))
     (vlax-for layout layouts
       (if (not (eq "MODEL" (strcase (vla-get-name layout))))
(progn
   (vlax-for ent (vla-get-block layout)
     (if (and (eq (vla-get-objectname ent)
  "AcDbBlockReference"
      )
      (eq (strcase (vla-get-name ent))
  (strcase blkname)
      )
)
       (progn
(setq atts (vlax-invoke ent 'getattributes))
(foreach att atts
   (if (eq (vla-get-tagstring att)
   (strcase attname1)
       )
     (setq val1 (vla-get-textstring att))
   )
   (if (eq (vla-get-tagstring att)
   (strcase attname2)
       )
     (setq val2 (vla-get-textstring att))
   )
)
(setq masterlist
(cons (cons val1 val2) masterlist)
;(cons (list (vla-get-name odbx) (cons val1 val2)) masterlist);for testing
)
       )
     )
   )
)
       )
     )
   )
)
      )
      (mapcar 'vlax-release-object (list odbx *acad))
    )
  )
  (reverse masterlist) 
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;modified with my title block attribute "TAG" with values "A-01" "SHT_TTL"
;;;added reconstruct list coding
;;;added open notepad with sheet list
(defun ARCH:CreateIndex2436TAG (/ indexlist file)
  (setq indexlist (getindex "TAG" "A-01" "SHT_TTL"))
  (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-DONE)) ;;added progress bar finish
;|
  (princ "\n")
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (princ (car a))
    (princ "\t")
    (princ (cdr a))
    (princ "\n")
  )
|;
  (setq file (open "C:\\Temp\\SheetIndex.txt" "w"))
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (write-line (strcat (car a) "\t" (cdr a)) file)
  )
  (close file)
  (command ".shell" "notepad C:\\Temp\\SheetIndex.txt")
)
;;;
(defun ARCH:CreateIndex2436TBA (/ indexlist file)
  (setq indexlist (getindex "2436TBA" "A-01" "SHT_TTL"))
  (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-DONE)) ;;added progress bar finish
;|
  (princ "\n")
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (princ (car a))
    (princ "\t")
    (princ (cdr a))
    (princ "\n")
  )
|;
  (setq file (open "C:\\Temp\\SheetIndex.txt" "w"))
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (write-line (strcat (car a) "\t" (cdr a)) file)
  )
  (close file)
  (command ".shell" "notepad C:\\Temp\\SheetIndex.txt")
)
;;;
(defun ARCH:CreateIndex3042TBA (/ indexlist file)
  (setq indexlist (getindex "3042TBA" "A-01" "SHT_TTL"))
  (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-DONE)) ;;added progress bar finish
;|
  (princ "\n")
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (princ (car a))
    (princ "\t")
    (princ (cdr a))
    (princ "\n")
  )
|;
  (setq file (open "C:\\Temp\\SheetIndex.txt" "w"))
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (write-line (strcat (car a) "\t" (cdr a)) file)
  )
  (close file)
  (command ".shell" "notepad C:\\Temp\\SheetIndex.txt")
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)
;;;(ARCH:CreateIndex2436TAG)
;;;(ARCH:CreateIndex2436TBA)
;;;(ARCH:CreateIndex3042TBA)
[\code]

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: Make Sheet Index using obectDBX
« Reply #17 on: February 10, 2006, 09:06:41 AM »
Allen

Thanks for the cleaner list formatting. I am the worst when it comes to handling lists.

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

whdjr

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #18 on: February 10, 2006, 09:39:11 AM »
...

My next goal is to use excel in lieu of notepad, and fill in cells within the excel file. There are probably some examples out there.
...

Gary,

Try this for starters.

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Make Sheet Index using obectDBX
« Reply #19 on: February 10, 2006, 09:41:48 AM »
Jeff

I still can't thank you enough. Hope you don't mind,
<snip>
Not at all.....recall what I posted with the original code:
Quote
See if this will do what you want....or at least get you close
it was my intention to get the basic code for what you needed and left it up to you how the returned data was used. :-D And I think you've done quite well!

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make Sheet Index using obectDBX
« Reply #20 on: February 10, 2006, 09:59:48 AM »
Thanks WHDJR

Thanks for the link......I have a lot to study up on this weekend.

p.s. what is your first name?

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

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Make Sheet Index using obectDBX
« Reply #21 on: February 10, 2006, 10:22:34 AM »
Gary, check his sig line......

whdjr

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #22 on: February 10, 2006, 10:26:06 AM »

p.s. what is your first name?

Gary


It's a secret...I could tell you but you know what would happen... :-D

What Jeff said. :wink:

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make Sheet Index using obectDBX
« Reply #23 on: February 10, 2006, 11:02:19 AM »
Will

You know i wear trifocals..............

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

whdjr

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #24 on: February 10, 2006, 11:06:27 AM »
That means 3 times better than me right?

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make Sheet Index using obectDBX
« Reply #25 on: February 10, 2006, 03:40:23 PM »
Jeff

I have another question for you. How would you modify your example to handle 2 attributed blocks, each having two values?
Already have the first attributed block for No. and Title.... second attributed block would be for Date and # (if block exist). I'm
looking but need some hints.

The routine wold need to go thru each sheet as before and give the following results:

Date                         #    No.        Title
----------------------------------------------------------------------
12 Feb 2006   1    A0.00     Cover

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: Make Sheet Index using obectDBX
« Reply #26 on: February 10, 2006, 04:04:32 PM »
Jeff

This is my first attemp....as you can see, this is not what I want. I'm trying.

Code: [Select]
(defun getfolder ()
  (defun BrowseForFolder (/ sh folder parentfolder folderobject result)
    ;;as posted the autodesk discussion customization group by Tony Tanzillo
    (vl-load-com)
    (setq sh
   (vla-getInterfaceObject
     (vlax-get-acad-object)
     "Shell.Application"
   )
    )
    (if (not ARCH#LOGO)(setq ARCH#LOGO " Your Logo"))
    (setq folder
   (vlax-invoke-method
     sh 'BrowseForFolder 0 (strcat ARCH#LOGO " : Select drawing location for ''Sheet Files''\n\t\t  Creates index of all drawings in folder.\n\t\t  By: Jeff Mishler ©2006") 0)
    ) ;;added BrowseForFolder title and info
    (vlax-release-object sh)

    (if folder
      (progn
(setq parentfolder
       (vlax-get-property folder 'ParentFolder)
)
(setq FolderObject
       (vlax-invoke-method
ParentFolder
'ParseName
(vlax-get-property Folder 'Title)
       )
)
(setq result
       (vlax-get-property FolderObject 'Path)
)
(mapcar 'vlax-release-object
(list folder parentfolder folderobject)
)
result
      )
    )
  )
  (defun getdwglist (folderlist)
    (apply 'append
   (mapcar '(lambda (f)
      (mapcar '(lambda (name)
(strcat f "\\" name)
       )
      (vl-directory-files f "*.dwg" 1)
      )
    )
   folderlist
   )
    )
  )
  (setq gotfolder (browseforfolder))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun getindex (blkname attname1 attname2 / *acad atts dwgs f folder layouts masterlist name odbx val1 val2 n)
  (if (and (setq *acad (vlax-get-acad-object))
   ;;(setq folder (browseforfolder))
           (setq folder gotfolder)
   (setq dwgs (getdwglist (list folder)))
      )
    (progn
      (setq n 1) ;;added progress bar count marker
      (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-INIT "Please Wait while the Program is Running" (length dwg))) ;;added progress bar start 
      (setq
odbx (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
       (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
       (vla-GetInterfaceObject
*acad
"ObjectDBX.AxDbDocument.16"
       )
     )
      )
      (foreach dwg dwgs
        ;;(ARCH:WORKING) ;;spinner test not used
        (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-SAFE n)) ;;added progress bar running
        (setq n (+ n 1)) ;;added progress bar count marker
(if
  (and
    (not (vl-catch-all-error-p
   (vl-catch-all-apply
     '(lambda ()
(vla-open odbx dwg)
      )
   )
)
    )
;see if the block is even in the drawing
    (not
      (vl-catch-all-error-p
(vl-catch-all-apply
  '(lambda ()
     (setq blk (vla-item (vla-get-blocks odbx) blkname))
   )
)
      )
    )
  )
   (progn
     ;;it is...carry on
     (setq layouts (vla-get-layouts odbx))
     (vlax-for layout layouts
       (if (not (eq "MODEL" (strcase (vla-get-name layout))))
(progn
   (vlax-for ent (vla-get-block layout)
     (if (and (eq (vla-get-objectname ent)
  "AcDbBlockReference"
      )
      (eq (strcase (vla-get-name ent))
  (strcase blkname)
      )
)
       (progn
(setq atts (vlax-invoke ent 'getattributes))
(foreach att atts
   (if (eq (vla-get-tagstring att)
   (strcase attname1)
       )
     (setq val1 (vla-get-textstring att))
   )
   (if (eq (vla-get-tagstring att)
   (strcase attname2)
       )
     (setq val2 (vla-get-textstring att))
   )
)
(setq masterlist
(cons (cons val1 val2) masterlist)
;(cons (list (vla-get-name odbx) (cons val1 val2)) masterlist);for testing
)
       )
     )
   )
)
       )
     )
   )
)
      )
      (mapcar 'vlax-release-object (list odbx *acad))
    )
  )
  (reverse masterlist) 
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun C:TBA (/ indexlist padout) 
  (getfolder)
  (setq indexlist1 (getindex "2436TBA" "A-01" "SHT_TTL"))
  (setq indexlist2 (getindex "IAADD" "XX" "X")) 
  (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-DONE)) ;;added progress bar finish
  (princ) 
)

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

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #27 on: February 10, 2006, 04:30:48 PM »
Gary
You can make this a reusable function like this.
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;modified with my title block attribute "TAG" with values "A-01" "SHT_TTL"
;;;added reconstruct list coding
;;;added open notepad with sheet list
(defun ARCH:CreateIndex (blkname attname1 attname2 / indexlist file)
  (setq indexlist (getindex blkname attname1 attname2))
  (if (member "acetutil.arx" (arx))(ACET-UI-PROGRESS-DONE)) ;;added progress bar finish
  (setq file (open "C:\\Temp\\SheetIndex.txt" "w"))
  (repeat
    (length indexlist)
    (setq a (car indexlist) indexlist (cdr indexlist))
    (write-line (strcat (car a) "\t" (cdr a)) file)
  )
  (close file)
  (command ".shell" "notepad C:\\Temp\\SheetIndex.txt")
)
;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(princ)

(ARCH:CreateIndex  "TAG" "A-01" "SHT_TTL") ; 2436TAG

(ARCH:CreateIndex "2436TBA" "A-01" "SHT_TTL") ; 2436TBA

(ARCH:CreateIndex "3042TBA" "A-01" "SHT_TTL") ; 3042TBA
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make Sheet Index using obectDBX
« Reply #28 on: February 10, 2006, 04:54:01 PM »
Allen

My head hurts.
Thanks, but now how would I use the routine for compiling the list using the two blocks so that I would have only one list?

(setq indexlist1 (getindex "2436TBA" "A-01" "SHT_TTL")) ;first block
(setq indexlist2 (getindex "IAADD" "XX" "X")) ;second block

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

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Make Sheet Index using obectDBX
« Reply #29 on: February 10, 2006, 05:04:38 PM »
If you want to check while in the same drawing for different blocks, then change this area.
Code: [Select]
(if (and (eq (vla-get-objectname ent)
  "AcDbBlockReference"
      )
      (eq (strcase (vla-get-name ent))
  (strcase blkname)
      )
)
to
Code: [Select]
(if
 (and
  (eq (vla-get-objectname ent) "AcDbBlockReference" )
  (vl-position (strcase (vla-get-name ent)) BlkNameList)
 )
Then enter in just a list of block names, in all capitols, when calling the sub.
Tim

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

Please think about donating if this post helped you.