Sending Parameters to Parts with ilogic

Sending Parameters to Parts with ilogic

Anonymous
Not applicable
4,941 Views
14 Replies
Message 1 of 15

Sending Parameters to Parts with ilogic

Anonymous
Not applicable

I have created an assembly with a form to change various parameters of the parts within this assembly. I have been sending these parameters individually using  a rule as shown below:

 

SyntaxEditor Code Snippet

Parameter("2223 00 01 11:1", "Conveyor_Length")= Conveyor_Length

 

This works fine for the current assembly, but if i want to do a copy design of this, then the rule does not update, and hence my form no longer works.

 

Is there a way to send all my user parameters to all parts within the assembly? I do not want to send model parameters though, as these have common names in all parts but whose values are different. (I have made sure that the user parameters in the assembly and in the parts have the same name.) Does it matter that in some of my parts, some of the named parameters that i am using are model parameters?

 

Thanks

 

Mark

0 Likes
4,942 Views
14 Replies
Replies (14)
Message 2 of 15

Xun.Zhang
Alumni
Alumni

Hi @Anonymous,

 

I think you are working on Inventor 2017, right? It seems a problem in 2017 and was fixed in 2018 already, have you tried in Inventor 2018?

 

Hope it helps!


Xun
0 Likes
Message 3 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous,

 

Here is a quick rule that runs through the assembly occurrences and then looks through the user parameters and attempts to set any user parameter to be the same value as the assembly parameter of the same name.

 

Using this method you don't need to be concerned with the occurrence names, once you've copied the assembly and components.

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

iLogicVb.UpdateWhenDone = True
Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
Dim oOcc As ComponentOccurrence
Dim oOcc_s As ComponentOccurrences = oCompDef.Occurrences
Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters
'look at each occurrence in the assembly
For Each oOcc In oOcc_s
	'look at each parameter in the occurrence
	For Each oParam In oUserParams
		'ignore errors when parameter is not found
		Parameter.Quiet = True
		'try to set the parameter in the occurence to match
		'the parameter in the assembly
		Parameter(oOcc.Name,oParam.Name) = Parameter(oParam.Name)
	Next
Next

 

EESignature

0 Likes
Message 4 of 15

Anonymous
Not applicable

Thanks Curtis,

 

That works thanks. The only problem is that the rule only runs when i manually click on it and tell it to run. All my other rules run automatically when i change a parameter in my form. Is there a way to make this run when i make a parameter change?

 

Regards

 

Mark

0 Likes
Message 6 of 15

Anonymous
Not applicable

... I've tried adding the rule to run after "Any Model Parameter Change" in the event triggers tool, but no joy. I've ended up listing all my user parameters in the rule and putting them equal to themselves and it works, but there must be a simpler way no?

 

Also it is not working for parts within sub assemblies. is there a way to do this from the top level assembly, or do i have to create another rule in the sub assembly?

0 Likes
Message 7 of 15

smilinger
Advisor
Advisor

Maybe you should consider using layout technique instead of using iLogic to pass parameters around. Change your parameters in layout part only and make other components link/derive parameters from the layout.

 

And the code below should solve your problem:

 

Sub Main()
	'uncomment this line to set as trigger
	'trigger = Conveyor_Length + Conveyor_Height + Conveyor_Width + ...

	Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
	Dim oOcc_s As ComponentOccurrences = oCompDef.Occurrences
	Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters
	'look at each occurrence in the assembly
	For Each oOcc As ComponentOccurrence In oOcc_s
		'update params for each occurrence
		UpdateParam(oOcc,oUserParams)
	Next
	iLogicVb.UpdateWhenDone = True
End Sub
Sub UpdateParam(occ As ComponentOccurrence, params As Inventor.UserParameters)
	Dim oParams As Parameters = occ.Definition.Parameters
	For Each param As UserParameter In params
		If oParams.IsExpressionValid(param.Name, param.Units) Then
			oParams(param.Name).Value = param.Value
		End If
	Next
	For Each subOcc As ComponentOccurrence In occ.SubOccurrences
		UpdateParam(subOcc, params)
	Next
