Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Run external rule in occurrences

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Arnold82
2713 Views, 3 Replies

Run external rule in occurrences

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

3 REPLIES 3
Message 2 of 4
Vladimir.Ananyev
in reply to: Arnold82

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

Message 3 of 4
Arnold82
in reply to: Arnold82

I will try this as soon as I work on the project again!

 

Looks great, thanks,

 


Arnold

Message 4 of 4
naresh_kalyan
in reply to: Arnold82

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report