How to get Part features names in C++



I need to get the features of a Part model in c++.

I can get Features as a collection of IDispatch.

Than, how to "cast" to various features?

In visual basic its easy Object, but how to do the same in C++


Thanks in advance for any help.

Best Regards



C++ test

    SolidEdgePart:Smiley TongueartDocumentPtr objDoc ;

    SolidEdgePart::ModelPtr objModel ;


    objDoc = objApp->Documents->Open("e:\\solidedge\\b.par") ;

    objModel = objDoc->Models->Item(1) ;


    SolidEdgePart::FeaturesPtr objFeatures ;

    objFeatures = objModel->Features ;


    long i ;

    IDispatch *f ;


    for (i=1;iCount;i++)


        f = objFeatures->Item(i) ;




VB Example that works


Private Sub Form_Load()

    Dim objApp As SolidEdgeFramework.Application

    Dim objDoc As SolidEdgePart.PartDocument

    Dim objModel As SolidEdgePart.Model

    Dim objFeats As SolidEdgePart.Features

    Const TESTFILE = "e:\solidedge\b.par"

    ' Report errors

    Const PI = 3.14159265358979

    ' Create/get the application with specific settings

    On Error Resume Next

    Set objApp = GetObject(, "SolidEdge.Application")

    If Err Then


        Set objApp = CreateObject("SolidEdge.Application")

        Set objDoc = objApp.Documents.Add("SolidEdge.PartDocument")

        objApp.Visible = True


        Set objDoc = objApp.ActiveDocument

    End If

    ' Close the part document

    Call objDoc.Close

    ' Open a Testcase

    Set objDoc = objApp.Documents.Open(FileName:=TESTFILE)

    ' Get the model object in the test case

    Set objModel = objDoc.Models(1)

    'Get the Features Object for the Model

    Set objFeats = objModel.Features

    Dim f As Object

    For i = 1 To objFeats.Count

        Set f = objFeats(i)

        Debug.Print i

        Debug.Print f.Name

        Debug.Print f.DisplayName

        Debug.Print f.EdgebarName

        Debug.Print f.SystemName

        Debug.Print f.Type ''Tipo di feature

        Debug.Print f.Suppress




    ' Release objects

    Set objApp = Nothing

    Set objDoc = Nothing

    Set objModel = Nothing

    Set objFeats = Nothing

End Sub


Posted by: Massimo Magris
Post date: 2/10/2009 5:24:21 AM


RE: How to get Part features names in C++



I don't have time right this second to give you a complete solution but here is what I've thrown together to give you an idea on how to do it.

  HRESULT hr = S_OK; IDispatch *pFeature; for (i=1;iCount;i++) { pFeature = objFeatures->Item(i) ; try { if( NULL != pFeature ) { DISPID rgDispId = 0; OLECHAR *szNames[] = {L"Name"}; hr = pFeature->GetIDsOfNames( IID_NULL, szNames, 1, LOCALE_USER_DEFAULT, &rgDispId ); if( SUCCEEDED(hr) ) { VARIANT varResult; VariantInit(&varResult); V_VT(&varResult) = VT_I4; DISPPARAMS disp = { NULL, NULL, 0, 0 }; hr = pFeature->Invoke( rgDispId, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &disp, &varResult, NULL, NULL ); if( SUCCEEDED(hr) ) { //varResult will contain the data } else { _com_issue_errorex(hr, pFeature, __uuidof(pFeature)); } } } else { hr = E_INVALIDARG; } } catch(_com_error &e) { hr = e.Error(); } }


Posted by: Jason Newell
Post date: 2/11/2009 6:59:22 AM

RE: How to get Part features names in C++



thank you, its really a great help and starting point!!!




Posted by: Massimo Magris
Post date: 2/11/2009 10:54:59 AM

RE: How to get Part features names in C++

No doubt that late binding with COM objects in C++ sucks...


Posted by: Jason Newell
Post date: 2/11/2009 10:58:53 AM