Patrick Jensen

Macro for Component Appearance Showing Up Black

Discussion created by Patrick Jensen on Jan 20, 2021

I am running the exact code posted here: 

2019 SOLIDWORKS API Help - Change Color of Component in Specific Display State Example (VBA) 

This changes the color of a part at the assembly level. However, when I run this, the component color shows up black regardless of the color I change it to. After the macro runs, if I edit the component appearance manually, don't change anything, and press apply...then the correct color appears.


Here is proof of the color it should be:

But here is how it appears in the graphics window:

Note that I am using the usb case part rather than the usb cover part from the tutorial. Otherwise, the code is the exact same. Once I apply a part appearance manually the part is able to change colors as normal using the macro. I have tried both "rebuild" and "redraw" and neither work. I have also tried to record a macro of me editing the part appearance manually and pressing apply but the code for this does not appear in the recorded macro.


I am curious if this happens with other users as well. If not, maybe it is related to a system or document setting. The way I intend to use this macro would involve thousands of parts so I cannot manually edit each one. I am looking for a way to have the color application work the first time.