I have a method for setting and getting the materials on a body.
public double[] Materials
{
get
{
var castArray = _Body.MaterialPropertyValues2.CastArray
if(castArray == null || castArray.Length == 0)
return InitMat();
else
{
return castArray;
}
}
set
{
var materialPropertyValues2 = value ?? InitMat();
_Body.MaterialPropertyValues2 = materialPropertyValues2;
Debug.Assert(_Body.MaterialPropertyValues2!=null);
}
}
Note the assert that the materials should not be null after set. For some objects it always is null. For example a body I create like
public Body2 CreateTool(double radius, double length, double x,double y,double z, double c)
{
var modeler = (IModeler)SwApp.GetModeler();
var facePos = new double[] {x, y, z};
var direction = new double[] {1, 0, 0};
var array = facePos.Concat(direction).Concat(new[] {radius, length}).ToArray();
var body = (Body2)modeler.CreateBodyFromCyl(array);
var transform = (MathTransform) MathUtility.CreateTransformRotateAxis(Mp(0, 0, 0), ZAxis, c);
body.ApplyTransform(transform);
return body;
}
will not allow me to set it's material. This may be the source of the problem from my previous question about tessellation not working. If there is no material then maybe no tessellation will occur.
SolidworksApi macros