Apply material without affecting the existing appearances? Need VBA help

Does anyone know to change the material in a SOLIDWORKS part without affecting the existing appearance? Basically, we don’t want the material to apply its texture and messing up the existing appearance.

Edit: I need a VBA macro. or some directions…

If you uncheck the “Apply appearance” on the Appearances tab before applying the material then it won’t change your chosen appearance.

1 Like

@BigCrazyAl : Is there a way to do this via the API?

@AmenJlili Woops! I missed that tag.

I have to give credit where it’s due to @artem for his library of code snippets from the link below.

'**********************
'Copyright(C) 2020 Xarial Pty Limited
'Reference: https://www.codestack.net/solidworks-api/document/materials/change-apply-appearance/
'License: https://www.codestack.net/license/
'**********************

Dim swApp As SldWorks.SldWorks
Dim swPart As SldWorks.PartDoc

Sub main()

    Set swApp = Application.SldWorks
    
    Set swPart = swApp.ActiveDoc
    
    If Not swPart Is Nothing Then
        
        Dim swMatVisPrps As SldWorks.MaterialVisualPropertiesData
        Set swMatVisPrps = swPart.GetMaterialVisualProperties
        swMatVisPrps.ApplyAppearance = False
        
        swPart.SetMaterialVisualProperties swMatVisPrps, swInConfigurationOpts_e.swAllConfiguration, Empty
    Else
        MsgBox "Please open part document"
    End If
    
End Sub
1 Like

@BigCrazyAl : Thanks. Seems to work now.
@artem : Thanks for the code. Does this work if the document and sldworks are hidden?

@AmenJlili, I have never checked, but I doubt it. Usually, anything related to visuals requires models to be visible, although there seems to be no reason to have doc visible to apply the material, but you never know…

1 Like