Hi,
I tried to get/set (change) the color of a body from a STEP-File imported.
The code is as follows:
var importFileData = _solidWorks.GetImportFileData("part.stp");
int errors = 0;
_solidWorks.LoadFile4("part.stp", "", importFileData, ref errors);
IPartDoc part = _solidWorks.ActiveDoc as IPartDoc;
IModelDoc2 model = _solidWorks.ActiveDoc as IModelDoc2;
var bodiesAsObject = (object[])part.GetBodies2((int)swBodyType_e.swAllBodies, false);
SelectionMgr swSelMgr = (SelectionMgr)model.SelectionManager;
SelectData swSelData = (SelectData)swSelMgr.CreateSelectData();
var bodies = bodiesAsObject.Cast
foreach (IBody2 body in bodies) {
if(null != body.MaterialPropertyValues2) {
var material = body.MaterialPropertyValues2 as double[];
body.Select2(false, swSelData);
material[0] = 1;
material[1] = 0;
material[2] = 0;
body.MaterialPropertyValues2 = material;
model.ForceRebuild3(false);
}
}
The result is as follows:
As you can see, “Body” gets the new color assigned.
But I need to set the color of “Importiert1” – how can I achieve this?
Please find the STEP-File attached.
Thanks,
Alex