Run iLogic rule of the parts in assembly

Run iLogic rule of the parts in assembly

andrea.franceschini
Explorer Explorer
5,133 Views
9 Replies
Message 1 of 10

Run iLogic rule of the parts in assembly

andrea.franceschini
Explorer
Explorer

Hello, I'm new here and I don't have a good knowledge of iLogic, but me and a colleague of mine are trying to solve a problem on an assembly.

We have in this assembly a lot of adaptive parts, and in every one of them there's an iLogic rule that change its part number with the name Pipe + lenght (witch is adaptive).

My problem is that in the assembly I have to rename all the different parts, and doing so it renames also the part number, and I have to run the rule part by part to restore it.

So in the assembly we tried with the iLogic rule 

iLogicVb.RunRule("Partname", "iLogic_rule")

 In witch Partname is obviously the part name, and iLogic_rule is the name we gave to the rule of the part, but to make it work we have to repeat it for every part.

Is it possible to write a rule that can update this rule in every part?

I tried to search for a solution but for now I'm not good enough to undestand some of it.

 

Thanks

0 Likes
Accepted solutions (1)
5,134 Views
9 Replies
Replies (9)
Message 2 of 10

Daan_M
Collaborator
Collaborator

Hi,

 

You could use something like this:

 

 

Sub Main()
	
Try
	
Dim oOcc As ComponentOccurrence
Dim oAss As AssemblyDocument
oAss = ThisDoc.Document

Dim oTempName As String

For Each oOcc In oAss.ComponentDefinition.Occurrences
	oTempName = oOcc.Name
	iLogicVb.RunRule(oTempName, "Your rule name") 'assuming its the same in all parts
Next

Catch ex As Exception
	MsgBox(ex)
	Exit Sub
End Try

End Sub

 

 

If you rules are named differently in all your assembly parts, you'll need to retrieve all the iLogic rule names in all occurences. Then manually assign the rules to the right component occurence inside iLogic with

 

iLogicVb.RunRule("Partname", "iLogic_rule")

 

Cheers

 

 

Message 3 of 10

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @andrea.franceschini 

Although the rule given by @Daan_M should work, I think it would be better to use the referenced documents instead of the occurrences. This is because the assembly could contain multiple occurrences of the same part and that would result in the rule being ran in the same part document once for each occurrence of the part in the document.

 

This will run the rule just once for every part document in the assembly 🙂

 

iLogicVb.UpdateWhenDone = True
Dim oAsm As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject AndAlso _
		oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		On Error Resume Next
		iLogicVb.Automation.RunRule(oRefDoc, "iLogic_rule")
	End If
Next

It will also get all sub occurrences aswell.

Message 4 of 10

andrea.franceschini
Explorer
Explorer

Great, it works!

 

Thank you very much!

Message 5 of 10

Daan_M
Collaborator
Collaborator

@JhoelForshav I didn't think about the same part inside the assembly multiple times, smart...

Message 6 of 10

t_fransman
Advocate
Advocate

I need an identical rule forced to run in a sub assembly when true or false is changed in the form. I have to go to the sub-assembly and run the rule it's annoying. Node is Named "BottomWeldment". Rule runs in the top level assembly but not "BottomWeldment". The rule has same name and basically does same thing, turns stuff on vis and ref or default. Just can't seem to trigger it from top level. Rule name is "Door Hand".

0 Likes
Message 7 of 10

Curtis_Waguespack
Consultant
Consultant
0 Likes
Message 8 of 10

myronHBBUW
Contributor
Contributor

This is great for parts, but it does not seem to work for my sub assemblys.

Do you know what is wrong maybe?

 

Tanks

 

0 Likes
Message 9 of 10

Daan_M
Collaborator
Collaborator

Hi,

 

I don't think Jhoel is very active on the forum lately. I suggest you make a new post since this one was over half a year ago and is already solved.

0 Likes
Message 10 of 10

DANIEL.DELANEY
Advocate
Advocate

Just add this: 

Or oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject

After .kPartDocumentObject.

Then it will do it to sub-assemblies also.

Revised script below:

iLogicVb.UpdateWhenDone = True
Dim oAsm As AssemblyDocument = ThisDoc.Document
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Or oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject AndAlso _
		oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		On Error Resume Next
		iLogicVb.Automation.RunRule(oRefDoc, "iLogic_Rule")
	End If
Next  

 

0 Likes