Hi @khadeerkruthi. I assume that first code is within an internal iLogic rule that is saved within the flange part, and not within an external iLogic rule, right? If so, then one additional thing that may be needed is a way to trigger this rule to run automatically when the value of that parameter changes. One way to do that, when you are working with an 'internal' iLogic rule only, is to include the blue, unquoted name of that parameter somewhere within that rule. That will cause the rule to run automatically whenever its value changes. I often just use a 'dummy variable' for this, which is a variable that is not used for anything, and I am simply setting its value to that parameter's value. That is usually enough to enable this behavior, as long as you do not have automatic triggering turned off in the settings.
Next, I would highly advise you to update your code to the newer system of dealing with materials. The system you are using has been outdated since around 2013, but for some reason they continue to let codes like that keep working. See the following online help documentation about this issue:
Consistent Materials (Materials and Appearances)
I have included a code example below that could be used to replace your existing iLogic rule code, with updated objects and methods being used within it. I customized it a bit to suit your custom situation. You will notice on Line 2 that I am just including that line of code to enable the automatic triggering behavior. As mentioned, that will only work in internal rules, not in external rules. I put all the 'feedback' as input into the iLogic Log window, instead of MessageBox.Show or MsgBox messages, since you want to be able to run this remotely (from an assembly).
PS. The other important difference is my code is using the 'ThisDoc.Document' phrase to get the Document that the rule is supposed to be focused on, while your code was using 'ThisApplication.ActiveDocument' phrase. The phrase your code was using will be pointing to the assembly when the rule gets ran from the assembly, because that is still the 'active' document in that situation, not the part. The phrase I am using will refer to the 'local' document (the document that the rule is saved within, if used from an internal rule, but if used from an external rule, then it will refer to essentially the same document as ThisApplication.ActiveEditDocument instead. But it is a very dynamic term, with a whole block of code supporting how it works in the background, in various scenarios.
Sub Main
oTrigger = flangeMaterial
Dim oPDoc As PartDocument = TryCast(ThisDoc.Document, Inventor.PartDocument)
If oPDoc Is Nothing Then
Logger.Debug("The iLogic rule named '" & iLogicVb.RuleName & _
"' exited, because no PartDocument was obtained!")
Return
End If
Dim oParams As Inventor.Parameters = oPDoc.ComponentDefinition.Parameters
Dim oMaterialParam As Inventor.Parameter = Nothing
Dim sParamName As String = "flangeMaterial"
Try : oMaterialParam = oParams.Item(sParamName) : Catch : End Try
If oMaterialParam Is Nothing Then
Logger.Debug("Could not find the Parameter named " & sParamName)
Return
End If
Dim sMaterialName As String = oMaterialParam.Value
Dim oFlangeMaterialAsset As MaterialAsset = Nothing
For Each oMaterialAsset As MaterialAsset In oPDoc.MaterialAssets
If oMaterialAsset.DisplayName = sParamName Then
oFlangeMaterialAsset = oMaterialAsset
Exit For
End If
Next oMaterialAsset
If oFlangeMaterialAsset Is Nothing Then
Logger.Debug("Could not find specified material asset within Part material assets!")
Return
End If
Try
oPDoc.ActiveMaterial = oFlangeMaterialAsset
Catch ex As Exception
Logger.Error("Error setting ActiveMaterial of Part!" & vbCrLf & ex.Message)
End Try
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)