Reply
Solved! Go to solution

Occurrence.GetMatrix not working

[ Edited ]

I made an assembly with 2 parts, and used Occurrence Properties interactively to move the parts about.  In my program, I'm calling GetMatrix on the part occurrence and am getting a 0 matrix. (Not even an identity.)  What's wrong?

 

      foreach (Occurrence x in doc.Occurrences)
      {
        var d = x.OccurrenceDocument;
        double[] docmat = new double[16];//       Array.CreateInstance(typeof(double), 16);
        x.GetMatrix(docmat);
      }
2 REPLIES

Re: Occurrence.GetMatrix not working

I'll take a look at this tonight when I get home and let you know what I find.

Jason Newell
Applications Architect
www.jasonnewell.net
Solution
Solution
Accepted by topic author AlanBaljeu
‎08-26-2015 04:32 AM

Re: Occurrence.GetMatrix not working

[ Edited ]

Here is some sample code that should explain everything. I also demonstrated how to leverage extension methods to make the matrix conversion from Array -> double[] cleaner. Let me know if you have any questions.

 

using SolidEdgeCommunity;
using SolidEdgeCommunity.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSJunk
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var application = SolidEdgeUtils.Connect();
            var assemblyDocument = application.GetActiveDocument<SolidEdgeAssembly.AssemblyDocument>();
            var occurrences = assemblyDocument.Occurrences;
            var occurrence = occurrences.Item(2);

            // Demonstrate getting matrix of type Array.
            var matrixArray = Array.CreateInstance(typeof(double), 0);
            occurrence.GetMatrix(ref matrixArray);

            // Demonstrate converting matrix of type Array to double[].
            var matrix = matrixArray.OfType<double>().ToArray();

            // Demonstrate using extension method to get matrix of type double[].
            matrix = occurrence.GetMatrix();
        }
    }

    public static class OccurrenceExtensions
    {
        public static double[] GetMatrix(this SolidEdgeAssembly.Occurrence occurrence)
        {
            Array matrix = Array.CreateInstance(typeof(double), 0);
            occurrence.GetMatrix(ref matrix);
            return matrix.OfType<double>().ToArray();
        }
    }
}
Jason Newell
Applications Architect
www.jasonnewell.net