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
- Component name is “ROD”
- External rule is saved in the file "C:\TEMP\MyRules\1.txt"
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.
Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network