iLogic and the Save Command

iLogic and the Save Command

steveh3
Advisor Advisor
2,771 Views
6 Replies
Message 1 of 7

iLogic and the Save Command

steveh3
Advisor
Advisor

Gang...

 

Getting an error when attempting to use the Save command (ThisDoc.Save)....The screencast video illustrates what I am attempting to do and the error I am seeing...

 

https://knowledge.autodesk.com/community/screencast/0271b42f-a46a-42b1-b60c-0ee2b14795e6

 

What am I missing?

 

Thanks in advance,

 

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Accepted solutions (1)
2,772 Views
6 Replies
Replies (6)
Message 2 of 7

Owner2229
Advisor
Advisor
Accepted solution

Hey, I believe there's an issue in the "Document.Save" command, as I believe it's supposed to pop up the regular "Save dialog" if it's a new document.

@ekinsb@adam.nagy Can any of you guys please confirm if this is a bug or the command serves only to save already saved documents. I've tested it on 2016, Build 138 and I'll try it on 2017 tomorrow at work. Thanks.

 

It did the same to me (showed the same error).

However, you can try this command instead:

 

 

ThisApplication.CommandManager.StartCommand(CommandIDEnum.kFileSaveCommand)

 

Here's the second page of the error:

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
   at Inventor._DocumentClass.Save()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 3 of 7

Owner2229
Advisor
Advisor

Also tested on the below, with the same result.

Inventor 2017 64-bit SP1, Build 196, Date Wed 07/13/2016 
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 4 of 7

steveh3
Advisor
Advisor

Thanks Mike...

 

Appears your recommendation did the trick...

 

ThisApplication.CommandManager.StartCommand(CommandIDEnum.kFileSaveCommand)

 

Appreciate the help!

 

Steve H.

Steve Hilvers
Inventor Certified User / Vault Professional Influencer
0 Likes
Message 5 of 7

AlexFielder
Advisor
Advisor

Hi @Owner2229@steveh

 

If I may add my $0.02 on this:

 

I suspect the reason the built-in iLogic save command is failing is because it is interfering with the DocumentEvents.OnSave Event that the Vault addin is intercepting/capturing in order to then display its own file naming dialogue.

 

Have you tried running the rule (for arguments' sake) with the vault addin disabled?

 

I bet your original rule would run just fine in that case.

 

When you run the ThisApplication.CommandManager.StartCommand(CommandIDEnum.kFileSaveCommand) command, (even though you are running it from iLogic) you are overriding the iLogic .save() method using the built-in API command & then Inventor's events fire normally and everything is fine.

 

You could absolutely see this in action if you ran the Event Watcher tool (with the ApplicationEvents.SaveDocument & UserInputEvents.OnActivateCommand checkboxes selected) at the same time as running this rule.

 

Does this error make it a bug? A small one, yes; I don't have knowledge of how many customers are using both iLogic and Vault (paid for) versions with file naming enabled but I am surprised this hasn't raised its head before now.

 

(At my previous company we used Vault Professional with file numbering enabled and although I used iLogic rules to help with mundane tasks I can't recall ever having iLogic save anything in the way your screencast shows. Maybe I found this error and decided the easiest option was to just save manually once the rule completed...)

0 Likes
Message 6 of 7

Owner2229
Advisor
Advisor

I don't think the Vault is causing the issue (at least not in my case) since I'm not using Vault on either of the tested machines and I made sure none of my AddIns were messing with any of the save-events while testing it.

So, all it had to do was pop-up the standard New-Save dialog.

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes
Message 7 of 7

AlexFielder
Advisor
Advisor

Hmmm, you're correct; Vault isn't the cause here.

 

What is happening is that the file is attempting to save without having a filename to save to.

 

Firing the built-in command forces Inventor to check if the file has been saved and (because it hasn't as its a new file) the correct prompts appear.

 

I guess a way around this in future is to either use the non-iLogic version as suggested already or check for whether the activedocument has a fullfilename; normally a clear sign it has in fact been saved.

 

TL;DR: Not a bug, but a limitation of the document.save() command inside iLogic.

0 Likes