iLogic Rule, Please help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone. I am trying to make an iLogic rule that we will run from within our main assembly.
Here is what I would like it to do:
1- Loop through all of the parts within the assembly (solid, sheet metal, welded assemblies and regular assemblies)
2- Depending on the 4 filetypes, do various operations on custom parameters and user parameters.
Solid: "RayonDePliage = NA", "MaterialThickness = NA", "MaterialType = NA", "Couleur = A", change part color to "TypePiece".
Sheet: "RayonDePliage = A", "MaterialThickness = B", "MaterialType = C", "Couleur = D", change part color to "TypePiece".
Welded: "Couleur = A".
Regular: "Couleur = A".
Here is my problem:
I have a working code for all 4 custom variables (RayonDePliage, MaterialThickness, MaterialType and Couleur" which I can implement easily, but I am having a hard time changing the color of most parts. The part color should be changed to the custom user parameter "Couleur" (in iProperties), but that user parameter is driven by a multi-value custom user parameter (in Fx) called "TypePiece", which does not exists in a lot of our parts. Once the iLogic rule runs into a part/assembly that does not have that parameter (TypePiece), it just stops running somehow, so I would need to create the multi-value user parameter if it does not exist and set it to a pre-defined value called "Principale" and then proceed to change the color of the parts (for solid parts and sheet metal parts only) and set the other 4 custom variables that I have a working code for.
Here is my code, if you could help, it would mean a lot to me as I am stuck there
As a side note, if it is possible to remove the 3 duplicated "oPartDoc = oDoc" please let me know how, I tried with one "oPartDoc = oDoc" before the Select Case, and it somehow wouldn't work.
Sub Main()
'Update custom iProperties and Part Colors for clients/paintshop.
Try
' Get the active assembly document.
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
' Iterate through all of the documents referenced by the assembly.
Dim oDoc As Document
Dim oPartDoc As PartDocument
For Each oDoc In oAsmDoc.AllReferencedDocuments
' Verify the type of document.
model = oDoc.DisplayName
modelFN = oDoc.FullFileName
Select Case oDoc.SubType
'Verify if it is a solid part.
Case "{4D29B490-49B2-11D0-93C3-7E0706000000}"
oPartDoc = oDoc
MsgBox("1")
Call CustomProp(model)
oPartDoc.ActiveRenderStyle = oPartDoc.RenderStyles.Item("Rose")
'Need to add 4 custom variables here
'Verify if it is a sheet metal.
Case "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
oPartDoc = oDoc
MsgBox("2")
Call CustomProp(model)
oPartDoc.ActiveRenderStyle = oPartDoc.RenderStyles.Item("Blé")
'Need to add 4 custom variables here
'Verify if it is an assembly (regular, welded).
Case "{E60F81E1-49B3-11D0-93C3-7E0706000000}","{28EC8354-9024-440F-A8A2-0E0E55D635B0}"
oPartDoc = oDoc
MsgBox("3")
'Need to add 4 custom variables here
End Select
Next
Catch
End Try
End Sub
Sub CustomProp(modelA As String)
' Modify the "Couleur" iProperties if the parameter TypePiece exists in the part.
Try
Select Case Parameter(modelA, "TypePiece")
Case "Principale"
iProperties.Value(modelA, "Custom", "Couleur") = "RAL 1015 - Light Ivory"
Case "GalvPeint"
iProperties.Value(modelA, "Custom", "Couleur") = "Acier galvanisé"
Case "Securite"
iProperties.Value(modelA, "Custom", "Couleur") = "Lisse - Jaune"
Case "Grillage"
iProperties.Value(modelA, "Custom", "Couleur") = "Noir"
Case "Usinage"
iProperties.Value(modelA, "Custom", "Couleur") = "Acier - Poli"
Case "TraySol"
iProperties.Value(modelA, "Custom", "Couleur") = "RAL 7042 - Traffic Grey A"
Case "Autre1"
iProperties.Value(modelA, "Custom", "Couleur") = "Magenta"
Case "Autre2"
iProperties.Value(modelA, "Custom", "Couleur") = "Cyan"
Case "Autre3"
iProperties.Value(modelA, "Custom", "Couleur") = "Rouge"
Case "Autre4"
iProperties.Value(modelA, "Custom", "Couleur") = "Rose"
End Select
' If it fails, do nothing.
Catch
End Try
End Sub