08-08-2024
03:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
08-08-2024
03:17 PM
A quick update to the previous example, this one only colors components named in a list
Imports System.ComponentModel
AddReference "System.drawing"
Imports System.Windows.Forms
Imports System.Drawing
Sub Main
Dim myList As New List(Of String)(New String() {"Foo", "Foo Too" }) 'list with part names
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oOccs As ComponentOccurrences = oADoc.ComponentDefinition.Occurrences
Dim oColor As Asset = GetColor
Call TraverseAssembly(oOccs, oColor, myList)
End Sub
Sub TraverseAssembly(oOccs As ComponentOccurrences, oColor As Asset, myList As List(Of String))
Dim oOcc As ComponentOccurrence
For Each oOcc In oOccs
If oOcc.DefinitionDocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
Call TraverseAssembly(oOcc.SubOccurrences, oColor, myList)
ElseIf oOcc.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
If myList.Contains(oOcc.Name) Then oOcc.Appearance = oColor
End If
Next
End Sub
Function GetColor() As Asset
Dim oClDlg As New System.Windows.Forms.ColorDialog
Dim oColor As System.drawing.Color
If oClDlg.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
oColor = oClDlg.Color
End If
oName = "Paint Color"
Dim oAppearance As Asset
Try 'create new appearance
oAppearance = ThisDoc.Document.Assets.Add(AssetTypeEnum.kAssetTypeAppearance,
"Generic", "Appearances", oName)
Catch
oAppearance = ThisDoc.Document.Assets.item(oName)
End Try
'set colors
Dim oNewColor As ColorAssetValue
oNewColor = oAppearance.Item("generic_diffuse")
oNewColor.Value = ThisApplication.TransientObjects.CreateColor(oColor.R, oColor.G, oColor.B)
Return oAppearance
End Function