DbxDocs in collection all return same name

DbxDocs in collection all return same name

Anonymous
Not applicable
508 Views
6 Replies
Message 1 of 7

DbxDocs in collection all return same name

Anonymous
Not applicable
Hi all,
This is puzzling me
'in a class containing dbx functionality...
Private moDbxDoc as axdbDocument
'in Init method...create dbxdoc via GetInterface

I have a collection of filenames

I open each in turn via dbx
For Each vFile In mColFileNames
FileName = CStr(vFile)
modbxdoc.Open Filename

I add each opened doc to collection
colDocs.Add moDbxDoc, moDbxDoc.Name

...then after processing...
I close each doc in collection, returning it's name for confirmation
Dim oDoc As AxDbDocument
For Each oDoc In colDocs
LogEntry "Close ", oDoc.Name

Set oDoc = Nothing'
Next
Set colDocs = Nothing
>>> They all return the same name (of the last file in the list) <<<

any one can explain this?
I'm assuming it's something to do with re-using the member variable moDbxDoc
to open each doc in turn
but don't understand why putting them in collection doesn't retain their
identity, but sets them all to the same one

do I need to create a local variable for each doc to keep them separate?
I used to recreate the interface for each file to be opened but thought if I
kept the docs in a collection I could create one interface and reuse it for
multiple files instead of recreating the interface multiple times
(like creating multiple database connections versus re-using one connection)

Thanks for any input
Mark
0 Likes
509 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
MP: any one can explain this?
MP: I'm assuming it's something to do with re-using the member variable moDbxDoc
MP: to open each doc in turn

Correct.

MP: but don't understand why putting them in collection doesn't retain their
MP: identity, but sets them all to the same one

That's because you only have one. Each time you add it to your collection you are essentially adding a pointer to it to the collection.

MP: do I need to create a local variable for each doc to keep them separate?

You can reuse the variable but you'll need to set it to a new instance each time.
0 Likes
Message 3 of 7

Anonymous
Not applicable
wrote in message news:6181001@discussion.autodesk.com...


snip

You can reuse the variable but you'll need to set it to a new instance each
time.

thanks for the confirmation fantum, I assumed that was it, the pointer was
always looking at modbxdoc

...so the question is, to close a dbx doc you have to set it to nothing
...but in a loop you want to reuse it to open next dwg so don't want to set
to nothing just yet
...if instead of setting to nothing in a loop and recreating each time with
GetInterface,
..does the act of opening a new dwg effectively close the preceeding dwg or
will it leave them all hanging in memory?

set dbxdoc = GetInterface
'in loop
dbxdoc.Open file1...do something
...repeat loop
dbxdoc.open file2 (now file1 closes??? or is it left open with no pointer to
it???)

or do i need to go back to what i had
'in loop
set dbxdoc = GetInterface
dbxdoc.open filex
...
set dbxdoc = nothing'close doc
'loop

I just thought that repeated creating of the interface was wasteful but
maybe that's the right thing to do afterall???

Thanks
mark
0 Likes
Message 4 of 7

Anonymous
Not applicable
MP: does the act of opening a new dwg effectively close the preceeding dwg

I can't say what's under the hood but that has been my experience.
0 Likes
Message 5 of 7

Anonymous
Not applicable
Thats' good to know...
So do you create the interface once then re-use it in a loop in that manner?

would you assume that was more "efficient" in terms of speed or memory
consumption than to re-create the interface each time in the loop?

just interested to know how the experts do it

Thanks for the responses
Mark

wrote in message news:6181565@discussion.autodesk.com...
MP: does the act of opening a new dwg effectively close the preceeding dwg I
can't say what's under the hood but that has been my experience.
0 Likes
Message 6 of 7

Anonymous
Not applicable
MP: So do you create the interface once then re-use it in a loop in that manner?

I haven't used it in a while but looking back over some dusty code it looks like I usually made repeated call to GetInterfaceObject. I can't say now if I thought I had a reason for that then.

MP: would you assume that was more "efficient" in terms of speed or memory
MP: consumption than to re-create the interface each time in the loop?

I wouldn't want to assume anything about efficiency without strapping it to a test bench but I would guess that disk access would so overwhelm the call to GetInterfaceObject that it would be a wash.

MP: just interested to know how the experts do it

I wouldn't call me an expert. Much less so when I wrote the code I just looked over.
0 Likes
Message 7 of 7

Anonymous
Not applicable
Thanks fantum
Mark

wrote in message news:6181958@discussion.autodesk.com...
MP: So do you create the interface once then re-use it in a loop in that
manner? I haven't used it in a while but looking back over some dusty code
it looks like I usually made repeated call to GetInterfaceObject. I can't
say now if I thought I had a reason for that then. MP: would you assume that
was more "efficient" in terms of speed or memory MP: consumption than to
re-create the interface each time in the loop? I wouldn't want to assume
anything about efficiency without strapping it to a test bench but I would
guess that disk access would so overwhelm the call to GetInterfaceObject
that it would be a wash. MP: just interested to know how the experts do it I
wouldn't call me an expert. Much less so when I wrote the code I just looked
over.
0 Likes