Copy an Open file and access via ObjectDBX

Copy an Open file and access via ObjectDBX

Anonymous
Not applicable
697 Views
8 Replies
Message 1 of 9

Copy an Open file and access via ObjectDBX

Anonymous
Not applicable
I need to access many open files via ObjectDBX...
Some files are open by users and therefor ignored when tried to copy with... FileCopy Target, Source

any ideas on how to get around this??
0 Likes
698 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
From the MS Knowledge base:
http://support.microsoft.com/kb/207703

1.Complete steps 1 through 4 from the "Steps to Reproduce Behavior" section
later in this article.

2.Create a module and type the following lines in the Declarations section:
Option Explicit

Declare Function apiCopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
3.Type the following procedure:
Sub CopyFile(SourceFile As String, DestFile As String)
'---------------------------------------------------------------
' PURPOSE: Copy a file on disk from one location to another.
' ACCEPTS: The name of the source file and destination file.
' RETURNS: Nothing
'---------------------------------------------------------------
Dim Result As Long
If Dir(SourceFile) = "" Then
MsgBox Chr(34) & SourceFile & Chr(34) & _
" is not valid file name."
Else
Result = apiCopyFile(SourceFile, DestFile, False)
End If
End Sub
wrote in message news:5452248@discussion.autodesk.com...
I need to access many open files via ObjectDBX...
Some files are open by users and therefor ignored when tried to copy with...
FileCopy Target, Source

any ideas on how to get around this??
0 Likes
Message 3 of 9

Anonymous
Not applicable
Or if the machine has microsoft scripting installed (which most do), just
use FileSystemObject...ie:

--

Dim dbxApp As AxDbDocument
Dim strLocalPageSetupsPath As String
Dim objFso As FileSystemObject

' Make a local copy of the selected page setup file. This way we can
avoid
' keeping the source file locked while routine is running
Set dbxApp = Nothing ' Close Previous
Set objFso = New FileSystemObject

If objFso.FileExists(txbPageSetupFile.Text) Then
strLocalPageSetupsPath =
objFso.BuildPath(ThisDrawing.GetVariable("TEMPPREFIX"), "pagesetups.dwt")
objFso.CopyFile txbPageSetupFile.Text, strLocalPageSetupsPath, True

' Use ObjectDBX to grab all the page setup names
' from file and populate the drop down box
Set dbxApp = GetInterfaceObject("ObjectDBX.AxDbDocument.16")
dbxApp.Open strLocalPageSetupsPath
Set mobjPlotConfigs = mdbxApp.PlotConfigurations
...etc
---

Notice I create a temporary file in autocad's temp folder which i delete
after i'm done using DBX. FileSystemObject is generally more robust then the
standard VBA file methods....but signficantly slower when dealing with a lot
of files and requires Microsoft Scripting be installed.

-Chris

wrote in message news:5452248@discussion.autodesk.com...
I need to access many open files via ObjectDBX...
Some files are open by users and therefor ignored when tried to copy with...
FileCopy Target, Source

any ideas on how to get around this??
0 Likes
Message 4 of 9

Anonymous
Not applicable
Filesystemobject... bla bla bla would not work... but the MS knowledgebase solution did...

Thanks!!!

for some reason - searching MS didn't cross my mind...
0 Likes
Message 5 of 9

Anonymous
Not applicable
It was an example....not a cut and paste drop in. Anyway I try to avoid API
calls when i can avoid them.

-Chris

wrote in message news:5452301@discussion.autodesk.com...
Filesystemobject... bla bla bla would not work... but the MS knowledgebase
solution did...

Thanks!!!

for some reason - searching MS didn't cross my mind...
0 Likes
Message 6 of 9

Anonymous
Not applicable
Why? As you noted using the FSO is slower and requires another Reference,
using the API is faster and will work on any Windows machine. (AFAIK)

"Chris Shoemaker" wrote in message
news:5452308@discussion.autodesk.com...
Anyway I try to avoid API calls when i can avoid them.
0 Likes
Message 7 of 9

