Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iLogic Error when saving part files after the first few times

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
2151 Views, 12 Replies

iLogic Error when saving part files after the first few times

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?

12 REPLIES 12
Message 2 of 13
mrattray
in reply to: Anonymous

Is the file read-only? Has it already been saved or is it being created by the rule? If you post the code that calls the SaveAs() method it may help.
"The parameter is incorrect." Doesn't mean anything, it's just a cover-all type message.
Mike (not Matt) Rattray

Message 3 of 13
Anonymous
in reply to: mrattray

 

>"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.

Message 4 of 13
mrattray
in reply to: Anonymous

It all looks good at a glance. Does saveLoc include the extension?
Does it work if you use False as the second argument?
Mike (not Matt) Rattray

Message 5 of 13
Anonymous
in reply to: mrattray

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.

Message 6 of 13
mrattray
in reply to: Anonymous

If you can't find it, you can try posting the caller side of this sub here. (Or have you narrowed the problem down to this sub?)
Maybe a second set of eyes is all you need.
Mike (not Matt) Rattray

Message 7 of 13
Anonymous
in reply to: mrattray

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).

Message 8 of 13
Anonymous
in reply to: Anonymous

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.

Message 9 of 13
Anonymous
in reply to: Anonymous

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

 

Message 10 of 13
Anonymous
in reply to: Anonymous

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.

Message 11 of 13
mrattray
in reply to: Anonymous

Now that's interesting. Sounds like Inventor is holding onto the files in its cache. Try going into your application options to the "File" tab and unchecking "Enable Quick File Open".
Mike (not Matt) Rattray

Message 12 of 13
mrattray
in reply to: mrattray

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.

Mike (not Matt) Rattray

Message 13 of 13
Anonymous
in reply to: mrattray

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.

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

Post to forums  

Autodesk Design & Make Report