End Sub

 

0 Likes
Message 8 of 15

Anonymous
Not applicable

Thanks smilinger,

 

That code is working well, but I am having a few problems with it.

 

Firstly, the code will only send the numerical user parameters. Is there a way to send text and Boolean parameters across too?

 

Secondly, if I have any supressed parts in the assembly, I get an error (see below)

Is there a way to just ignore any supressed parts?

 

Thanks in advance

 

Mark

 

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

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.ComponentOccurrence.get_Definition()
   at LmiRuleScript.UpdateParam(ComponentOccurrence occ, UserParameters params)
   at LmiRuleScript.Main()
   at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
   at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

 

0 Likes
Message 9 of 15

Anonymous
Not applicable

I think I've found a solution if anyone is interested:

 

 

 

Sub Main()

    Dim oDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim oCompDef As AssemblyComponentDefinition = oDoc.ComponentDefinition
    Dim oOcc_s As ComponentOccurrences = oCompDef.Occurrences
    Dim oUserParams As UserParameters = oCompDef.Parameters.UserParameters
    'look at each occurrence in the assembly
    For Each oOcc As ComponentOccurrence In oOcc_s
        'update params for each occurrence
        UpdateParam(oOcc,oUserParams)
    Next
    iLogicVb.UpdateWhenDone = True
End Sub
Sub UpdateParam(occ As ComponentOccurrence, params As Inventor.UserParameters)

 If Component.IsActive(occ.Name) = True

    Dim oParams As Parameters = occ.Definition.Parameters
    For Each param As UserParameter In params
        Try 
        oParams(param.Name).Value = param.Value
        Catch
        End Try
    Next
    
    For Each subOcc As ComponentOccurrence In occ.SubOccurrences
        UpdateParam(subOcc, params)
    Next
 End If
End Sub

 

 

 

0 Likes
Message 10 of 15

Anonymous
Not applicable

I'm nearly there with this code (see above post) but there are a couple of things i would like to improve.

 

Firstly, is there a way to change this so it works if i have any weldments in the assembly? I get the following error:

Public member 'Parameters' on type 'WeldsComponentDefinition' not found.

 

Secondly, i have some assemblies with patterns in, and so when i run the rule it is taking longer and longer the larger the pattern. Is there a way to make this rule more efficient so it only sends parameters to the first occurence of every part/sub assembly?

 

Thanks

0 Likes
Message 11 of 15

RogerTheShrubber
Advocate
Advocate

Thanks for the question, I am trying to accomplish the same thing.  I was having the same problem getting the rule to trigger.  Turns out that I was changing a Model Parameter, not a User Parameter, so the rule would not trigger.  I created a sketch at the assembly level which had dimensions that referenced all my user parameters.  This created  Model Parameters that would change whenever the User Parameter changed.  Copy Parameter rule triggered.

0 Likes
Message 12 of 15

R.Mabery
Advocate
Advocate

Mark,

 

Yes, you can go loop thru the occurrences and push parameters.  It looks like others have helped you with that. 

 

You can also stabilize the browser node names in your assembly (before you copy design).  That way, the "2223 00 01 11:1" portion of your code is always written to something like "Conveyor_Weldment" or whatever you stabilize the node name as.  

 

You'll have to change the code as well.  Code to the stabilized node name.

 


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 13 of 15

Anonymous
Not applicable
Oh wow... Great advice! You're an Applications Expert with iMAGINIT?
0 Likes
Message 14 of 15

R.Mabery
Advocate
Advocate

Yep.


Thanks,
Randy Mabery
Applications Expert
IMAGINiT Technologies
0 Likes
Message 15 of 15

Charbel.yammine
Participant
Participant

Hello Curtis,

 

What is the best way to push multiple parameters using ilogic to multiple parts and replace them and their drawing if they already exist in Vault.

 

https://www.youtube.com/watch?v=6-GNaoGu40w

 

trying to achieve exactly what was described in this video.

 

do you have a sample code for that?

 

Thanks

0 Likes