Author Topic: Objectdbx all Xrefs within Folder  (Read 6875 times)

0 Members and 1 Guest are viewing this topic.

GDF

  • Water Moccasin
  • Posts: 2081
Objectdbx all Xrefs within Folder
« on: August 30, 2006, 10:02:14 AM »
Ok, please don't laugh, but I am stuck and need help with this. I am trying to use Tim Willey's
ReloadBindXrefs routine in an objectdbx function to bind all xrefs within the folder selected.

Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MsgBox.lsp (c) 2001-2003, John F. Uhden, Cadlantic/CADvantage
;; A cute little utility to invoke a VBA message box and return a
;; value to AutoLisp.
;; Requires AutoCAD 2000 (R15) or higher.
;; The buttons are a Boolean value representing a logical sum of
;; the following values:
;;--------------------------------------------------------
;; MsgBox(prompt[, buttons][, title][, helpfile, context])
;; Buttons:
;; vbOKOnly    0 Display OK button only.
;; vbOKCancel    1 Display OK and Cancel buttons.
;; vbAbortRetryIgnore    2 Display Abort, Retry, and Ignore buttons.
;; vbYesNoCancel    3 Display Yes, No, and Cancel buttons.
;; vbYesNo    4 Display Yes and No buttons.
;; vbRetryCancel    5 Display Retry and Cancel buttons.
;; vbCritical   16 Display Critical Message icon.
;; vbQuestion   32 Display Warning Query icon.
;; vbExclamation   48 Display Warning Message icon.
;; vbInformation   64 Display Information Message icon.
;; vbDefaultButton1    0 First button is default.
;; vbDefaultButton2  256 Second button is default.
;; vbDefaultButton3  512 Third button is default.
;; vbDefaultButton4  768 Fourth button is default.
;; vbApplicationModal    0 Application modal; the user must respond to the
;; message box before continuing work in the current application.
;; vbSystemModal 4096 System modal; all applications are suspended until the
;; user responds to the message box.
;;
;; Revised (01-27-03) thanks to Ed Jobe's contribution about snagging the return value.
;;
;;(ARCH:MsgBox "Title" 64 "Message")
;;
(defun ARCH:MsgBox (Title Buttons Message / useri1 value)
  (vl-load-com)
  (or *acad* (setq *acad* (vlax-get-acad-object)))
  (setq useri1 (getvar "useri1"))
  (acad-push-dbmod)
  (vla-eval
    *acad*
    (strcat
      "ThisDrawing.SetVariable \"USERI1\","
      "MsgBox (\""
      Message
      "\","
      (itoa Buttons)
      ",\""
      Title
      "\")"
    )
  )
  (setq value (getvar "useri1"))
  (setvar "useri1" useri1)
  (acad-pop-dbmod)
  value)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;function to extract 2 attribute values from a specific block in the drawings of a specified folder
