Inventor Customization

Reply
Valued Contributor
Arnold82
Posts: 56
Registered: ‎12-20-2012
Message 1 of 3 (328 Views)
Accepted Solution

Run external rule in occurrences

328 Views, 2 Replies
01-29-2013 01:48 AM

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

ADN Support Specialist
Vladimir.Ananyev
Posts: 467
Registered: ‎08-14-2012
Message 2 of 3 (297 Views)

Re: Run external rule in occurrences

02-07-2013 03:05 AM 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

Valued Contributor
Arnold82
Posts: 56
Registered: ‎12-20-2012
Message 3 of 3 (280 Views)

Re: Run external rule in occurrences

02-14-2013 04:56 AM in reply to: Arnold82

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

 

Looks great, thanks,

 


Arnold

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube