This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
This macro removes all colors from the part document on all levels (face, feature, body, model) using SOLIDWORKS API.
Macro can be configured to remove the colors from all configurations or active configuration only. This option can be set by changing the value of the following constant at the beginning of the macro:
Const REMOVE_FROM_ALL_CONFIGS AsBoolean = True'True to remove from all configurations, False to remove from active configuration only
Const REMOVE_FROM_ALL_CONFIGS AsBoolean = TrueDim swApp As SldWorks.SldWorks
Sub main()
Set swApp = Application.SldWorks
Dim swModel As SldWorks.ModelDoc2
Set swModel = swApp.ActiveDoc
IfNot swModel IsNothingThenIf swModel.GetType() = swDocumentTypes_e.swDocDRAWING Then
Err.Raise vbError, "", "Drawings are not supported"EndIfDim configOpts As swInConfigurationOpts_e
configOpts = GetConfigurationOptions(REMOVE_FROM_ALL_CONFIGS)
If swModel.GetType() = swDocumentTypes_e.swDocPART ThenDim swPart As SldWorks.PartDoc
Set swPart = swModel
Dim vBodies AsVariant
vBodies = swPart.GetBodies2(swBodyType_e.swAllBodies, False)
RemoveMaterialPropertiesFromBodies vBodies, True, configOpts
RemoveMaterialPropertiesFromFeatures swPart.FeatureManager.GetFeatures(False), configOpts
EndIf
swModel.Extension.RemoveMaterialProperty configOpts, Empty
swModel.GraphicsRedraw2
Else
Err.Raise "Please open part or assembly document"EndIfEndSubSub RemoveMaterialPropertiesFromBodies(bodies AsVariant, removeFromFaces AsBoolean, configOpts As swInConfigurationOpts_e)
IfNot IsEmpty(bodies) ThenDim i AsIntegerFor i = 0 To UBound(bodies)
Dim swBody As SldWorks.Body2
Set swBody = bodies(i)
swBody.RemoveMaterialProperty configOpts, Empty
If removeFromFaces ThenDim vFaces AsVariant
vFaces = swBody.GetFaces()
RemoveMaterialPropertiesFromFaces vFaces, configOpts
EndIfNextEndIfEndSubSub RemoveMaterialPropertiesFromFaces(faces AsVariant, configOpts As swInConfigurationOpts_e)
Dim i AsIntegerIfNot IsEmpty(faces) ThenFor i = 0 To UBound(faces)
Dim swFace As SldWorks.Face2
Set swFace = faces(i)
swFace.RemoveMaterialProperty2 configOpts, Empty
NextEndIfEndSubSub RemoveMaterialPropertiesFromFeatures(features AsVariant, configOpts As swInConfigurationOpts_e)
Dim i AsIntegerIfNot IsEmpty(features) ThenFor i = 0 To UBound(features)
Dim swFeat As SldWorks.Feature
Set swFeat = features(i)
Debug.Print swFeat.Name
swFeat.RemoveMaterialProperty2 configOpts, Empty
NextEndIfEndSubFunction GetConfigurationOptions(allConfigs AsBoolean) As swInConfigurationOpts_e
If REMOVE_FROM_ALL_CONFIGS Then
GetConfigurationOptions = swInConfigurationOpts_e.swAllConfiguration
Else
GetConfigurationOptions = swInConfigurationOpts_e.swThisConfiguration
EndIfEndFunction
Notifications
Join session by SOLIDWORKS and PDM API expert Artem Taturevych at 3DEXPERIENCE World 2026 on Wednesday, Feb 4 at 08:30 AM CST to explore 10 essential macros for automating drawings, assemblies, custom properties, and more