I'm in the process of creating an iLogic that would allow a user to select parts in an assembly then run the rule to select from a radio button to either add or remove a customer supplied part this would then add a Instance Property called CSP and add an X for the value. Then I have it set up to change the color of the part to red so the user sees its different (Not sure if there is a way to do this for all representations but that would be helpful) but I would also like to add a 3D annotation leader text to the part. When the user selects the remove CSP it would undo all of these changes. I need a little help on creating the instances and the 3D annotations. Below is the current code I have that is definitely a work in progress.
Sub Main
oDoc = ThisAssembly.Document
oADef = oDoc.ComponentDefinition
oOccs = oADef.Occurrences
oTrans = ThisApplication.TransactionManager.StartTransaction(oDoc, "Rename Components W/ SN")
Dim oSelectSet As SelectSet = ThisDoc.Document.SelectSet
CSPSelection = InputRadioBox("Select what process.", "Add Customer Supplied Part", "Remove Customer Supplied Part", booleanParam, Title := "Select a Option")
If CSPSelection = True Then
''Add Customer Supplied Part
If oSelectSet.Count = 0 Then 'nothing was pre-selected
oSelectedView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartDefaultFilter, "Select Part")
Else
Dim oPreSelectedParts As New List(Of DrawingView)
For Each oObj In oSelectSet
If TypeOf oObj Is DrawingView Then
Dim oSelView As DrawingView = oObj
oPreSelectedParts.Add(oSelView)
End If
Next
If oPreSelectedParts.Count = 0 Then Exit Sub 'none of pre-selected was view
For Each oView As DrawingView In oPreSelectedViews
'do what you need to do to each view here
Next
End If
ColorChangePart(oOccs)
Else If CSPSelection = False Then
''Remove Customer Supplied Part
If oSelectSet.Count = 0 Then 'nothing was pre-selected
oSelectedView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartDefaultFilter, "Select Part")
Else
Dim oPreSelectedParts As New List(Of DrawingView)
For Each oObj In oSelectSet
If TypeOf oObj Is DrawingView Then
Dim oSelView As DrawingView = oObj
oPreSelectedParts.Add(oSelView)
End If
Next
If oPreSelectedParts.Count = 0 Then Exit Sub 'none of pre-selected was view
For Each oView As DrawingView In oPreSelectedViews
'do what you need to do to each view here
Next
End If
ColorRemovePart(oOccs)
End If
oTrans.End
End Sub
Sub ColorChangePart(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
Try
If oComp.OccurrencePropertySetsEnabled Then
Dim oInstPSet As PropertySet = oComp.OccurrencePropertySets.Item(1)
Dim oInstP As Inventor.Property = oInstPSet.Item("CSP")
Dim oSN As String = oInstP.Value.ToString
If oSN = "X" Then
Dim topAsm As AssemblyDocument = ThisDoc.Document
Dim uAppearance As Asset = topAsm.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", "CUSTOMER SUPPLIED")
Dim uColor As ColorAssetValue = uAppearance.Item("generic_diffuse")
' Dim RNG = Math.Round(Rnd() * 255)
' Dim RNG1 = Math.Round(Rnd() * 255)
' Dim RNG2 = Math.Round(Rnd() * 255)
uColor.Value = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
'Random Color
'uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG,RNG1,RNG2)
oComp.Appearance = uAppearance
Else If oSN = "" Then
End If
End If
Catch
End Try
If oComp.SubOccurrences.Count > 0 Then
ColorChangePart(oComp.SubOccurrences)
End If
Next
End Sub
Sub ColorRemovePart(oComps As ComponentOccurrences)
If IsNothing(oComps) OrElse oComps.Count = 0 Then Exit Sub
For Each oComp As ComponentOccurrence In oComps
Try
If oComp.OccurrencePropertySetsEnabled Then
Dim oInstPSet As PropertySet = oComp.OccurrencePropertySets.Item(1)
Dim oInstP As Inventor.Property = oInstPSet.Item("CSP")
Dim oSN As String = oInstP.Value.ToString
If oSN = "" Then
'Dim topAsm As AssemblyDocument = ThisDoc.Document
'Dim uAppearance As Asset = topAsm.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", "CUSTOMER SUPPLIED")
'Dim uColor As ColorAssetValue = uAppearance.Item("generic_diffuse")
' Dim RNG = Math.Round(Rnd() * 255)
' Dim RNG1 = Math.Round(Rnd() * 255)
' Dim RNG2 = Math.Round(Rnd() * 255)
'uColor.Value = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
'Random Color
'uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG,RNG1,RNG2)
'oComp.PartComponentDefinition.ClearAppearanceOverrides
oComp.AppearanceSourceType = kPartAppearance
Else If oSN <> "" Then
End If
End If
Catch
End Try
If oComp.SubOccurrences.Count > 0 Then
ColorChangePart(oComp.SubOccurrences)
End If
Next
End Sub
Your code is accessing drawing views which is for the drawing document views was that your intention?
For design view reps in the assembly here is the API help for RepresentationsManager
Syntax
AssemblyComponentDefinition.RepresentationsManager() As RepresentationsManager
Syntax
RepresentationsManager.DesignViewRepresentations() As DesignViewRepresentations
Can't find what you're looking for? Ask the community or share your knowledge.