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

0 Members and 5 Guests are viewing this topic.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #135 on: January 29, 2010, 06:30:12 PM »
Lee, your nose is welcome around here. 8-)

Thanks CAB

BTW I got a missing ) in your post.

Oops! Code updated  :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #136 on: January 29, 2010, 06:36:04 PM »
One more got ya 8-)
Command: createindex
; error: bad argument type: VLA-OBJECT nil
; reset after error

Code: [Select]
     (mapcar 'vlax-release-object (list odbx *acad))
odbx is nil in my test, it is processing the Open DWG.

Off to dinner, see ya later.


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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #137 on: January 29, 2010, 07:25:29 PM »
One more got ya 8-)
Command: createindex
; error: bad argument type: VLA-OBJECT nil
; reset after error

Code: [Select]
      (mapcar 'vlax-release-object (list odbx *acad))
odbx is nil in my test, it is processing the Open DWG.

Off to dinner, see ya later.





 :oops:  I really should test these things before posting - but not being a draftsman myself, I don't exactly have a set of drawings that I can readily test it on... so most of my code is 'theoretical'...   :wink:  Anyway, code updated, hopefully it is OK now...

Thanks CAB, enjoy your meal  :-)
« Last Edit: January 29, 2010, 07:30:15 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #138 on: January 29, 2010, 09:49:46 PM »
Well you nailed that time. 8-)

Code: [Select]
Command: createindex

Russell-3   2       FLOOR     PLAN
Russell-4   1       FLOOR     PLAN
Russell-4   2       ELEVATIONS   PLAN
Russell-4   3       ELEVATIONS   PLAN
Russell-4   4       ELECTRICAL   PLAN
Russell-4   5       FOUNDATION   PLAN
Russell-4   6       FRAMING       PLAN
Russell-5   1       FLOOR     PLAN
Russell-5   2       ELEVATIONS   PLAN
Russell-5   3       ELEVATIONS   PLAN
Russell-5   4       ELECTRICAL   PLAN
Russell-5   5       FOUNDATION   PLAN
Russell-5   6       FRAMING       PLAN
Russell-6   1       FLOOR     PLAN
Russell-6   2       ELEVATIONS   PLAN
Russell-6   3       ELEVATIONS   PLAN
Russell-6   4       ELECTRICAL   PLAN
Russell-6   5       FOUNDATION   PLAN
Russell-6   6       FRAMING       PLAN
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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #139 on: January 30, 2010, 06:28:24 AM »
Excellent :-)  Thanks

GDF

  • Water Moccasin
  • Posts: 2081
Re: Make Sheet Index using obectDBX
« Reply #140 on: January 30, 2010, 11:09:45 AM »
I would use this to handle other versions:

             (setq odbxdoc
                (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
                  (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
                  (vla-GetInterfaceObject
                    (vlax-get-acad-object)
                    (strcat "ObjectDBX.AxDbDocument." oVer))))
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Vince

  • Newt
  • Posts: 55
Re: Make Sheet Index using obectDBX
« Reply #141 on: February 01, 2010, 09:02:20 AM »
You are using the wrong version of the routine.
Use this:
Code: [Select]
;|
  function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006
  And kindly edited by Tim Willey to extract any number of attributes
  |;

(defun getindex   (blkname attList / *acad atts dwgs f folder layouts masterlist name odbx)
  (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 "" 0))
    (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 attList (mapcar '(lambda (x) (cons x "")) attList))
  (if (and (setq *acad (vlax-get-acad-object))
            (setq folder (browseforfolder))
            ;(setq folder "C:\\Program Files\\ACAD2000\\=Active Projects\\Steve Carter\\Russell")
            (setq dwgs (getdwglist (list folder)))
      )
    (progn
      (setq
         odbx (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
                (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
                (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.17")
              )
      )
      (foreach dwg dwgs
         (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 (setq tempList (assoc (vla-get-TagString att) attList))
                                (setq attList
                                        (subst (cons (car tempList) (vla-get-TextString att))
                                                tempList
                                                attList
                                        )
                                )
                              )
                            )
                            (setq masterlist
                                    (cons (cons (vl-filename-base (vla-get-Name odbx)) attList)
                                          masterlist
                                    )
                                             ;(cons (cons (cons (cons val1 val2) val3) val4) masterlist)
                                             ;(cons (list (vla-get-name odbx) (cons val1 val2)) masterlist);for testing
                            )
                         )
                       )
                     )
                   )
                )
              )
            )
         )
      )
      (mapcar 'vlax-release-object (list odbx *acad))
    )
  )
  (reverse masterlist)
)

CAB,

Thank you for your assistance......the code ran successfully this time however, In the "indexlist" section I specified the block name and 4 attributes and the index that was created had the file name and only 1 attribute.....plus the index that was created contained some duplicates. The directory had only 16 drawing files and the created index contained 20 lines.

Any thoughts on what I might be doing incorrectly....??


Regards,
Vince

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #142 on: February 01, 2010, 09:52:54 AM »
Please post the index list that was created.

