Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everybody.
I want to write a macro to change color, line type, line weight by selecting part in the assembly drawing, but I want to change part color in only 1 view, other views have no effect.
The code below is what I collected from the forum. This code changes the part color in all views.
I have edited it a bit the way I understand it.
Can you help me edit the code according to my wishes? Or if you have better code, please share me.
Option Explicit
Sub Main()
Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument
Dim partStr As String
partStr = GetPartName()
Dim oTrans As Transaction
Dim ViewCurves As DrawingCurvesEnumerator
Dim refAssyDef As ComponentDefinition
Dim oColor As color
Set oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
Set oTrans = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Colorize [PART]")
Dim i As sheet
Dim j As DrawingView
Dim k As ComponentOccurrence
Dim c As DrawingCurve
For Each i In oDoc.Sheets
For Each j In i.DrawingViews
If j.ReferencedDocumentDescriptor.ReferencedDocumentType = kPresentationDocumentObject Then
Set refAssyDef = j.ReferencedDocumentDescriptor.ReferencedDocument.ReferencedDocuments(1).ComponentDefinition
ElseIf j.ReferencedFile.DocumentType = kAssemblyDocumentObject Then
Set refAssyDef = j.ReferencedFile.DocumentDescriptor.ReferencedDocument.ComponentDefinition
End If
For Each k In refAssyDef.Occurrences
If k.name = partStr Then
Set ViewCurves = j.DrawingCurves(k)
For Each c In ViewCurves
c.color = oColor
c.LineType = kDashDottedLineType
c.LineWeight = 0.05
Next
End If
Next
Next
Next
oTrans.End
End Sub
Function GetPartName() As String
Dim oOccioV As DrawingCurveSegment
Set oOccioV = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Seleziona Componente")
Dim oView As DrawingView
Set oView = oOccioV.Parent.Parent
Dim oToccoH As Object
Set oToccoH = oOccioV.Parent.ModelGeometry.Parent.Parent
GetPartName = oToccoH.name
End Function
Solved! Go to Solution.