Reply

Iterating part features

[ Edited ]

 

Hello,

I'm new to SE, I am searching for a way to iterate all the features in part: datums , sketches and features belongs to models. I would like to iterate the features in time-stamp(creation) order, or in a parent- child order(first parent than child). I've searched in this forum and couldn't find example for it.

I have experience in writing code for the other CAD Siemens has (NX) I'll appreciate if you can map me equal terms between SE and NX, e.g. I believe body in NX is model in SE.

I found a features collection for a model, but I did not found a base class/ interface that I can use to iterate the collection and to extract information like feature type (extrude, chamfer draft etc...) , is there a common interface for it?

Thank you

Tomer

 

 

 

Posted by: Tomer Laor
Post date: 5/21/2011 5:43:42 AM

3 REPLIES

RE: Iterating part features

[ Edited ]

Ok, answering to myself, hope this will help others:

Regarding common interface/base class for features. here is a C# code that uses reflection to get the type of a feature in a modelwith alittle bit formatting the return string from FeatureTypeConstants)

foreach (Model m in part.Models)

{

m_partTypes[Features] += m.Features.Count;

foreach (Object o in m.Features)

{

string displayType;

try

{

object featureType = o.GetType().InvokeMember("Type", BindingFlags.GetProperty, null, o, null);

FeatureTypeConstants ftype = (FeatureTypeConstants)featureType;

displayType = ftype.ToString().Substring(2);

if (displayType.EndsWith(FEATUREOBJECT))

displayType = displayType.Substring(0, displayType.Length - FEATUREOBJECT.Length);

 

}

catch (System.Exception ex)

{

Console.WriteLine("couldn't get feature type : " + ex.Message);

displayType = "UnknownFeatType";

}

}

}

 

Posted by: Tomer Laor
Post date: 5/23/2011 3:37:04 AM

Re: RE: Iterating part features

hello,

 

would you know how to translate this into C++?

 

Re: RE: Iterating part features

This is not exactly what you asked for but it's close enough to give you an idea how it "Invoke" a property on an object. If you still can't figure out how to make it work let me know and I'll modify the code to do what you what.

 

Snippet is from C:\Program Files\Solid Edge ST6\SDK\Advanced\samples\Addins\VC\util.cpp. 

 

// This routine returns the document type given the dispatch of a Solid Edge document.
// Returns E_INVALIDARG if pDocDispatch is NULL. Otherwise, returns the result from the Invoke
// method on that dispatch.
HRESULT GetDocType( LPDISPATCH pDocDispatch, DocumentTypeConstants& nDocType )
{
	HRESULT hr = NOERROR;

	nDocType = igUnknownDocument;

	try
	{
		if( NULL != pDocDispatch )
		{
			DISPID rgDispId = 0;

			OLECHAR *Names[1] = {L"Type"};

			hr = pDocDispatch->GetIDsOfNames( IID_NULL,
				Names,
				1,
				LOCALE_USER_DEFAULT,
				&rgDispId );

			if( SUCCEEDED(hr) )
			{
				VARIANT varResult;
				VariantInit(&varResult);
				V_VT(&varResult) = VT_I4;

				DISPPARAMS disp = { NULL, NULL, 0, 0 };

				// Get the document type property.
				hr = pDocDispatch->Invoke( rgDispId,
					IID_NULL,
					LOCALE_USER_DEFAULT,
					DISPATCH_PROPERTYGET,
					&disp,
					&varResult,
					NULL,
					NULL );
				if( SUCCEEDED(hr) )
				{
					nDocType = (DocumentTypeConstants)(V_I4(&varResult));
				}
				else
				{
					_com_issue_errorex(hr, pDocDispatch, __uuidof(pDocDispatch));
				}
			}

		}
		else
		{
			hr = E_INVALIDARG;
		}
	}
	catch(_com_error &e)
	{
		hr = e.Error();
	}

	return hr;
}

 

Jason Newell
Applications Architect
www.jasonnewell.net