Hi,
I am just posting some code I got working.
This selects the component edges and changes the property of those. I would still prefer to change the component property if someone knows how to do this?
I am also open to any improvements.
sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
Call MsgBox("This macro only works on drawing documents.")
Exit Sub
End If
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim refAssyDef As ComponentDefinition
Dim oColor As Color
Dim oTrans As Transaction = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Colorize [PART]")
For Each sheet As Sheet In oDoc.Sheets
For Each view As DrawingView In Sheet.DrawingViews
If View.ReferencedDocumentDescriptor.ReferencedDocumentType = DocumentTypeEnum.kPresentationDocumentObject Then
refAssyDef = View.ReferencedDocumentDescriptor.ReferencedDocument.ReferencedDocuments(1).ComponentDefinition
ElseIf View.ReferencedFile.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
refAssyDef = View.ReferencedFile.DocumentDescriptor.ReferencedDocument.ComponentDefinition
End If
If (refAssyDef Is Nothing) Then
Continue For
End If
For Each occurrence As ComponentOccurrence In refAssyDef.Occurrences
if occurrence.Name.Contains("SubAssembly1")Then
oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 255) 'RGB Blue
Call ProcessColour(occurrence, view, oColor)
end if
if occurrence.Name.Contains("SubAssembly2")Then
oColor = ThisApplication.TransientObjects.CreateColor(0, 128, 0) 'RGB Green
Call ProcessColour(occurrence, view, oColor)
end if
if occurrence.Name.Contains("SubAssembly3") Then
oColor = ThisApplication.TransientObjects.CreateColor(128, 0, 255) 'RGB Purple
Call ProcessColour(occurrence, view, oColor)
end if
Next
Next
Next
oTrans.End()
end sub
Private Sub ProcessColour(occurrence As ComponentOccurrence, view As DrawingView, oColor As Color )
Try
Dim ViewCurves As DrawingCurvesEnumerator = View.DrawingCurves(occurrence)
For Each c As DrawingCurve In ViewCurves
c.Color = oColor
Next
Catch ex As Exception
msgbox(ex)
End Try
End Sub