Ilogic rule to set a part to disable/enable by keyword

Ilogic rule to set a part to disable/enable by keyword

ILU
Enthusiast Enthusiast
869 Views
3 Replies
Message 1 of 4

Ilogic rule to set a part to disable/enable by keyword

ILU
Enthusiast
Enthusiast

I am new to ilogic but i am pretty sure that is possible
I am looking for a rule to set to disable a part if text parameter is set to No/ Yes.
we are using in all assemblies as a prefix a project number and we have few assemblies where same part it is used.
For example P12345_part(3):1
I am looking for a piece of code to find to find the "part(3)" into assembly and set it to disable.
Thanks in advance

0 Likes
Accepted solutions (2)
870 Views
3 Replies
Replies (3)
Message 2 of 4

RO-ENG
Explorer
Explorer
Accepted solution

The code below will probably work for you, it will look trough each component and check if the name contains "part(3)" if it does it will suppress the part if the parameter "EnablePart" is set to No, and it will unsuppres if it is set to Yes, when the parameter is on neither yes or no, it will also suppress te feature. Important to note is that you would have to make a custom level of detail for the code to work though

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
	If (oOccurrence.Name.Contains("part(3)")) Then
		Dim Enabled As Boolean = (EnablePart = "Yes")
		Component.IsActive(oOccurrence.Name) = Enabled
	End If
Next
 

 

0 Likes
Message 3 of 4

Mirtchii
Advocate
Advocate

Hi ILU,

You can try using this. No need to make a new Level of detail too.

First, create a true/false parameter named "part 3" then paste the below code to the coding space.

 

ThisAssembly.BeginManage()

If (part3) Then
*****
End If
ThisAssembly.EndManage()

*****: You have to look at the Model tab in Rule window, right click on the part that you want ( in this case P12345_part(3)) and choose "Capture current state" to finish the code.

 

Hope you can solve your problem.

0 Likes
Message 4 of 4

ILU
Enthusiast
Enthusiast
Accepted solution

Thanks @RO-ENG 

the code worked flawlessly. Finaly mine rule looked like below

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
	If oOccurrence.Name.Contains("keyword") Then
		Dim Part As Boolean = (Parameter = "YES")
					
	End If
Next
oPart = Component.InventorComponent(oOccurrence.Name)


If Parameter = "YES" Then
	oPart.Visible= True
	oPart.Enabled = True
		
	Else
		oPart.Visible = False
		oPart.Enabled = False
		
	End If
	
iLogicVb.UpdateWhenDone = True