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: 

Code fails on second run

4 REPLIES 4
Reply
Message 1 of 5
Marcus_Chong
197 Views, 4 Replies

Code fails on second run

Hi,

 

This line of code is giving me error on second run. The first run, the line works fine. However, when i run again, it will give an error. And when i open the target file, and I click on the UserParameter without doing anything and close the file. Then i run again, it will work again. 

 

Please help.

 

Line 8:

oCompDoc.ComponentDefinition.Parameters.UserParameters.Item("Shell_ID").Value = oShellID

 

Error:

Error on line 8 in rule: Manifold Support, in document: TPAS004-R0-AS-01.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

 

Sub Main()
	
	Dim oDoc As AssemblyDocument = ThisDoc.Document
	Dim oOcc As ComponentOccurrence = oDoc.ComponentDefinition.Occurrences.ItemByName("Manifold Support")
	Dim oCompDoc As Document = oOcc.Definition.Document
	Dim oShellID As Decimal = Parameter("Shell_ID1") / 10
	
	oCompDoc.ComponentDefinition.Parameters.UserParameters.Item("Shell_ID").Value = oShellID
	
	Parameter("MS_EL") = Parameter("N1_EL")
	Parameter("MS_Or") = Parameter("N1_Or") + 180
	Parameter("mMS_Or") = -Parameter("MS_Or")
	Parameter("mMS_EL") = Parameter("MS_EL")

	Call UpdateModel(oDoc, oOcc)

End Sub

 

4 REPLIES 4
Message 2 of 5
WCrihfield
in reply to: Marcus_Chong

Hi @Marcus_Chong.  What does the 'UpdateModel' routine contain?  And what does the 'More Info' tab of the error message say.  Besides just Unspecified Error, it might specify what it was trying to do when it encountered that error, such as which stage of the code in Line 8 it has a problem with.  (Was it not able to find that specific UserParameter, or was the error at the point where it tries to set its value?)  This sort of sounds like the referenced document is not getting updated between runs, and you manually going into that part and clicking on that parameter is causing that referenced model to automatically update for you.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5
Marcus_Chong
in reply to: WCrihfield

Hi @WCrihfield ,

 

This is the link for the files. https://we.tl/t-N1fbf8bwip

 

This is the file that shows the error.

 

Please help.

 

Thank you.

Message 4 of 5
A.Acheson
in reply to: Marcus_Chong

Hi @Marcus_Chong 

In these two lines place a message box before and after each call for a value and check it's value is what you expect. 

Dim oShellID As Decimal = Parameter("Shell_ID1") / 10
	
	oCompDoc.ComponentDefinition.Parameters.UserParameters.Item("Shell_ID").Value = oShellID
	

 In addition you might need to update the document using document update or parameter update. You will find these snippets in the ilogic editor.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 5 of 5
Marcus_Chong
in reply to: A.Acheson

Hi @A.Acheson ,

 

This two lines is just to assign Parameter to oShellID, and then to push the parameter to designated component.

 

The problem is not sure why it is showing error.

 

I have rebuilt the model from scratch, it seems working now. I will test it out again and update here. Just wondering whether any chance due to bug or maybe something wrong with the file?

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report