;;;by Jeff Mishler Feb. 9, 2006
;;;
;;;new functions and rewrite by Allen Butler
;;;
;;;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
;;;now gets date from titleblock "xrefed" drawing file
;;;by Gary Fowler
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;pulled out this function from getindex below
(defun getfolder ()
  (defun BrowseForFolder (/ sh parentfolder folderobject result folder)
    ;;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  Xref Bind of all drawings in folder.\n\t\t  By: Tim Willey") 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
   )
    )
  )
  (browseforfolder)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun getindex  (folder)
  (if (and (setq *acad (vlax-get-acad-object))
            folder
   (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.16")))
      (foreach
             dwg  dwgs       
      (mapcar 'vlax-release-object (list odbx *acad))))
    )
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Subroutines ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;by Tim Willey 8/24/06
(defun ReloadBindXrefs (Doc / XrefList LstLen TroubleList)
  (vlax-for
Blk  (vla-get-Blocks Doc)
    (if (= (vla-get-IsXref Blk) :vlax-true)
      (progn
(if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Reload (list Blk)))
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Detach (list Blk)))
    (setq TroubleList (cons Blk TroubleList))
    (prompt (strcat "\n Detached xref: " (vla-get-Name Blk))))
  (progn (vla-Bind Blk :vlax-true)
(if (and (= (vla-get-IsXref Blk) :vlax-true)
  (not (vl-position (vla-get-Name Blk) XrefList)))
   (setq XrefList (cons Blk XrefList))))))))
  (setq LstLen (length XrefList))
  (while (and (> LstLen 0) (> LstLen (setq LstLen (length XrefList))))
    (foreach
   Blk XrefList
      (if (or (= (vla-get-IsXref Blk) :vlax-false)
      (and (vla-Bind Blk :vlax-true) (= (vla-get-IsXref Blk) :vlax-true)))
(setq XrefList (vl-remove Blk XrefList)))))
  (foreach
Blk  (append XrefList TroubleList)
    (prompt (strcat "\n Unable to bind xref: " (vla-get-Name Blk))))
  (princ))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Main Function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ReloadBindXrefsIT ()
  (setq Result
(ARCH:WARNING-5
"Bind Insert"
"     Bind ALL found Xrefs within the current\n"
"     Drawing, ignors xrefs not found.\n\n"
"     [ Yes ]\t  to continue on...\n"
"     [ No ]\t  not at this time."
""
)
  )
  (cond
    ((= result 0)(c:xxx))
    ((= result 1)(prompt "\n*** ///////// Program  CANCELLED ///////// ***"))
  )
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun C:TEST  () 
  (setq folder (getfolder))
  (setq indexlist (getindex folder))   
 
  (foreach dwg dwgs 
    (ReloadBindXrefs (vla-get-ActiveDocument (vlax-get-Acad-Object))) ;;calling Tims function
  )

  (princ))

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: Objectdbx all Xrefs within Folder
« Reply #1 on: August 30, 2006, 12:18:38 PM »
What you would do is (if you want to work on all drawings within the directory)
Get the folder
(setq DirPath (getfolder))
Then you would step through each file, open it with ObjectDBX, and run my routine on it, and then save it.
So I would do something like
Code: [Select]
(defun c:Test (/ DirPath odbx FullPath)

(if
 (and
  (setq DirPath (getfolder))
  (setq odbx
   (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.16")
   )
  )
 )
 (foreach Dwg (vl-direcotry-files DirPath "*.dwg" 1)
  (setq FullPath (strcat DirPath Dwg))
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list odbx FullPath)))
   (prompt (strcat "\n ++ Couldn't open drawing \"" FullPath "\""))
   (progn
    (prompt (strcat "\n  - Report for - " FullPath))
    (ReloadBindXrefs odbx)
    (vla-SaveAs obdx (vla-get-Name odbx))
   )
  )
 )
)
(vlax-release-object odbx)
(setq odbx nil)
(princ)
)
Untested, but should be what you want.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Objectdbx all Xrefs within Folder
« Reply #2 on: August 30, 2006, 02:47:24 PM »
Tim

Thanks for all of the help. I made the following changes and still get the following error:

; Unable to bind xref: Data
; Unable to bind xref: TITLE
; Unable to bind xref: COVER; error: bad argument type: VLA-OBJECT nil


Code: [Select]
;;;by Tim Willey 8/29/06
(defun C:Test (/ DirPath odbx FullPath)
(setq *acad (vlax-get-acad-object)) ;ADDED
(if
 (and
  (setq DirPath (getfolder))
  (setq odbx
   (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.16")
   )
  )
 )
 (foreach Dwg (vl-directory-files DirPath "*.dwg" 1) ;CORRECTED SPELLING
  (setq FullPath (strcat DirPath "\\" Dwg)) ;ADDED "\\"
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list odbx FullPath)))
   (prompt (strcat "\n ++ Couldn't open drawing \"" FullPath "\""))
   (progn
    (prompt (strcat "\n  - Report for - " FullPath))
    (ReloadBindXrefs odbx)
    (vla-SaveAs obdx (vla-get-Name odbx))
   )
  )
 )
)
(vlax-release-object odbx)
(setq odbx nil)
(princ)
)

Gary
« Last Edit: August 30, 2006, 02:49:02 PM by Gary Fowler »
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: Objectdbx all Xrefs within Folder
« Reply #3 on: August 30, 2006, 03:14:45 PM »
You didn't catch enough of my mis-typing.
Code: [Select]
;;;by Tim Willey 8/29/06
(defun C:Test (/ DirPath odbx FullPath)
(setq *acad (vlax-get-acad-object)) ;ADDED
(if
 (and
  (setq DirPath (getfolder))
  (setq odbx
   (if (< (atoi (substr (getvar "acadver") 1 2)) 16)
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument")
    (vla-GetInterfaceObject *acad "ObjectDBX.AxDbDocument.16")
   )
  )
 )
 (foreach Dwg (vl-directory-files DirPath "*.dwg" 1) ;CORRECTED SPELLING
  (setq FullPath (strcat DirPath "\\" Dwg)) ;ADDED "\\"
  (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-Open (list odbx FullPath)))
   (prompt (strcat "\n ++ Couldn't open drawing \"" FullPath "\""))
   (progn
    (prompt (strcat "\n  - Report for - " FullPath))
    (ReloadBindXrefs odbx)
    (vla-SaveAs odbx (vla-get-Name odbx)) ; was trying to save 'obdx'
   )
  )
 )
)
(vlax-release-object odbx)
(setq odbx nil)
(princ)
)
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Objectdbx all Xrefs within Folder
« Reply #4 on: August 30, 2006, 03:37:40 PM »
Tim