My first thought is that the block in some drawings does not have a matching attribute or the attribute is blank.
If it is blank it should still print a line with the DWG name.
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.

Vince

  • Newt
  • Posts: 55
Re: Make Sheet Index using obectDBX
« Reply #143 on: February 01, 2010, 11:20:59 AM »
Please post the index list that was created.

My first thought is that the block in some drawings does not have a matching attribute or the attribute is blank.
If it is blank it should still print a line with the DWG name.


CAB,

Here is a copy of the index list that was created.....!

Command: createindex

P0001-S-001     S-001
P0001-S-101     S-101
P0001-S-102     S-102
P0001-S-201     S-201
P0001-S-301     S-301
P0001-S-302     S-302
P0001-S-302     S-302C
P0001-S-302     S-302P
P0001-S-303     S-303
P0001-S-304     S-304
P0001-S-305     S-305
P0001-S-306     S-306
P0001-S-307     S-307
P0001-S-308     S-308
P0001-S-309     S-302C
P0001-S-309     S-302P
P0001-S-309     S-309
P0001-S-310     S-310
P0001-S-401     S-401
P0001-S-402     S-402

I checked the block in all of the drawing files and it is the correct block however, on all of the drawings there are 3 attributes for the title of the sheet and the first attribute (in this test case) is always blank. But I thought the routine would pickup the second or third attributes.....??

I hope this is helpful.....??


Regards,
Vince

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #144 on: February 01, 2010, 05:57:10 PM »
Give this one a try.
The attribute tags supplied needed to be forced Tags strings to all upper case.

Code: [Select]
;;  http://www.theswamp.org/index.php?topic=8661.msg351362#msg351362
;;  Note it will not process any open drawings


;|
  function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006
  And kindly edited by Tim Willey to extract any number of attributes

  Modified by Lee Mac to process open drawings
  Modified by CAB forced Tags to match to Tags strings in all upper case
  |;

(defun getindex   (blkname attList / *acad atts dwgs err f flag folder layouts masterlist name odbx odbxdoc)
  (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 "" 0))
    (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 attList (mapcar '(lambda (x) (cons (strcase x) "")) attList)) ; CAB forced to upper case
  (if (and (setq *acad (vlax-get-acad-object))
            ;(setq folder (browseforfolder))
            (setq folder "C:\\Program Files\\ACAD2000\\=Active Projects\\Steve Carter\\Russell")
            ;(setq folder "C:\\Program Files\\ACAD2000\\Working")
            (setq dwgs (getdwglist (list folder)))
      )
    (progn
             (setq odbxdoc
                (if (< (atoi (setq oVer (substr (getvar "acadver") 1 2))) 16)
                  (vla-GetInterfaceObject (vlax-get-acad-object) "ObjectDBX.AxDbDocument")
                  (vla-GetInterfaceObject (vlax-get-acad-object) (strcat "ObjectDBX.AxDbDocument." oVer))))

      (vlax-for doc (vla-get-Documents *acad)
        (setq DocLst (cons (cons (strcase (vla-get-FullName doc)) doc) DocLst)))
     
      (foreach dwg dwgs

        (setq flag (and (setq odbx (cdr (assoc (strcase dwg) DocLst)))))

        (or odbx
            (and (setq Err (vl-catch-all-apply
                             (function vla-open) (list odbxdoc dwg)) odbx odbxdoc)))

       
         (if
           (and
             (or flag
                 (not (vl-catch-all-error-p err)))
             ;; 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 (setq tempList (assoc (strcase(vla-get-TagString att)) attList)) ; CAB force CAPS
                                (setq attList
                                        (subst (cons (car tempList) (vla-get-TextString att))
                                                tempList
                                                attList
                                        )
                                )
                              )
                            )
                            (setq masterlist
                                    (cons (cons (vl-filename-base (vla-get-Name odbx)) attList)
                                          masterlist
                                    )
                                             ;(cons (cons (cons (cons val1 val2) val3) val4) masterlist)
                                             ;(cons (list (vla-get-name odbx) (cons val1 val2)) masterlist);for testing
                            )
                         )
                       )
                     )
                   )
                )
              )
            )
         )
      )
      (mapcar
        (function
          (lambda (x) (and x (not (vlax-object-released-p x))
                           (vlax-release-object x))))
        (list odbxdoc odbx *acad))
    )
  )
  (reverse masterlist)
)
« Last Edit: February 03, 2010, 02:57:52 PM by CAB »
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.

jaydee

  • Guest
Re: Make Sheet Index using obectDBX
« Reply #145 on: November 14, 2011, 07:36:54 AM »
Quote
  function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006
  And kindly edited by Tim Willey to extract any number of attributes

  Modified by Lee Mac to process open drawings
  Modified by CAB forced Tags to match to Tags strings in all upper case

Hi.
I love this getindex routine using odbx
Is anyone able help to mod the (getindex) routine above to just read and process the current drawing folder WITHOUT having to open the browser window.

