The goal of this project is to take a base part file, save new copies as needed, then modify the copies. They're rings for storage tanks that share the same tank diameter but differ in height and thickness. I have a SaveAsCopy rule in my template ring part that I run externally from my main assembly after passing down the new file names to the part rule. Since I'm testing a lot, I'm always deleting the parts from the assembly, then clearing out the new copies from my folder and running the rule again. Eventually after 1-5 times inventor starts giving me an error.
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
The More Info Tab:
System.ArgumentException: The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData) at Inventor.Document.SaveAs(String FileName, Boolean SaveCopyAs) at LmiRuleScript.Main() at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem) at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
The two other posts on here that deal with that error say it involves enumerating an array that is being changed and looking for an entry that is gone. I have a feeling it has to do with a left over variable (but this is all in iLogic rules so they get cleared at the end of the rule?), temporary files or remnant file references. It works again if I close the assembly and open it back up. Any suggestions?
>"The parameter is incorrect." Doesn't mean anything, it's just a cover-all type message.
Ah, I just assumed the error number on the end varied to give slightly more info, but now I see they're all the same.
saveLoc = RuleArguments("saveLoc") save = RuleArguments("saveFile") 'variable = RuleArguments("example") 'Grabs the same named variable from the oArg variable from the top level rule If save = 1000 Then MsgBox(saveLoc) ThisDoc.Document.SaveAs(saveLoc, True) 'MsgBox("Ring Saved: " & "RING" & ringText) End If
Thats the only code in the part that is being run in the ring part. The file is not read-only, and its not a new file being created by the assembly rules. I've tried verifying file names and locations, as demonstrated by the msgboxs, but it all seems clean.
Setting that flag to false just renames the base template part and replaces the reference to the template part in my assembly file. And yep, contains the file extension. Like I said, it'll run 1-5 times with no problems, then suddenly not like it. I guess I'll just go line by line and make sure something extra isn't getting added to my ArrayLists after the n-th run or something weird like that.
Public Function SaveRings(ByVal ruleName As String, saveLoc As String, saveFile As Double) As Byte() Dim oArg as NameValueMap oArg = ThisApplication.TransientObjects.CreateNameValueMap MsgBox(oArg.count) Call oArg.Add("saveLoc", saveLoc) Call oArg.Add("saveFile", saveFile) 'must equal 1000 for the part to save new copies 'Call oArg.Add("saveQty", saveQty) MsgBox(oArg.count) iLogicVb.RunRule("RING.ipt","FuncSave", oArg) End Function
In the main sub() :
For Each item in oClsThk ringName = "RNG" & p & ".ipt" saveLoc = sourceFolder & "\" & ringName p+=1 oClsRingLoc.add(saveLoc) oClsRings.add(ringName) out1 = saveLoc If saveFlag = 1000 Then 'MsgBox(saveLoc) If System.IO.File.Exists(saveLoc) Then MsgBox(saveLoc & " file already exists") End If x = SaveRings("Function", saveLoc, saveFlag) End If Next
This is the most code from the main assembly I'm comfortable posting in this thread(NDAs and all that).
Interesting little update. The configuration I've been testing has 6 areas of differing rings, but only 4 unique rings and thus 4 files. I just ran it and got the error when using the 6 areas - 4 unique parts config. Now when I switched it to 6 areas, and 6 completely unique rings, it errored out on files 1-4 and didn't create them, but it did create new 5 and 6 files.
Leads me back to my hypothesis that its keeping file references, or variables in memory that are causing conflicts.
So this morning I made a new rule and copied just the save functions over. I fed it a parameter that stored one of the file names/locations from my big master rule and it gave the same error, and then I explicitly pasted the file path and name into a new string, and it still errors out.
Sub Main() 'saveLoc = out1 saveLoc = "Z:\Data\[customer]\iParts\Sandbox\Rough Draft\RNG4.ipt" saveFlag = 1000 x = SaveRings("Function", saveLoc, saveFlag) End Sub Public Function SaveRings(ByVal ruleName As String, saveLoc As String, saveFile As Double) As Byte() Dim oArg as NameValueMap oArg = ThisApplication.TransientObjects.CreateNameValueMap Call oArg.Add("saveLoc", saveLoc) Call oArg.Add("saveFile", saveFile) 'must equal 1000 for the part to save new copies 'Call oArg.Add("saveQty", saveQty) iLogicVb.RunRule("RING.ipt","FuncSave", oArg) End Function
Well I think I've taken this to my current limit of knowlege. I got a copy of Process Monitor (regmon and filemon) and looked at what Inventor is trying to do when it saves the files. On a fresh attempt that causes no errors (read: I just opened my assembly and ran the rule) Inventor does a "QueryDirectory" for "RING1.ipt" which returns "NO SUCH FILE". Inventor then does a "CreateFile" for "RING1.ipt", then does all its other save stuff. When the errors pop up, (after I've deleted the parts from my assembly, and deleted the files from the folder in preparation for a second test), it doesn't attempt the "QueryDirectory" and just goes for "CreateFile" which, oddly enough, is what it does anytime you just save a file.
So it seems like Inventor is still looking for the non-existant files to save to for some reason. I think I now know enough to work around it. I'll just have to limit the number of saves, and make more use of replace part. Of course, if someone knows whats going on here, or what I'm doing wrong, feel free to let me know.
It may also be wise to post this question (with a link back to this thread) in the Customization forum. There's folks there with much more programming exertise who may be able to edjucate both of us.
I tried that earlier, but hadn't restarted inventor. But I just tried it after restarting and no dice. I'll post a link to this in that other forum.