Hello,
I am using the .NET and the ComApi Interop stuff for development of an application that uses the View Control.
I want to get the matrix out of a InwLTransform3f so I can modify it and put it back using the state.OverrideTransform(..) function.
The InwLTransform3f.Matrix property returns an object that boxes the array of doubles in the matrix. So far so good, the values are in the object and all looks fine.
The problem is that when I try to unbox the doubles out of the object I get a very nasty InvalidCastException. I have tried various things to cast such as...
double[] matrix = new double[16];
transf = frag.GetLocalToWorldMatrix();
object mob = transf.Matrix;
matrix[0] = ((double[])(mob))[1];
or
matrix = (double[])mob;
both of these methods throw an exception and will not cast. Very frustrating...
I have the same issue with the InwLTransform3f2.GetLinear() function.
I would appreciate any advice that anyone can give on how to do this correctly.
Many thanks
Ken
Solved! Go to Solution.
Solved by kennethmjones. Go to Solution.
Hello again,
Just incase anyone is interested I managed to figure the answer to this one myself. I thought I would share it with the forum.
I figured out how to get the matrix data out of the object that is returned by the InwLTransform3f.Matrix interface.
It can be done using the C# Array.Copy function like this.
Array.Copy((Array)mTobj, matrix, 16);
Where mTbj is the object returned by InwLTransform3f.Matrix and matrix is an array of 16 doubles. This copies and unboxes the data in the object and you can use them modify them and apply them to the model again as you like.
I don't know why the object returned by InwLTransform3f.Matrix will not unbox with a simple cast but this is one solution I found.
It turns out that I did not actualy need to go this far for what I wanted to do with the transformation but it was a good learning exersize for me anyway.
By the way, the ComApi.InwLTransform3f2
I hope someone finds this useful.
Ken
I am very new for 3D cad automation. I am trying to get the matrix object through InwLTransform3f interface, but its always giving default value(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, ,0, 0, 0, 0, 1).
could you please tell me how to get the matrix object because i am working for scale the object.
My functionality is First i select the object then i get the matrix.
I updated the matrix value for scale and set the matrix.
The object is getting scale but it also the object was move from one place to another.
I want to scale the object in same area.
Please help me.
Thanks.