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

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #120 on: January 28, 2010, 07:43:24 PM »
One note, it will not process any open drawings!
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: 12906
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #121 on: January 28, 2010, 07:56:43 PM »
One note, it will not process any open drawings!

I haven't followed this thread completely, but I had to also get around the problem of processing open drawings in the Attribute Extractor, you may want to refer to the code if it helps  :wink:

http://www.theswamp.org/index.php?topic=29124.0

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #122 on: January 28, 2010, 08:26:46 PM »
I must be too tired but I didn't see where you opened a DWG file as read only.

Off to hunt for some dinner. 8-)
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: 12906
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #123 on: January 28, 2010, 09:50:46 PM »
I must be too tired but I didn't see where you opened a DWG file as read only.

Off to hunt for some dinner. 8-)


I make a list of the open documents in the session, and check against this list before Opening an ODBX Document. The open document object can then be used in place of the dbx document object.

I tried using vla-open/close on the open document to open it as read-only, but found that this was unnecessary.

Hope this helps! :-)

Lee

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #124 on: January 28, 2010, 11:34:33 PM »
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 #125 on: January 29, 2010, 09:01:44 AM »
OK for my use I did this:
Code: [Select]
(defun c:CreateIndex (/ indexlist StrList SortByIndex)

;;  CAB 07/17/09
;;  sort list given the position order to sort on
;;  positions may be ignored by omitting them from the order list
(defun SortByIndex (lst order / iidx)
  (setq len (length order))
  (vl-sort lst
           '(lambda (e1 e2 / idx)
              (setq idx -1)
              (while
                (and
                  (< (setq idx (1+ idx)) len)
                  (setq iidx (nth idx order))
                  (= (nth iidx e1) (nth iidx e2))
                )
              )
              (< (nth iidx e1) (nth iidx e2))
            )
  )
)
  
  (setq indexlist (getindex "Aproved Title Block D- Attr" '("SheetNo" "TITLE1" "TITLE2")))

  ;;  pre process the sub lists by flattening them to strings only
  ;;  then remove leading & trailing space, tab & CR
  ;;  then sort on 1st & 2nd items in the list
  (if indexlist
    (progn
      (setq StrList (mapcar '(lambda(dwg)
      (cons (car dwg) (mapcar 'cdr (cdr dwg)))
      ) indexlist))
      (setq StrList (mapcar '(lambda(dwg)
      (mapcar '(lambda(str)(vl-string-trim " \t\n" str)) dwg))
      StrList)
   StrList (SortByIndex StrList '(0 1)))
    )
      
  )

  ;;  Print the list
  (princ "\n")
  (foreach dwg StrList
    (mapcar '(lambda (str) (princ str) (princ "\t")) dwg)
    (princ "\n")
    (princ)
  )
)

When I try to use this I get a "Too Few Arguments" error..........what am I doing wrong....??


Regards,
Vince

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #126 on: January 29, 2010, 09:21:01 AM »
That was for MY block
Code: [Select]
  (setq indexlist (getindex "Aproved Title Block D- Attr" '("SheetNo" "TITLE1" "TITLE2")))
Change for YOUR block:
Code: [Select]
  (setq indexlist (getindex "Drawing-Title" '("NUM" "Title-1" "Title-2" "Title-3")))
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 #127 on: January 29, 2010, 10:07:54 AM »
That was for MY block
Code: [Select]
  (setq indexlist (getindex "Aproved Title Block D- Attr" '("SheetNo" "TITLE1" "TITLE2")))
Change for YOUR block:
Code: [Select]
  (setq indexlist (getindex "Drawing-Title" '("NUM" "Title-1" "Title-2" "Title-3")))

CAB,

I updated the code for my block name but I am still getting the "too few arguments" error.....!


Thanks,
Vince

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #128 on: January 29, 2010, 10:22:48 AM »
Run from VLIDE. At the command line enter VLIDE
From the pull down menus at the top select File/Open
Navigate to this new lisp & load it.

Left click in that window with the new lisp to make sure it is active.

From the pull down menus at the top select Debug & make sure the "Break on Error" is checked.
From the pull down menus at the top select Tools/Enviornmental Options/General
Activate the Diagnostic Tab
Check Report statistics...
Check Print notification ...
Check Echo PRINx ....
Check Inspect drawings....

From the pull down menus at the top select Tools/Load Text in Editor

In the Visual Lisp Console window you should see something liske this:
; 2 forms loaded from #<editor "C:/Program Files/ACAD2000/LISP Routines/Title Block Index CAB.LSP">
_$

It will reflect your path, not the one shown here.

Activate ACAD & run the routine again.
Please post the output at the command line.
If you are taken back to VLIDE   Press [Ctrl+F9] and tell me the line that is highlighted.
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 #129 on: January 29, 2010, 03:26:58 PM »
Run from VLIDE. At the command line enter VLIDE
From the pull down menus at the top select File/Open
Navigate to this new lisp & load it.

Left click in that window with the new lisp to make sure it is active.

From the pull down menus at the top select Debug & make sure the "Break on Error" is checked.
From the pull down menus at the top select Tools/Enviornmental Options/General
Activate the Diagnostic Tab
Check Report statistics...
Check Print notification ...
Check Echo PRINx ....
Check Inspect drawings....

From the pull down menus at the top select Tools/Load Text in Editor

In the Visual Lisp Console window you should see something liske this:
; 2 forms loaded from #<editor "C:/Program Files/ACAD2000/LISP Routines/Title Block Index CAB.LSP">
_$

It will reflect your path, not the one shown here.

Activate ACAD & run the routine again.
Please post the output at the command line.
If you are taken back to VLIDE   Press [Ctrl+F9] and tell me the line that is highlighted.

CAB,

I followed your instructions and on the command line I received....too few arguments......then I hit [Ctrl+F9] and the lines below were highlighted......I hope this was helpful....!


;|function to extract 2 attribute values from a specific block in the drawings of a specified folder
  by Jeff Mishler Feb. 9, 2006 |;
(defun getindex   (blkname attname1 attname2 attname3 attname4 / *acad atts dwgs f folder layouts masterlist name odbx val1 val2 val3 val4)
  (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
      )
    )
  )
  (if (and (setq *acad (vlax-get-acad-object))
      (setq folder (browseforfolder))
      (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 (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))
            )
            (if (eq (vla-get-tagstring att)
               (strcase attname3)
                )
              (setq val3 (vla-get-textstring att))
            )
            (if (eq (vla-get-tagstring att)
               (strcase attname4)
                )
              (setq val4 (vla-get-textstring att))
            )
         )
         (setq 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)
)



Thanks, Vince

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #130 on: January 29, 2010, 03:38:26 PM »
I see the problem.
I'll get back to you soon.
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #131 on: January 29, 2010, 03:47:16 PM »
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)
)
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: 12906
  • London, England
Re: Make Sheet Index using obectDBX
« Reply #132 on: January 29, 2010, 04:18:43 PM »
I hope you don't mind me sticking my nose in, but hopefully this will process open drawings:

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
  |;

(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 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
         odbxdoc (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
                   (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
                   (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.17")
              )
      )

      (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 (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
        (function
          (lambda (x) (and x (not (vlax-object-released-p x))
                           (vlax-release-object x))))
        (list odbxdoc odbx *acad))
    )
  )
  (reverse masterlist)
)

PS>  Haven't tested it, but are you sure that you can use the same ODBX document instance for each drawing? I tried that logic on my program and I can't seem to get it to function without creating a new ODBX doc for each drawing that is opened.
« Last Edit: January 29, 2010, 07:38:37 PM by Lee Mac »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Make Sheet Index using obectDBX
« Reply #133 on: January 29, 2010, 04:55:28 PM »
PS>  Haven't tested it, but are you sure that you can use the same ODBX document instance for each drawing? I tried that logic on my program and I can't seem to get it to function without creating a new ODBX doc for each drawing that is opened.

Yes.  Once you open the document with ODBX, it is that new document, and the old one is closed.

The process I use is:
Get the interface object for ODBX
Use that interface to open each drawing
Do what I need to said drawing
Save if I want
After all drawings have been processed, release the ONE odbx interface object referenced.
Tim

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

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Make Sheet Index using obectDBX
« Reply #134 on: January 29, 2010, 06:27:25 PM »
Lee, your nose is welcome around here. 8-)

BTW I got a missing ) in your post.
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.