I tried to mod this part of codes and rem out (browseforfolder) subfunction, but it wouldn't read open drawings, which i like to keep Modified by Lee Mac to process open drawings
We have a very deep cad folder tree, 8 level deep and what i find most efficient is open a drawing and make index of the same folder.

Thankyou
Code: [Select]
  (if (and (setq *acad (vlax-get-acad-object))
            ;(setq folder (browseforfolder))
            (setq folder (getvar "dwgprefix"))
            (setq dwgs (getdwglist (list folder)))
      )
[/code



« Last Edit: November 14, 2011, 07:47:40 AM by jaydee »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #146 on: November 14, 2011, 08:11:48 AM »
Here is a completely rewritten version:

Supply it with the directory to process, block name and attribute tag list.

Code: [Select]
;|
  function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006
  And kindly edited by Tim Willey to extract any number of attributes

  Modified by Lee Mac to process open drawings
  Modified by CAB forced Tags to match to Tags strings in all upper case
 
  Rewritten by Lee Mac 14.11.2011 to process a directory supplied as an argument.
|;

(defun getindex ( directory blknme attlst / acapp acdocs dbx doc lst pair result tmp x )

    (setq attlst (mapcar '(lambda ( x ) (cons (strcase x) "")) attlst)
          blknme (strcase blknme)
    )
    (if
        (and
            (vl-file-directory-p
                (setq directory
                    (vl-string-right-trim "\\" (vl-string-translate "/" "\\" directory))
                )
            )
            (setq lst
                (mapcar
                    (function
                        (lambda ( x ) (strcat directory "\\" x))
                    )
                    (vl-directory-files directory "*.dwg" 1)
                )
            )
        )
        (progn
            (setq acapp (vlax-get-acad-object))
            (vlax-for doc (vla-get-documents acapp)
                (setq acdocs (cons (cons (strcase (vla-get-fullname doc)) doc) acdocs))
            )
            (setq dbx (LM:ObjectDBXDocument acapp))
            (foreach dwg lst
                (if
                    (and
                        (setq doc
                            (cond
                                (   (cdr (assoc (strcase dwg) acdocs)))
                                (   (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-open (list dbx dwg)))) dbx)
                            )
                        )
                        (not
                            (vl-catch-all-error-p
                                (vl-catch-all-apply 'vla-item (list (vla-get-blocks doc) blknme))
                            )
                        )
                    )
                    (vlax-for layout (vla-get-layouts doc)
                        (if (not (eq "MODEL" (strcase (vla-get-name layout))))
                            (vlax-for obj (vla-get-block layout)
                                (if
                                    (and
                                        (eq "AcDbBlockReference" (vla-get-objectname obj))
                                        (eq blknme
                                            (if (vlax-property-available-p obj 'effectivename)
                                                (strcase (vla-get-effectivename obj))
                                                (strcase (vla-get-name obj))
                                            )
                                        )
                                        (eq :vlax-true (vla-get-hasattributes obj))
                                    )
                                    (progn
                                        (setq tmp attlst)
                                        (foreach att (vlax-invoke obj 'getattributes)
                                            (if (setq pair (assoc (strcase (vla-get-tagstring att)) tmp))
                                                (setq tmp  (subst (cons (car pair) (vla-get-textstring att)) pair tmp))
                                            )
                                        )
                                        (setq result (cons (cons (vl-filename-base dwg) tmp) result))
                                    )
                                )
                            )
                        )
                    )
                )
            )
            (foreach obj (list doc dbx acapp)
                (if (and obj (eq 'VLA-OBJECT (type obj)) (not (vlax-object-released-p obj)))
                    (vlax-release-object obj)
                )
            )
        )
    )
    (reverse result)
)

(defun LM:ObjectDBXDocument ( acapp / acver )
    (vla-GetInterfaceObject acapp
        (if (< (setq acver (atoi (getvar "ACADVER"))) 16)
            "ObjectDBX.AxDbDocument"
            (strcat "ObjectDBX.AxDbDocument." (itoa acver))
        )
    )
)

Untested, so I hope I haven't missed anything...

mkweaver

  • Bull Frog
  • Posts: 352
Re: Make Sheet Index using obectDBX
« Reply #147 on: November 14, 2011, 08:49:58 AM »
Nice thread.

I'm coming at this from just about exactly the opposite direction.  We create a table with a list of drawing numbers (which match the filename).  I then have a routine that will read this table, go out and find all of the drawings in the list, read their title blocks and bring the contents back into the original table.  I have the routine reading about 3 drawings per second.

Once I got the routine for reading the data from the drawings it opened up several possibilities.  For example, I built a routine that would read the drawing index and create a dsd file (for loading into the publish dialog) and automatically publish all of the drawings.

I like objectdbx:-)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #148 on: November 14, 2011, 08:51:30 AM »

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Make Sheet Index using obectDBX
« Reply #149 on: November 14, 2011, 09:05:45 AM »
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io