Setting parameter values in another file through iLogic

Setting parameter values in another file through iLogic

mitchELAHB
Advocate Advocate
776 Views
5 Replies
Message 1 of 6

Setting parameter values in another file through iLogic

mitchELAHB
Advocate
Advocate

Hi,

 

I have an assembly, and am trying to set parameters in a sub assembly using iLogic. I have the following subroutine: 

Sub SetUserParameters(oParentDoc As Document, oChildDoc As Document, oParameterName As String)

	Dim oChildParams As Parameters = oChildDoc.ComponentDefinition.Parameters
	Dim oParentParams As Parameters = oParentDoc.ComponentDefinition.Parameters
	
	MsgBox(oParentDoc.DisplayName & ": " & oParentParams.Item(oParameterName).Name & " = " & oParentParams.Item(oParameterName).Value & vbNewLine & oChildDoc.DisplayName & ": " & oChildParams.Item(oParameterName).Name & " = " & oChildParams.Item(oParameterName).Value)
	
	'try to set parameter of child equal to parent
	Try 
		oChildParams.Item(oParameterName).Value = oParentParams.Item(oParameterName).Value
	Catch
		Try
			'create Parameter And Set
			oChildParams.UserParameters.AddByExpression(oParentParams.Item(oParameterName).Name, oParentParams.Item(oParameterName).Value, oParentParams.Item(oParameterName).Units)
		Catch
			MsgBox("Couldn't set parameter " & oParameterName & " in file " & oChildDoc.DisplayName)
		End Try
	End Try

End Sub

 

The code should set the value in the child file, and make a parameter if required, but falls through to the last catch statement implying it was unable to set the parameter.  I have tested separately both setting and adding the parameter, and I can't get either to work. What am I doing wrong?  

0 Likes
Accepted solutions (1)
777 Views
5 Replies
Replies (5)
Message 2 of 6

A.Acheson
Mentor
Mentor

Hi @mitchELAHB 

 

It looks goof to me although i haven't tested it. Did you check the value for each argument for the add expression method? There might be issues in there? I am assuming the child document is writable?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 3 of 6

mitchELAHB
Advocate
Advocate

Hi @A.Acheson 

 

After some further testing, it appears if I close inventor and re open the parent file, it functions correctly, until I open the child file. Once that file has been opened, I need to close both the parent and child files before opening the parent again. Not such a big deal in the future, but annoying for testing it now. Do you know of any work around, or why it would be behaving like this? 

 

Thanks

0 Likes
Message 4 of 6

A.Acheson
Mentor
Mentor

Can you share how your using this sub routine? It sounds like your not accessing the documents at the right time. And yes the documents being passed all have to be open visible/invisible. Simply creating a sub routine and return the FullfileName of the document will be enough to test it is accessible. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 6

WCrihfield
Mentor
Mentor

Hi guys.  This sounds like a ModelStates related issue to me.  Read the following online help documentation page for more info.

https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=GUID-418B956A-AC3F-48D8-BEBC-FC28C4B51DA2 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 6

mitchELAHB
Advocate
Advocate
Accepted solution

Hi Guys, 

 

Thanks for the input, after futhur testing it must have just been a bit of a bug in the computer. Since the last restart of the system I have not encounted this error again.

 

Thanks!

0 Likes