SaveAsInventorDWG creates version conflict

SaveAsInventorDWG creates version conflict

DelightfulCurmudgeon
Participant Participant
609 Views
4 Replies
Message 1 of 5

SaveAsInventorDWG creates version conflict

DelightfulCurmudgeon
Participant
Participant

I have an automated save operation that has worked for years. It saves a copy using the respective drawing type

If IO.Path.GetExtension(odoc.FullFileName).Contains("dwg") Then
    Dim Drawdoc As DrawingDocument = CType(odoc, DrawingDocument)
    Drawdoc.SaveAsInventorDWG(SaveName, True)
Else
    odoc.SaveAs(SaveName, True)
End If

I'm having the problem that as soon as the autosave function fires for a .dwg file, the version in the active document is altered causing the error message:

0EM3g000000WQpq.png

This does not occur when saving a .idw file.

 

0 Likes
Accepted solutions (1)
610 Views
4 Replies
Replies (4)
Message 2 of 5

TA.Fehr
Advocate
Advocate

I can confirm the issue.
I tried running the command from iLogic and ran into the same issue
I also tried activating the document  prior to running the SaveAsInventorDWG command via API, but this still caused version conflicts when manually saving the original.
Even manually clicking "SaveCopyAs" in a separate location causes the version conflict.

This would seem to be an error within Inventor save process itself. The issue does not happen when saving as an ".idw" file, this seems to be strictly relegated to .dwg extensions.

So one thing you may be able to do is save the document as an ".idw". If the purpose is  for having automated backups, you will still have the drawing, however, when you restore it, you will have to either have a code that corrects this, or manually restore it to a .dwg file.

0 Likes
Message 3 of 5

DelightfulCurmudgeon
Participant
Participant

I tried saving the drawing as an IDW with the code

 

Drawdoc.SaveAs(SaveName.Replace("dwg", "idw"), True)

 

but this gives an unspecified error.

 

However, if I run the iLogic code from within the document

 

ThisDoc.Document.SaveAs(ThisDoc.ChangeExtension(".idw"),True)

 

The drawing saves as an IDW without error. However, as my program isn't run via iLogic triggers, this doesn't really work.

I tried creating a duplicate document and copying the sheets into it and saving it as an IDW and this works,

 

 

        Private Function SaveDWGasIDW(odoc As Document, Savename As String) As Boolean
            Dim idwDoc As DrawingDocument = DirectCast(odoc, DrawingDocument)
            Dim DrawingDoc As DrawingDocument = CType(g_inventorApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, , False), DrawingDocument)
            For Each sheet As Sheet In idwDoc.Sheets
                sheet.CopyTo(DrawingDoc)
            Next
            DrawingDoc.Sheets.Item(1).Delete()
            DrawingDoc.SaveAs(Savename, False)
            DrawingDoc.Close()
        End Function


however, it seems overly cumbersome for a workaround to a "savecopyas" function that should work out of the box.

0 Likes
Message 4 of 5

TA.Fehr
Advocate
Advocate
Accepted solution

I wouldn't recommend copying each sheet
I've tested the following code and it seems to work. The reference to 'odoc' refers to the original file with the .dwg extension. The variable "savename" is created as a string and changing the .dwg to an .idw outside the sub. When the variable is changed within the save command it seems to cause problems. Ensure the document to be saved is active, and then call it through the Inventor instance, rather than the document inserting the new name in the save location.
I added a check for either dwg or idw, but this is technically unnecessary as the drawing will always be saved as an idw file.

 

                    If IO.Path.GetExtension(odoc.FullFileName).Contains("dwg") Then
                        g_inventorApplication.ActiveDocument.SaveAs(SaveName, True)
                    Else
                        odoc.SaveAs(SaveName, True)
                    End If

 

  

However, remember that if this is the option you use, when you restore you will have to revert the idw file back to a dwg. There may be implications that I'm unaware of, but if you do it manually watch your extensions and save accordingly.

If you do it programmatically you would need to do something like this

 

Dim DWGDoc As DrawingDocument = DirectCast(g_InventorApplication.ActiveDocument, DrawingDocument)
DWGDoc.SaveAsInventorDWG("Original file name with dwg extension", True)
g_InventorApplication.Documents.Open("Original file name with dwg extension", True)
g_InventorApplication.Documents.ItemByName(DWGDoc.FullFileName).Close(True)

 

 If you don't save the active drawing as a copy, you'll run into issues. So save it as a copy with the dwg extension, then open the new drawing, and close or delete the backup.

0 Likes
Message 5 of 5

A.Acheson
Mentor
Mentor

Hi @DelightfulCurmudgeon 

I agree with @TA.Fehr  last suggestion to save as a copy and open. Otherwise you can't delete the old version in the same operation. This is due to the referenced documents being open in memory I believe. It isn't a desirable workflow as it is obviously slow to open and close drawings but it is the only thing that works for .dwg. I didn't think it was only a .dwg extension problem however. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes