Set a line type for a specific part in the drawing view

By Xiaodong Liang

Issue
I would like to change the way a linetype appears for a specific part, globally throughout my drawing package. I am currently selecting the part in the model tree in the browser and changing it that way, but I have to do it on multiple views, for multiple pages and am wondering if there is a quicker way.

Solution
When you select a part of the drawing, it actually gets the corresponding drawing curves appearing in the drawing view and set their line type. So with code, you need to get the curves firstly. Following is a code demo:

Sub changeLT()

    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
   
    Dim oEachSheet As Sheet
    Dim oEachView As DrawingView
   
    For Each oEachSheet In oDoc.Sheets
      For Each oEachView In oEachSheet.DrawingViews
       
 
   ‘ if you want to change all drawing curves
    ‘ *****************
    ‘       Dim oDrwCs As DrawingCurvesEnumerator
    ‘       Set oDrwCs = oEachView.DrawingCurves()
    ‘
    ‘       Dim oEachDrwC As DrawingCurve
    ‘       For Each oEachDrwC In oDrwCs
    ‘
    ‘        ‘change the line type
    ‘        oEachDrwC.LineType = kDashedHiddenLineType
    ‘        ‘ change the line weight
    ‘        oEachDrwC.LineWeight = oEachDrwC.LineWeight * 2
    ‘  
    ‘ ***********************

           
    ‘ if you want to change the curves from specific part, assume the referenced document of
    ‘ the drawing view is from an assembly.
       
        ‘get the referenced document

        Dim oRefDoc As Document
        Set oRefDoc = oEachView.ReferencedDocumentDescriptor.ReferencedDocument
       
        If TypeOf oRefDoc Is AssemblyDocument Then
       
    ‘ this is an assemly
           
            Dim oEachOcc As ComponentOccurrence
           
            For Each oEachOcc In oRefDoc.ComponentDefinition.Occurrences
               If TypeOf oEachOcc.Definition.Document Is PartDocument Then
               
‘ if this is the part you want to change
                 If oEachOcc.Name = "Part1:1" Then
                
                 
‘get the drawing cruves the part generates
                   Dim oDrwCs_part As DrawingCurvesEnumerator
                   Set oDrwCs_part = oEachView.DrawingCurves(oEachOcc)
                   
                    Dim oDrwC_part As DrawingCurve
                    For Each oDrwC_part In oDrwCs_part
                   
                     ‘change the line type
                     oDrwC_part.LineType = kDashedHiddenLineType
               
     ‘ change the line weight
                     oDrwC_part.LineWeight = oDrwC_part.LineWeight * 2
                     Next
                     End If
               End If
            Next
         End If
       
      Next
    Next
End Sub


Comments

One response to “Set a line type for a specific part in the drawing view”

  1. Broman Avatar
    Broman

    Is there a way to check for a certain line type and then perform an action based on what the line type is? When I perform a check on drawing curves in a view, all I get is “kDefaultLineType” on every line, regardless of whether it is a visible line or a hidden line. I would like to be able to filter based on whether it is a continuous line type and ignore other line types.

Leave a Reply to BromanCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading