Dear All --


I am writing a program to mate two parts using 2 reference planes. Hence, I am using relations3d.AddPlanar(plane1, plane2, false, ref arrDou1, ref arrDou2);

But I am getting error-ed out everytime i use this.


I read a couple of posts in this, and in one Jason has replied like:


Jara, Don't feel bad. COM Interop Array's are tough. To make things worse, .NET 2.0 is broken regarding this. This code will work in .NET 1.1. If you're using .NET 2.0, I'll have to do some more digging to show you how to do it. Array maxRangePoint = Array.CreateInstance(typeof(double), 0); Array minRangePoint = Array.CreateInstance(typeof(double), 0); bodyObj.GetRange(ref minRangePoint, ref maxRangePoint); } I am using .NET 2.0. In this case how I should declare the array of doubles.






Posted by: Kiran Thomas
Post date: 12/15/2010 11:38:09 PM


RE: AddPlanar

Hi thomforum,


unfortunately you didn't mention which .NET language you use (C#, VB, C++/CLI etc.).


Below an example how to define and initialize an array of double in VB that may be used as a reference parameter to Solid Edge API calls:


Dim myArray() As Double = New Double() {}


Posted by: Wolfgang Kunert
Post date: 12/16/2010 2:51:35 AM

RE: AddPlanar

Kunert --


Stupid of me not mentioning the language.


I use C#.





Posted by: Kiran Thomas
Post date: 12/16/2010 5:00:46 PM

RE: AddPlanar



The syntax in C# is either


double[] myArray = new double[] {};
or simply
double[] myArray = {};


Posted by: Wolfgang Kunert
Post date: 12/16/2010 9:11:33 PM

RE: AddPlanar

Kunert --


Thanks for the reply, I know normally your way of declaring will work, but not with COM interop's.


Okay, let me put it this way...

So far I have tried these ways..


System.Array arrDou = new double[] {}


dobule[] arrDou = new double[] {}


System.Array arrDou = Array.CreateInstance(TypeOf(double), 0);


System.Array arrDou = Array.CreateInstance(Type.GetType("System.Object"), 0);


All these leads to RUN TIME ERROR's. NO errors while compiling



Thats when I saw the below post.


Does anybody know how to declare the System.Array in this.






Posted by: Kiran Thomas
Post date: 12/16/2010 10:43:05 PM

RE: AddPlanar

Do you have for ease a code snippet which allows to reproduce your runtime error?



Posted by: Wolfgang Kunert
Post date: 12/16/2010 11:33:10 PM

RE: AddPlanar

See the code. Sorry couldnt upload as text, was showing errors 




using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;


using System.Reflection;

using System.Runtime.InteropServices;

using SolidEdgeConstants;


using System.Collections;


namespace CreateAssembly


    public partial class Form1 : Form


        SolidEdgeFramework.Application SEdgeApp = null;

        SolidEdgeFramework.Documents SEdgeDocs = null;

        SolidEdgeAssembly.AssemblyDocument SEdgeAssDoc = null;

        SolidEdgeAssembly.Occurrences SEdgeOccs = null;

        SolidEdgeAssembly.Occurrence SEdgeOcc1 = null;

        SolidEdgeAssembly.Occurrence SEdgeOcc2 = null;

        SolidEdgeFramework.Reference SEdgeRef1 = null;

        SolidEdgeFramework.Reference SEdgeRef2 = null;

        SolidEdgePart.PartDocument SEdgePart1 = null;

        SolidEdgePart.PartDocument SEdgePart2 = null;

        SolidEdgeAssembly.Relations3d relations3d = null;

        SolidEdgeAssembly.GroundRelation3d groundRelations3d = null;

        SolidEdgePart.RefPlanes refPlanes = null;

        SolidEdgePart.RefPlane refPlane1 = null;

        SolidEdgePart.RefPlane refPlane2 = null;

        SolidEdgeAssembly.PlanarRelation3d planarRel = null;


        string strPart1 = "";

        string strPart2 = "";



        public Form1()



            strPart1 = @"D:\Test1.par";

            strPart2 = @"D:\Test2.par";



        private void btnCreateAssembly_Click(object sender, EventArgs e)





                //Get the running instance of SolidEdge Session

                SEdgeApp = (SolidEdgeFramework.Application)



                SEdgeApp.Visible = true;

                SEdgeApp.DisplayAlerts = false;

                SEdgeApp.DisplayFullScreen = true;


                //Reference to documents

                SEdgeDocs = SEdgeApp.Documents;

                //Create a new assembly document

                SEdgeAssDoc = (SolidEdgeAssembly.AssemblyDocument)SEdgeDocs.Add("SolidEdge.AssemblyDocument", Missing.Value);

                //Reference to occurences collection

                SEdgeOccs = SEdgeAssDoc.Occurrences;

                //Add a part document to assembly

                SEdgeOcc1 = SEdgeOccs.AddByFilename(strPart1, Missing.Value);

                SEdgePart1 = (SolidEdgePart.PartDocument)SEdgeOcc1.OccurrenceDocument;


                //Add another part document to assembly

                SEdgeOcc2 = SEdgeOccs.AddByFilename(strPart2, Missing.Value);

                SEdgePart2 = (SolidEdgePart.PartDocument)SEdgeOcc2.OccurrenceDocument;


                //Get the relation between parts

                relations3d = SEdgeAssDoc.Relations3d;

                //Get the ground relation(By default the newly arrived part will be mated to ground)

                groundRelations3d = (SolidEdgeAssembly.GroundRelation3d)relations3d.Item(2);

                //Delete all those mates



                refPlanes = (SolidEdgePart.RefPlanes)SEdgePart1.RefPlanes;

                refPlane1 = refPlanes.Item(1);

                refPlanes = (SolidEdgePart.RefPlanes)SEdgePart2.RefPlanes;

                refPlane2 = refPlanes.Item(1);


                if (true)


                    //System.Array arrDou1 = new double[] { 0.0, 0.0, 0.0 };

                    //System.Array arrDou2 = new double[] { 0.0, 0.0, 0.0 };

                    Array arrDou1 = Array.CreateInstance(Type.GetType("System.Double"), 3);

                    Array arrDou2 = Array.CreateInstance(Type.GetType("System.Double"), 3);

                    bool status = false;

                    //Add planar relationship

                    planarRel = relations3d.AddPlanar(refPlane1, refPlane2, status, ref arrDou1, ref arrDou2);



                //Release all objects


                MessageBox.Show("Parts inserted");



            catch (Exception ex)






        private void ReleaseAll()




                if (SEdgeOcc1 != null)



                    SEdgeOcc1 = null;


                if (SEdgeOccs != null)



                    SEdgeOccs = null;


                if (SEdgeAssDoc != null)



                    SEdgeAssDoc = null;


                if (SEdgeDocs != null)



                    SEdgeDocs = null;


                if (SEdgeApp != null)



                    SEdgeApp = null;



            catch (Exception ex)













Posted by: Kiran Thomas
Post date: 12/19/2010 11:49:03 PM

RE: AddPlanar

Never mind ... got the answer.. Had to use GetRootPoint method before I use addPlanar method





Posted by: Kiran Thomas
Post date: 12/20/2010 1:34:04 AM

Re: AddPlanar

By the way, setting the]/sysarray option in the type library importer causes the need to do System.Array.CreateInstance(). This setting is necessary for marshalling the SAFEARRAYs properly, but requires some extra syntax in declaring and accessing the arrays. For instance, I believe in C#, the bracket operator doesn't work with System.Array, and you have to use CreateInstance to declare one.


Creating the System.Array (with /sysarray set on the relevant interop assembly) in C# works very similarly to the VB .NET example. The only difference is the function to call to get the type is [b]typeof[/b] instead of GetType.


// can use var in C# 4.0 since type on RHS is unambiguous
var myArray = Array.CreateInstance(typeof(double), 10);


There's more info at].NET Framework 4: Default Marshaling for Arrays.


Posted by: Jay Carlton
Post date: 6/26/2012 8:44:02 AM