Reply

get_Edges via InvokeMember...

[ Edited ]

I'm trying to build a general class for accessing Part Feature methods and properties. I've had success up to trying to implement the get_Edges method via InvokeMember...which fails with the following COMException...

 

Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

 

Below is my test code, it should be started with SolidEdge running and a part with at least one feature as the active document...

 

The whole project is attached.

 

Any help would be appreciated.

 

Thanks,

John

 

 

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 

namespace SEDemo

{

class Program

{

static void Main(string[] args)

{

SolidEdgeFramework.Application app = ConnectToCAD();

SolidEdgePart.PartDocument Part = ActivePartDoc(app);

SolidEdgePart.Model Model = Part.Models.Item(1);

object Feature = Model.Features.Item(1);

 

Object[] GetEdgesArgs = new Object[] { (object)SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll };

SolidEdgeGeometry.Edges Edges = (SolidEdgeGeometry.Edges)Feature.GetType().InvokeMember

("get_Edges",

System.Reflection.BindingFlags.InvokeMethod,

null,

Feature,

GetEdgesArgs);

 

}

 

 

static public SolidEdgeFramework.Application ConnectToCAD()

{

 

SolidEdgeFramework.Application app = null;

try

{

app =

(SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");

if (app != null) Console.WriteLine("Connected to Solid Edge");

}

catch //(Exception ex)

{

Console.WriteLine("Could not connect to Solid Edge");

 

}

return app;

}

 

static public SolidEdgePart.PartDocument ActivePartDoc(SolidEdgeFramework.Application app)

{

 

if ((app != null) && (app.ActiveDocumentType == SolidEdgeFramework.DocumentTypeConstants.igPartDocument))

{

return (SolidEdgePart.PartDocument)app.ActiveDocument;

}

return null;

 

}

}

}

 

 

Posted by: John Dixon
Post date: 6/8/2006 4:58:25 AM

2 REPLIES

RE: get_Edges via InvokeMember...

[ Edited ]

John,

 

I haven't tried coding it myself, but at first glance, this is what I see.

 

/* You need to change this line */

SolidEdgeGeometry.Edges Edges = (SolidEdgeGeometry.Edges)Feature.GetType().InvokeMember ("Edges", System.Reflection.BindingFlags.GetProperty, null, Feature, NULL); }

 

 

I suppose it's technically possible to call the "get" method of a property but you would have to exactly match the method name. It could be "get..." or "get_...". It's just easier in my opinion to use BindingFlags.GetProperty when possible.

 

Posted by: Jason Newell
Post date: 6/8/2006 5:38:14 AM

RE: get_Edges via InvokeMember...

[ Edited ]

Hi Jason,

 

Thanks for the quick response!

 

I could not find a definition for the "Edges" property, just the "get_Edges" method. This seems to be the case for all feature types.

 

Changing the code as you suggested yields the following error:

 

Exception has been thrown by the target of an invocation.

 

As opposed to the error my code returned:

Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))

 

Thanks,

John

 

 

 

 

 

Posted by: John Dixon
Post date: 6/8/2006 7:49:14 AM