get_FacesByRay

Hello all,

 

I have troubles with get_FacesByRay method.

 

I tried:

SolidEdgeGeometry.Faces intersectFaces = (SolidEdgeGeometry.Faces) bodyObj.get_FacesByRay(0,0,0, 0,0,1);

 

but it finished with error that change type to SolidEdgeGeometry.Faces is not allowed.

 

I changed it to

 

System.Object intersectFaces = (System.Object) bodyObj.get_FacesByRay(0,0,0, 0,0,1);

 

and it works but how can I change type to SolidEdgeGeometry.Faces to be able to read results? (I tried it as next step but without success)

 

In VB every object can be declared as

 

Dim intersectFaces as Object

 

and than it works as SolidEdgeGeometry.Faces without changing of type. Is something like that possible also in C#?

 

Best regards,

 

Jara

 

Posted by: Jara Ctverak
Post date: 5/24/2007 9:01:05 PM

7 REPLIES

RE: get_FacesByRay

Jara,

 

the following should work in C#:

 

System.Object pColl = pBody.get_FacesByRay(x,y,z, nx,ny,nz);

System.Type objType = pColl.GetType();

int n = (int) objType.InvokeMember("Count", System.Reflection.BindingFlags.GetProperty,

null, pColl, null);

if (n > 0)

{

MessageBox.Show("Intersection found");

}

else

{

MessageBox.Show("NO intersection found");

}

 

HTH,

Martin

 

Posted by: Martin Bernhard
Post date: 5/25/2007 3:48:24 AM

RE: get_FacesByRay

Here is the answer that I got from an SE developer.

 

 

I believe it will be an IDMFace interface. Look for the gtfordm.h include file that goes along with the ole4dm.h include file defined by the OLE4DM working group years ago.

 

When you are working with ole4dm, you are not working with SolidEdgeGeometry you are working with “OLE4DM” industry “standard” geometry. I believe OLE4DM is basically defunct as the working group disbanded and there is no new development going on that I am aware of. Using OLE4DM as opposed to SolidEdgeGeometry allows one to write common code that is reusable with any system that supports OLE4DM.

 

So for instance if you want to insert a Solid Edge part into an OLE4DM container and a Solid Works part into the same container, it can be done and both products support the common interfaces as defined by the OLE4DM working group. Of course by its very nature that means there is less you can do with OLE4DM than each vendor’s specify geometry interfaces (SolidEdgeGeometry).

 

 

If this is true, the last post will not work. Looking around in the GTforDM.h, I found an interface, IEnumDMFaces, that looks promising but since it's not defined in any Solid Edge Type Library, you'll have to hand define it in C#. I've done it before but I do not have time at the moment to try it.

 

 

MIDL_INTERFACE("0002D225-0000-0000-C000-000000000046")

IEnumDMFaces : public IUnknown

{

public:

virtual /* [local] */ HRESULT STDMETHODCALLTYPE Next(

/* [in] */ ULONG cFaces,

/* [out] */ LPDMFACE *pFace,

/* [out] */ ULONG *pcFetched) = 0;

 

virtual HRESULT STDMETHODCALLTYPE Skip(

/* [in] */ ULONG cFaces) = 0;

 

virtual HRESULT STDMETHODCALLTYPE Reset( void) = 0;

 

virtual HRESULT STDMETHODCALLTYPE Clone(

/* [out] */ LPENUM_DMFACES *pEnumFaces) = 0;

 

};

 

 

Posted by: Jason Newell
Post date: 5/25/2007 3:52:54 AM

RE: get_FacesByRay

Jason,

 

in a little test in C++, I can always get a valid IDispatch interface from the GetFacesByRay method. By checking the type of this IDispatch pointer using ITypeInfo, I can see that either an empty Faces collection is returned, when there is no face found, or a generic _Collection with a number of valid Face objects inside.

So, I am able to ask for the Count property of this IDispatch pointer. That's the way, I was using this method before (in C++) and it worked.

 

Martin

 

Posted by: Martin Bernhard
Post date: 5/25/2007 4:55:37 AM

RE: get_FacesByRay

Here is some code that I got to work. I don't know how to make get_FacesByRay() work so I used get_Faces() instead.

 

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 

namespace SEFaces

{

class Program

{

static void Main(string[] args)

{

SolidEdgeFramework.Application application = null;

SolidEdgePart.PartDocument partDoc = null;

SolidEdgePart.Model model = null;

SolidEdgeGeometry.Body body = null;

SolidEdgeGeometry.Faces faces = null;

SolidEdgeGeometry.Face face = null;

 

try

{

application = Marshal.GetActiveObject("SolidEdge.Application") as SolidEdgeFramework.Application;

partDoc = application.ActiveDocument as SolidEdgePart.PartDocument;

model = partDoc.Models.Item(1);

body = model.Body as SolidEdgeGeometry.Body;

faces = body.get_Faces(SolidEdgeGeometry.FeatureTopologyQueryTypeConstants.igQueryAll) as SolidEdgeGeometry.Faces;

// I'm not sure how to use get_FacesByRay but the case to SolidEdgeGeometry.Faces interface succeeds.

//faces = body.get_FacesByRay(-100, -100, -100, 100, 100, 100) as SolidEdgeGeometry.Faces;

 

for (int i = 0; i

{

face = faces.Item(i) as SolidEdgeGeometry.Face;

}

}

catch (System.Exception e)

{

Console.WriteLine(e.Message);

}

 

if (face != null) Marshal.ReleaseComObject(face); face = null;

if (faces != null) Marshal.ReleaseComObject(faces); faces = null;

if (body != null) Marshal.ReleaseComObject(body); body = null;

if (model != null) Marshal.ReleaseComObject(model); model = null;

if (partDoc != null) Marshal.ReleaseComObject(partDoc); partDoc = null;

if (application != null) Marshal.ReleaseComObject(application); application = null;

}

}

}

 

 

 

Posted by: Jason Newell
Post date: 5/25/2007 5:30:29 AM

RE: get_FacesByRay

Thank's very much to all of you.

 

I tried Martin's approach and it works!

 

So thank you again!

 

Best regards,

 

Jara

 

Posted by: Jara Ctverak
Post date: 5/27/2007 9:04:02 PM

RE: get_FacesByRay

Posted By Jara Ctverak on 05/28/2007 2:04 AM

Thank's very much to all of you.

 

I tried Martin's approach and it works!

 

So thank you again!

 

Best regards,

 

Jara

 

Hi, my dear, would you give me a sample in C#? Thanks!

 

Posted by: assassin 007
Post date: 7/12/2010 9:37:55 PM

RE: get_FacesByRay

Posted By assassin on 07/13/2010 2:37 AM

Posted By Jara Ctverak on 05/28/2007 2:04 AM

Thank's very much to all of you.

 

I tried Martin's approach and it works!

 

So thank you again!

 

Best regards,

 

Jara

 

Hi, my dear, would you give me a sample in C#? Thanks!

 

Yeah!

I solved it!

Object Faces;

SolidEdgeGeometry.Face TopFace = null;

Faces = SEPartBody.get_FacesByRay(0.01, 0.01, 0.01, 0, 0, 1);

 

                Type type = Faces.GetType();

 

                int t=(int)type.InvokeMember("Count", System.Reflection.BindingFlags.GetProperty,null, Faces, null);

 

                TopFace=(SolidEdgeGeometry.Face) type.InvokeMember("Item",System.Reflection.BindingFlags.InvokeMethod,null,Faces,new object[]{1});

 

Posted by: assassin 007
Post date: 7/12/2010 11:24:42 PM