Macro to update style for Parts List Style

Macro to update style for Parts List Style

sonny_jenema
Community Visitor Community Visitor
150 Views
2 Replies
Message 1 of 3

Macro to update style for Parts List Style

sonny_jenema
Community Visitor
Community Visitor

Hello! If anyone in the Autodesk community could help me, I'd greatly appreciate it! 

 

Problem statement: Our .idw drawings are using an outdated Parts List Style and need to be updated. I've created the new style that must be applied to all old .idw drawings. I have written a macro for engineers to use that checks the .idw for the old parts list style and replaces it with the new style. However, I get a "Run-time error 438" error at line  oPartsListTable.Style.TableStyleName = newStyle

 

Below is the code referenced:

 

Sub UpdatePartsListStyle()
    ' Get the active drawing document
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument

    ' Define the desired new style
    Dim newStyle As String
    newStyle = "Epicor Parts"

    ' Check if the active document is a drawing document
    If Not oDrawDoc Is Nothing Then
        ' Check if there's a parts list table on the active sheet
        If oDrawDoc.ActiveSheet.PartsLists.Count > 0 Then
            ' Assuming there's only one parts list table; adjust as needed
            Dim oPartsListTable As PartsList
            Set oPartsListTable = oDrawDoc.ActiveSheet.PartsLists.Item(1)

            ' Modify the parts list table style settings
            oPartsListTable.Style.TableStyleName = newStyle

            ' Refresh the table to apply the changes
            oPartsListTable.Refresh

            ' Notify the user
            MsgBox "Parts List style updated to '" & newStyle & "'."
        Else
            MsgBox "No parts list table found on the active sheet."
        End If
    Else
        MsgBox "The active document is not a drawing document."
    End If
End Sub

 

Is this the right approach to updating the Parts List Style? 

0 Likes
151 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @sonny_jenema.  You need to get the actual PartsListStyle object, either by copying it from the 'global' styles library to the local drawing, or by copying it from a template to the old drawing directly.  Then set that PartsListStyle object as the value of PartsList.Style property.  What you are attempting to do in your example is change a setting within the old style.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

sonny_jenema
Community Visitor
Community Visitor

Thank you! I will give that a try and see if it works. 

0 Likes