INV2008 Pro: SaveAs doesn't work

INV2008 Pro: SaveAs doesn't work

Anonymous
Not applicable
782 Views
14 Replies
Message 1 of 15

INV2008 Pro: SaveAs doesn't work

Anonymous
Not applicable
I'm using the SaveAs command as follows:

_inventor.ActiveDocument.SaveAs(_inventor.FileLocations.Workspace & "\" & txtFilename.Text, False)

The flag to not do a savecopyas doesn't seem to work correctly. It will create the new file and you think the new file it the active one, but the iProperties dialog still points to the old file. Very strange. Any ideas?

Try it out.

(It seems to work in VB, not as a VB.net add-in)
0 Likes
783 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

You can set the SaveCopyAs argument to False only
if the active document has never been saved before. This flag is not supported
(and must be specified as True) for documents that have already been saved to
disk. If you want to simulate 'Save As' through the API, you will need to do a
'Save Copy As', close the current document and then open the copied document.
This is what the 'Save As' command essentially does underneath.

 

Sanjay-
0 Likes
Message 3 of 15

Anonymous
Not applicable
Is this going to be supported in the future?
0 Likes
Message 4 of 15

Anonymous
Not applicable

Well, this will be very difficult to support since
it will involve swapping of a document underneath. So if you are holding on to a
Document pointer, we'd have to swap the object that it points to since the
active document will need to change. What is the problem with the approach I
mentioned earlier? After all, that's basically what the Save As command
does.

 

Sanjay-
0 Likes
Message 5 of 15

Anonymous
Not applicable
So I set the flag to True for existing documents. When saving an Inventor DWG file this way, the export dialog appears instead of just saving a copy as a new DWG file. Something I'm missing?
0 Likes
Message 6 of 15

Anonymous
Not applicable

As you may be aware, there are now two flavors of a
dwg file - AutoCAD dwg and Inventor dwg. If a dwg file extension is provided in
the SaveAs method, this assumes that the file should be translated out to an
AutoCAD dwg format. This has always been the behavior of this method, so we
didn't want to change this. And this is the reason that you see the export
dialog.

 

In order to do a 'save copy as' on an Inventor
dwg to another Inventor dwg, you need to use the
DrawingDocument.SaveAsInventorDWG method instead.

 

Sanjay-
Message 7 of 15

Anonymous
Not applicable
Ahhh, now it's coming together. Thanks for the info.
0 Likes
Message 8 of 15

Anonymous
Not applicable
One more question as to the order of operations for a SaveAs override, does this order make sense:

1. OnFileSaveAsDialog Event Sub
2. Do Override Events (Show Form)
3. Form: If DWG then SaveAsInventorDWG, If not then SaveAs
4. Close Form
5. Open the new file
6. Set kEventHandled

At what point can I close the original file? It seems as if no matter where I put the entry, Inventor will crash? Any suggestions?
0 Likes
Message 9 of 15

Anonymous
Not applicable

Could you provide some details on what it is you
are trying to do? What is the user workflow?

 

Sanjay-
0 Likes
Message 10 of 15

Anonymous
Not applicable
1. Capture saveasdialog event
2. display new saveas form
3. save the file (part or dwg),
0 Likes
Message 11 of 15

Anonymous
Not applicable

There is an easier approach to this, but there is
one limitation in Inventor 2008 that has been addressed in 2009. The approach is
to set the HandlingCode in the event to kEventHandled and the FileName to the
string of your choice (i.e. the one obtained using your own form). If you
go this route, you don't have to explicitly save the documents thru the API -
Inventor takes care of that for you. The limitation in Inventor 2008 is
that you cannot specify whether you want a drawing to be saved as an
Inventor or an AutoCAD dwg - the event assumes AutoCAD dwg if a dwg
extension is provided.

 

So, if your utility is intended for Inventor 2009
or later, the solution is really simple as shown below. Else, you'll have to
further experiment with your code that performs the save using the
API.

 

Sanjay- 

 

 

Private Sub
oFileUIEvents_OnFileSaveAsDialog(FileTypes() As String, ByVal SaveCopyAs As
Boolean, ByVal ParentHWND As Long, FileName As String, ByVal Context As
NameValueMap, HandlingCode As HandlingCodeEnum)
   

    ' Your dialog/form here
   

    ' Specify that event is being handled and the file
name
    HandlingCode = kEventHandled
   
FileName = "C:\temp\test.ipt"
   
    ' If
a DWG file extension is specified, the following specifies
   
' whether to save the document to AutoCAD or Inventor dwg.

    ' WORKS ONLY IN INVENTOR
2009 OR LATER
    Call Context.Add("SaveAsInventorDWG",
True)


End Sub
0 Likes
Message 12 of 15

Anonymous
Not applicable
I think I mostly got it now. I have the code (which needs to run in INV2008) to detect if it is a DWG and cancel the saveas and perform a seperate SaveAsDWG operation. That works good.
The last question i have is based on the code you provided, where would you add the code to close the oldfile and open the newfile when performing a "save as" type operation? It would seem that you would need to do this after the saveasdialog sub is completed. How would you do this?
0 Likes
Message 13 of 15

Anonymous
Not applicable

 

Unfortunately, I couldn't find a safe point where
you can close the original document. I guess you'll have to leave the original
document open in Inventor 2008 (the issue should only occur when saving dwg
files). Sorry.

 

Sanjay-

 

 
0 Likes
Message 14 of 15

Anonymous
Not applicable
Add this to the wishlist for 2010...
0 Likes
Message 15 of 15

Anonymous
Not applicable

As I mentioned earlier, you shouldn't have to take
this (workaround) route in Inventor 2009 or later. You can simply specify the
options in the OnFileSaveAsDialog (as demonstrated by the sample I posted
earlier).

 

Sanjay- 
0 Likes