I am playing around with the API to change color of components and set them back to their original values. To do this, I create an assemblydoc member, get its component list and traverse the assembly tree. I get the part name, part ID and color values and store them in a separate data structure. I proceed to change the color of these parts with a custom color (something that I set) and post-process the model information. Finally, I use the part name to change the individual part colors back to the original values.
I was considering using the part ID that SW has to uniquely identify duplicate parts so that I can correctly assign the original colors. However, it looks like SW assigns the same ID value to different parts. For ex., two instances of the same cylinder (part) when present in different sub-assemblies have the same ID. Even worse, a box present in an entirely different sub-assembly has the same part ID as the cylinder!!
Some code to illustrate how I'm doing this (using C++/CLI)-
ISldWorks^ swApp = gcnew SldWorksClass;
IModelDoc2^ swModel = swApp->IActiveDoc2;
swAssembly = (IAssemblyDoc^)swModel;
arr = (array<Object^>^)swAssembly->GetComponents(false);
for (int i = 0; i < arr->GetLength(0); i++)
swChildComp = (Component2^)arr[i];
String^ loopPartIDnet = swChildComp->GetID().ToString(); // get part id here
So, the question is: is there a unique partID code that SW assigns to its components that I can use?