Hi all,
I am trying to use an alternative method to multiply a transform. To do this, I am using System.Windows.Media.Media3D. But when I try to use it, I get a different result from when I use the SolidWorks API MultiplyTransform. I have attached my part and code (below). I think I am wrongly creating the Matrix3D, but I have tried different ways and none would give the same result as SolidWorks.
Transform.SLDPRT (45.6 KB)
public void MultiplyTransform0()
{
var progId = "SldWorks.Application";
var progType = Type.GetTypeFromProgID(progId);
ISldWorks app = Activator.CreateInstance(progType) as SolidWorks.Interop.sldworks.ISldWorks;
app.Visible = true;
ModelDoc2 model = app.OpenDocSilent(@"<YOUR PATH>\Transform.SLDPRT", 1, 0);
Sketch sketch = model.GetActiveSketch2();
MathUtility mathUtility = app.IGetMathUtility();
MathTransform mathTransform = sketch.ModelToSketchTransform;
mathTransform = mathTransform.Inverse();
double[] transform = mathTransform.ArrayData;
SketchPoint sketchPoint = sketch.GetSketchPoints2()[0];
double[] point = new double[] { sketchPoint.X, sketchPoint.Y, sketchPoint.Z };
MathPoint mathPoint = mathUtility.CreatePoint(point);
mathPoint = mathPoint.MultiplyTransform(mathTransform);
double[] resultValue = mathPoint.ArrayData;
Vector3D vector1 = new Vector3D(point[0], point[1], point[2]);
Matrix3D matrix1 = new Matrix3D(
transform[0], transform[1], transform[2], transform[13],
transform[3], transform[4], transform[5], transform[14],
transform[6], transform[7], transform[8], transform[15],
transform[9], transform[10], transform[11], transform[12]
);
Vector3D vectorResult = new Vector3D();
vectorResult = Vector3D.Multiply(vector1, matrix1);
}
Thanks in advance for helping me out!
JJ