Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Save a document using Inventor VBA Macro

10 REPLIES 10
Reply
Message 1 of 11
isocam
6662 Views, 10 Replies

Save a document using Inventor VBA Macro

Can anybody help?

 

I am trying to automatically save an inventor document (ipt, idw or iam) using a VBA macro.

 

here is my code so far....

 

Dim oDoc As Document

Set oDoc = ThisApplication.ActiveDocument

If oDoc Is Nothing Then Exit Sub

oDoc.Save

 

But Inventor keeps crashing every time I run the macro.

 

What is wrong?

 

Many thanks in advance!!!!

 

IsoCAM

 

 

 

 

10 REPLIES 10
Message 2 of 11
santoshr0114
in reply to: isocam

I think Save needs argument of file name/path.
Because oDoc.Save brings up the save dialog which prompts for filename

I tried you code Inventor does not crash, but prompts the Save Dialog for filename for new file.

For a file which is already saved and if i run this macro, it runs successfully and the file is saved.
Regards
Santosh
Message 3 of 11
Nik_Barbour
in reply to: isocam

In the past I have used...

 

Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

oDoc.Save 'Save.

 

 

Message 4 of 11
rjay75
in reply to: isocam

Testing your code in Invent 2013 didn't crash it.

 

However there something to note, if the document is a new document and you call the Save method on it as you are doing it should display the dialog prompt for a filename. But if somewhere before this point you have SilentOperation set to true, [ThisApplication.SilentOperation = True], then it will display an error message.

 

 

Message 5 of 11
isocam
in reply to: rjay75

Can somebody test the following code?

 

Sub savepart()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument

oDoc.Save 'Save.
End Sub

 

I think it does not work!!!!

 

Please help???

 

Regards

 

Darren

Message 6 of 11
santoshr0114
in reply to: isocam

Darren,

 

Your code works only for the document which is previously saved.

This does not work for new document.

 

Check the earlier comments... 

Regards
Santosh
Message 7 of 11
isocam
in reply to: santoshr0114

Hi,

 

Did you actually try the code?

 

The part is existing. Running the code does not update the file.

 

Please try the code and see what I mean.

 

Regards

 

Darren

Message 8 of 11
santoshr0114
in reply to: isocam

Yes i did try your code...

I get Save Dialog for new document.

If the document is already saved then it saves sucessfully

Regards
Santosh
Message 9 of 11
ekinsb
in reply to: isocam

I tried the code too and also get the Save As dialog.  That is by design and is the same behavior you see interactively in Inventor.  The first time you save a document the Save As dialog appears so you can specify the location and file name to create.  Saving after that doesn't display a dialog but just performs the save to the existing document.

 

To save a new document using the API and bypassing the dialog you need to use the Document.SaveAs method. The first argument is the file name and the second argument should be False, indicating you are doing a Save As rather than a Save Copy As.

 

You can check to see if a document has been saved by checking the Document.FullFilename.  If this returns an empty string then the document has never been saved.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 10 of 11
DonStauffer99
in reply to: isocam

Document.Save still crashes Inventor 2018.

Message 11 of 11
ali.shahmirzadi
in reply to: isocam

you need to use something like this

 

Call oDrawDoc.SaveAs("c:\temp\test.idw", False) 

 

it works fine then, hope its wat you are looking for

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report