Matrix methods

The occurrence class has a method GetMatrix() which gives a matrix for converting from part coordinates to assembly coordinates and back.  But this yields a 16 array, and I see no methods for using this matrix.  Given there are different ways it could be encoded, I hope somewhere there are methods for multiplying these matrices together, and transforming points.  Anyone?


Re: Matrix methods



I am by no means a matrix expert but I do know there are plenty of 3rd party libraries for handling matrices. Solid Edge leaves it up to you to choose the library of your choice or roll your own. I've worked with math gurus in the past who totally got Solid Edge matrices and had no issue working with them. They knew what they were doing though and I don't...


I threw together a small demo of 2 free libraries that I'm familar with. OpenTK & SharpGL. Again, I don't for a second pretend that I know how to use them. Just sharing what I do know.


using SolidEdgeCommunity;
using SolidEdgeCommunity.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MatrixDemo
    class Program
        static void Main(string[] args)

            var application = SolidEdgeUtils.Connect();
            var assembly = application.GetActiveDocument<SolidEdgeAssembly.AssemblyDocument>();
            var occurrences = assembly.Occurrences;

            foreach (var occurrence in occurrences.OfType<SolidEdgeAssembly.Occurrence>())
                // Allocate array.
                Array matrix = Array.CreateInstance(typeof(double), 16);

                // Get the occurrence matrix.
                occurrence.GetMatrix(ref matrix);

                // Convert Array to double[] for ease of use.
                double[] m = matrix.OfType<double>().ToArray();

                // NuGet package id: OpenTK

                // NuGet package id: SharpGLCore


        static void DemoOpenTK(double[] m)
            var matrix4d = new OpenTK.Matrix4d(


            // Demo of multiplying matrices. *Static method*
            // OpenTK.Matrix4d.Mult(left, right);

        static void DemoSharpGL(double[] m)
            // Convert array to multidimensional array.
            double[,] ma = {
                                   { m[0], m[1], m[2], m[3] },
                                   { m[4], m[5], m[6], m[7] },
                                   { m[8], m[9], m[10], m[11] },
                                   { m[12], m[13], m[14], m[15] }

            var matrix = new SharpGL.SceneGraph.Matrix(ma);

            // Demo of multiplying matrices. *Static method*
            // SharpGL.SceneGraph.Matrix.Multiply(left, right);

If it were me, once I settled on a solution, I would simply write extension methods over the Solid Edge API to make working with the matrices easier. There are plenty of examples of how to write Solid Edge API extension methods on GitHub (SolidEdge.Community).

Jason Newell
Applications Architect

Re: Matrix methods

Pinging @AdityaG and @jay_carlton to see if their group can offer any guidance or sample code.

Jason Newell
Applications Architect

Re: Matrix methods

Since asking the question, I elected to download and wrap a public C# maths library.  I have no difficulty working with matrices, except that there are a lot of methods and I preferred to start with something rather than start with nothing.


About these extension methods, my impression is there's nothing magic about them and they are simply useful methods that use the SolidEdge API.

Re: Matrix methods

Solid Edge uses the computer graphics row major matrix ordering, as opposed to the math's textbook's column major. That means the 16 values are

 xx  xy  xz  0

 yx  yy  yz  0

 xz  zy  zz  0

 tx  ty  tz  1

consisting of a 3x3 rotation matrix and a translation vector.


Given a 3D vector (vx, vy, vz) in the 'local' coordinate system, or space as I like to call it, then the premultiplication

(vx vy vz 1) X [xx xy xz 0]

                      [yx yy yz 0]

                      [zx zy zz 0]

                      [tx ty tz 1]

produces the transformed vector. The applies the rotation followed by the translation.


The inverse transformation is formed by multiplying the reverse translation, a negation, followed by the reverse rotation, a transpose.

[ 1  0  0 0] X [xx yx zx 0]

[ 0  1  0 0]     [xy yy zy 0]

[ 0  0  1 0]     [xz yz zz 0]

[tx ty tz 1]     [  0   0   0 1]


The appropriate methods should be in the maths library.


There is a very brief summary on homogeneous math at the beginning of my article on codeproject at


Re: Matrix methods

"The appropriate methods should be in the maths library."


I grabbed a library and it has appropriate methods.  Did you have something in mind when you said "the maths library"?

Re: Matrix methods

No, I had nothing in mind.