Thanks again for your time on this.
It went thru all of the drawings, but did not bind any of them.

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

KewlToyZ

  • Guest
Re: Objectdbx all Xrefs within Folder
« Reply #5 on: August 30, 2006, 03:43:08 PM »
Just curious, have you tried the -exporttoautocad command?

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Objectdbx all Xrefs within Folder
« Reply #6 on: August 30, 2006, 04:02:20 PM »
After more testing, it seems like you can't do these types of things with ObjectDBX and Lisp.  I opened one drawing with ODBX that has four xrefs in it.  I grabbed them, and put them into a list.  I then tried to reload them, didn't work, then tried to bind them, didn't work.  So now I have come to the conclussion that you can't do these things to them.  One way (work around) would be to detach them, and then insert them as blocks, but that would take a lot of coding.  Sorry.  Here is a quote from the command line showing what I'm talking about.
Quote
Command: (vla-reload (nth 0 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-reload (nth 1 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-reload (nth 2 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-reload (nth 3 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-bind (nth 0 blklist) :vlax-true)
; error: Automation Error. Key not found

Command: (vla-bind (nth 1 blklist) :vlax-true)
; error: Automation Error. Key not found

Command: (vla-bind (nth 2 blklist) :vlax-true)
; error: Automation Error. Key not found

Command: (vla-bind (nth 3 blklist) :vlax-true)
; error: Automation Error. Key not found
These area all attached as overlays, with two loaded, and two unloaded.
Tim

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

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Objectdbx all Xrefs within Folder
« Reply #7 on: August 30, 2006, 04:03:04 PM »
Just curious, have you tried the -exporttoautocad command?
I haven't.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Objectdbx all Xrefs within Folder
« Reply #8 on: August 30, 2006, 04:04:47 PM »
Tim

Thanks. I double checked to make sure allof the xrefs were pathed correctly.

Gary

After more testing, it seems like you can't do these types of things with ObjectDBX and Lisp.  I opened one drawing with ODBX that has four xrefs in it.  I grabbed them, and put them into a list.  I then tried to reload them, didn't work, then tried to bind them, didn't work.  So now I have come to the conclussion that you can't do these things to them.  One way (work around) would be to detach them, and then insert them as blocks, but that would take a lot of coding.  Sorry.  Here is a quote from the command line showing what I'm talking about.
Quote
Command: (vla-reload (nth 0 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-reload (nth 1 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-reload (nth 2 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-reload (nth 3 blklist))
; error: Automation Error. Description was not provided.

Command: (vla-bind (nth 0 blklist) :vlax-true)
; error: Automation Error. Key not found

Command: (vla-bind (nth 1 blklist) :vlax-true)
; error: Automation Error. Key not found

Command: (vla-bind (nth 2 blklist) :vlax-true)
; error: Automation Error. Key not found

Command: (vla-bind (nth 3 blklist) :vlax-true)
; error: Automation Error. Key not found
These area all attached as overlays, with two loaded, and two unloaded.
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: Objectdbx all Xrefs within Folder
« Reply #9 on: August 30, 2006, 04:05:29 PM »
Just curious, have you tried the -exporttoautocad command?
I haven't.

I have not either, how does it work?

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

KewlToyZ

  • Guest
Re: Objectdbx all Xrefs within Folder
« Reply #10 on: August 30, 2006, 04:45:49 PM »
It binds all xref and dbx ref's like AEC to the drawing and lets you save it anywhere from 2007 down to 2004 format.
It is a 2007 feature though I beleive, never tried it in 2006.
More or less architectural desktop references can be a nuisance in a base file so I clean them up using the command.
The file opens up as a regular drawing then which is good for our network bandwidth not to mention productivity.

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Objectdbx all Xrefs within Folder
« Reply #11 on: August 30, 2006, 05:12:25 PM »
I've been pretty busy today so couldn't do any testing. Thanks, Tim, for confriming what I suspected. There isn't much, if anything, that can be done with an Xref in ODBX, as it does not get loaded so there's nothing to edit. In order to Bind ODBX would need to know the Layer status/properties of the Xref layers, among many other things, but without a database to look them up..........

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Objectdbx all Xrefs within Folder
« Reply #12 on: August 30, 2006, 05:33:48 PM »
Yea, I guess it was just wishful thinking.  Learned two things about Lisp today.
Tim

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

Please think about donating if this post helped you.

GDF

  • Water Moccasin
  • Posts: 2081
Re: Objectdbx all Xrefs within Folder
« Reply #13 on: August 30, 2006, 05:36:35 PM »
Yea, I guess it was just wishful thinking.  Learned two things about Lisp today.


Tim

Thanks again for trying. I learned a lttle more on how to use objectdbx.

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