Open and Save Method Enigma

Open and Save Method Enigma

Anonymous
Not applicable
341 Views
2 Replies
Message 1 of 3

Open and Save Method Enigma

Anonymous
Not applicable
Hi,

Here's something I can't explain to me while saving a Drawing document.
I've a Bpart.idw copied from Apart.idw document. The Apart.idw and Bpart.idw reference Apart.ipt

Here's the code I 've used first with the .Open Method and Openvisible parameter set to "True". This works fine. Bpart.idw reference Bpart.ipt.

Then I change the Openvisible to "False". In this case Debug.Print function calls show the good result for the .ReplaceReference method. But when opening the Bpart.idw, Apart.ipt is still referenced.

Sub ReplaceReferenceIdw()

Dim oDrwName As String
oDrwName = "c:\Temp\Bpart.idw"

Dim oNewName As String
oNewName = "c:\Temp\Bpart.ipt"

'Open the Drawing document
Dim oDrwDoc As DrawingDocument

Set oDrwDoc = ThisApplication.Documents.Open(oDrwName, False)

' Search for the first referenced document (assuming it is unique)
Dim oDocDescriptor As DocumentDescriptor
Set oDocDescriptor = oDrwDoc.ReferencedDocumentDescriptors.Item(1)

Dim oFileDescriptor As FileDescriptor
Set oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor
Debug.Print oFileDescriptor.FullFileName 'Show referenced document

' Replace referenced document, Update it, Save it and Close it
Call oFileDescriptor.ReplaceReference(oNewName)
Call oDrwDoc.Update
Debug.Print oFileDescriptor.FullFileName 'Show referenced document
Call oDrwDoc.Save
Debug.Print oFileDescriptor.FullFileName 'Show referenced document again
Call oDrwDoc.Close
End Sub

Obviously, there's something I can't understand. Is anyone could explain that to my tired brain.

C.Saint
0 Likes
342 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
The problem here is that drawings depend heavily on a view being present in
order to update. In this case, although ReplaceReference succeeds, the
drawing doesn't recognize this as being a 'dirtying' change and hence the
Save turns out to be a no-op. To fix this, simply add the following line of
code to explicitly dirty the document after you've changed the reference and
before saving the document.

oDrwDoc.Dirty = True

Sanjay-

wrote in message news:5475776@discussion.autodesk.com...
Hi,

Here's something I can't explain to me while saving a Drawing document.
I've a Bpart.idw copied from Apart.idw document. The Apart.idw and
Bpart.idw reference Apart.ipt

Here's the code I 've used first with the .Open Method and Openvisible
parameter set to "True". This works fine. Bpart.idw reference Bpart.ipt.

Then I change the Openvisible to "False". In this case Debug.Print function
calls show the good result for the .ReplaceReference method. But when
opening the Bpart.idw, Apart.ipt is still referenced.

Sub ReplaceReferenceIdw()

Dim oDrwName As String
oDrwName = "c:\Temp\Bpart.idw"

Dim oNewName As String
oNewName = "c:\Temp\Bpart.ipt"

'Open the Drawing document
Dim oDrwDoc As DrawingDocument

Set oDrwDoc = ThisApplication.Documents.Open(oDrwName, False)

' Search for the first referenced document (assuming it is unique)
Dim oDocDescriptor As DocumentDescriptor
Set oDocDescriptor = oDrwDoc.ReferencedDocumentDescriptors.Item(1)

Dim oFileDescriptor As FileDescriptor
Set oFileDescriptor = oDocDescriptor.ReferencedFileDescriptor
Debug.Print oFileDescriptor.FullFileName 'Show referenced document

' Replace referenced document, Update it, Save it and Close it
Call oFileDescriptor.ReplaceReference(oNewName)
Call oDrwDoc.Update
Debug.Print oFileDescriptor.FullFileName 'Show referenced document
Call oDrwDoc.Save
Debug.Print oFileDescriptor.FullFileName 'Show referenced document again
Call oDrwDoc.Close
End Sub

Obviously, there's something I can't understand. Is anyone could explain
that to my tired brain.

C.Saint
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thank you Sanjay !

It's Ok now.

C.Saint
0 Likes