Run External Rule in each part

Run External Rule in each part

NikelARH4K2
Contributor Contributor
255 Views
3 Replies
Message 1 of 4

Run External Rule in each part

NikelARH4K2
Contributor
Contributor

I am trying to repurpose this code to instead of running that rule in each assembly but find each part in a assembly that has that rule in it and run a external rule in each part. But i want it to only run the external rule if the part already has "Master_Parts_List" in it.  I am having difficulty getting it to work, help would be appreciated 

Dim oDoc As AssemblyDocument = ThisDoc.Document
 
'define the ilogicAutomation
Dim iLogicAuto As Object 
iLogicAuto = iLogicVb.Automation 
 
Dim oRuleName As String = "Master_Parts_List" 
Dim oRule As Object 
 
For Each doc As Document In oDoc.AllReferencedDocuments
On Error Resume Next
oRule = iLogicAuto.GetRule(doc, oRuleName) 
 
iLogicAuto.RunRuleDirect(oRule) 
Next
0 Likes
256 Views
3 Replies
Replies (3)
Message 2 of 4

mslosar
Advisor
Advisor

The API has a sample on looping through the Structured Bom view of an assembly. You can loop through it and execute the rule on everything i t runs into - including sub assemblies.

0 Likes
Message 3 of 4

NikelARH4K2
Contributor
Contributor

Is in one of these?

NikelARH4K2_0-1697141322858.png

 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @NikelARH4K2.  If I am understanding your request correctly, then you want to run a rule from the main assembly that will find every part (not sub assembly) being referenced within the main assembly, and check if it contains an internal iLogic rule named "Master_Parts_List", and if it does, then run an external iLogic rule by the same name in a way that it will focus on that part that contained the internal rule.  Does that sound accurate?  If so, then I believe that the following iLogic rule should work OK for you.

Dim oDoc As Document = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments
For Each oRefDoc As Document In oRefDocs
	'next line checks if it is a part, and if not, skips to next oRefDoc in loop
	If oRefDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
	'if the rule is not found, it will not throw an error
	Dim oRule As iLogicRule = iLogicVb.Automation.GetRule(oRefDoc, "Master_Parts_List")
	If oRule Is Nothing Then Continue For
	iLogicVb.Automation.RunExternalRule(oRefDoc, "Master_Parts_List")
Next

That final method for running the external rule allows us to input the document that we want the external rule to focus on.  However, that functionality is not necessarily guaranteed, because it depends somewhat on how your external rule is coded.  If it uses the 'ThisDoc.Document' term, then that is a step in the right direction.  But some of the simpler looking iLogic snippets that do not include any specification for which document they will focus on may, or may not work properly that way.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes