Is it possible to run an external rule in assembly occurrences?
You have RunRule in Component, But it does not seem to work with external rules
I referenced to occurrences and opened it using ThisApplication.Documents.Open(filepath, False)
Then i tried calling the same external rule. I thought it would run the external rule in the opened file,
but I ended up with a infinite loop on the main assembly.
Is there a way to run your rule in every occurrence with external?
Thanks in advance,
Arnold
Solved! Go to Solution.
Solved by Vladimir.Ananyev. Go to Solution.
iLogic has several functions to run external rules in any components.
It is not needed to open component’s documents invisibly because there are already loaded.
The following sample rules assume that
You should change these values to meet your requirements.
Rule “Run_External_NoArgs” in assembly document:
'Get component by its name Dim oComp As Componentoccurrence = Component.InventorComponent("ROD") 'reference to document for this component Dim oDoc as Inventor.Document = ocomp.definition.Document 'external rule filename Dim ExternalRuleFile As String = "C:\TEMP\MyRules\1.txt" 'run external rule auto = iLogicVb.Automation auto.RunExternalRule(oDoc, ExternalRuleFile) Beep
Rule “Run_External_Args” in assembly document:
'Get component by its name Dim oComp As Componentoccurrence = Component.InventorComponent("ROD") 'reference to document for this component Dim oDoc as Inventor.Document = ocomp.definition.Document ' External rule filename Dim ExternalRuleFile As String = "C:\TEMP\MyRules\1.txt" 'fill argument's list Dim map As NameValueMap = ThisApplication.transientobjects.CreateNameValueMap map.Add("Property", "Part Number") map.Add("Parameter", "d0") 'run external tule with parameters auto = iLogicVb.Automation auto.RunExternalRuleWithArguments(oDoc, ExternalRuleFile, map) Beep
The text of external rule saved in the file "C:\TEMP\MyRules\1.txt".
The rule is able to respond to the arguments of "Property" and "Parameter". If the arguments pass correct names, the rule displays a message with the values specified by the property and parameter. If no arguments are detected then message box shows component's document full filename only.
'get this document display name dim Name as string = thisdoc.document.FullFilename 'check if the rule got arguments dim St1 as string dim St2 as string dim Arg as string If RuleArguments.Exists("Property") Then try Arg = RuleArguments("Property") St1 = iProperties.Value("Project", Arg) Catch St1 = "Wrong property name" End try end if If RuleArguments.Exists("Parameter") Then try Arg = RuleArguments("Parameter") St2 = cstr(Parameter(Arg)) Catch St2 = "Wrong parameter name" End try end if msgbox("RESULTS " & vbnewline & _ Name & vbnewline & _ St1 & vbnewline & _ St2)
Hope this helps.
Greetings... Happy New Year 2015.
Hi One & All,
I'm facing a problem with iLogic. I have bunch of Parts in which few Parts contains iLogic rules and few does not contain any rules.
I could able to trigger the Rules through VBA, using iLogicAuto.runrule oPrtDoc, RuleName
But, this is failing as some of Parts does not contain any Rules.
All I need to put a condition to check, whether the Part contain iLogicRules > If yes then Run the Rule. For Example...
If iLogicAuto.RuleExists ("RuleName") then 'Only for Example, this is not a code
iLogicAuto.runrule oPrtDoc, RuleName
end if
Regards
NKalyan