Anonymous
Not applicable
For me....three reasons...if you're only performing the operation on a few
files, the performence difference is negligable. Secondly, the FSO is easier
for the person who comes along after me to maintin and understand then the
API calls. Third, correct me if i'm wrong but I think you've got a much
better chance of crashing AutoCAD (and possibly the system) with the native
API calls rather then the API wrapped accessible through COM. In other
words...you've got to know a little bit more about what you're doing 🙂

-Chris

"Jeff Mishler" wrote in message
news:5452295@discussion.autodesk.com...
Why? As you noted using the FSO is slower and requires another Reference,
using the API is faster and will work on any Windows machine. (AFAIK)

"Chris Shoemaker" wrote in message
news:5452308@discussion.autodesk.com...
Anyway I try to avoid API calls when i can avoid them.
0 Likes
Message 8 of 9

Anonymous
Not applicable
OK, all valid reasons....I was just curious as I had a mentor that believed
(or so it seemed) that everything should be done via API calls. I tend to
use them only on occassion, as it seems you do.

On another, semi-related subject, I noticed in that little bit of code you
posted that you set your ObjectDBX variable to nothing and reset it with
GetInterfaceObject for each drawing. There is no need to do this since
everytime the Open method is used it closes whatever was open previously.
The only time it need be set to nothing is when you are completely done with
it. Again, probably not noticeable, as far as processor time, for only a few
files, but for a bunch it would have an impact.

Regards,
Jeff

"Chris Shoemaker" wrote in message
news:5452321@discussion.autodesk.com...
For me....three reasons...if you're only performing the operation on a few
files, the performence difference is negligable. Secondly, the FSO is easier
for the person who comes along after me to maintin and understand then the
API calls. Third, correct me if i'm wrong but I think you've got a much
better chance of crashing AutoCAD (and possibly the system) with the native
API calls rather then the API wrapped accessible through COM. In other
words...you've got to know a little bit more about what you're doing 🙂

-Chris

"Jeff Mishler" wrote in message
news:5452295@discussion.autodesk.com...
Why? As you noted using the FSO is slower and requires another Reference,
using the API is faster and will work on any Windows machine. (AFAIK)

"Chris Shoemaker" wrote in message
news:5452308@discussion.autodesk.com...
Anyway I try to avoid API calls when i can avoid them.
0 Likes
Message 9 of 9

Anonymous
Not applicable
Interesting....thanks for the tip. I'm actually working on something now
that's going to use ObjectDBX on a lot of drawings so that should come in
handy.

-Chris

"Jeff Mishler" wrote in message
news:5452333@discussion.autodesk.com...
OK, all valid reasons....I was just curious as I had a mentor that believed
(or so it seemed) that everything should be done via API calls. I tend to
use them only on occassion, as it seems you do.

On another, semi-related subject, I noticed in that little bit of code you
posted that you set your ObjectDBX variable to nothing and reset it with
GetInterfaceObject for each drawing. There is no need to do this since
everytime the Open method is used it closes whatever was open previously.
The only time it need be set to nothing is when you are completely done with
it. Again, probably not noticeable, as far as processor time, for only a few
files, but for a bunch it would have an impact.

Regards,
Jeff

"Chris Shoemaker" wrote in message
news:5452321@discussion.autodesk.com...
For me....three reasons...if you're only performing the operation on a few
files, the performence difference is negligable. Secondly, the FSO is easier
for the person who comes along after me to maintin and understand then the
API calls. Third, correct me if i'm wrong but I think you've got a much
better chance of crashing AutoCAD (and possibly the system) with the native
API calls rather then the API wrapped accessible through COM. In other
words...you've got to know a little bit more about what you're doing 🙂

-Chris

"Jeff Mishler" wrote in message
news:5452295@discussion.autodesk.com...
Why? As you noted using the FSO is slower and requires another Reference,
using the API is faster and will work on any Windows machine. (AFAIK)

"Chris Shoemaker" wrote in message
news:5452308@discussion.autodesk.com...
Anyway I try to avoid API calls when i can avoid them.
0 Likes