Features

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

i am trying to get the items in the "Ordered" history list and be able to suppress/unsuppress them.

 

i have seen this bit of VB code :

'Get the Features Object for the Model
    Set objFeats = objModel.Features

what are these features? are they at all related to the items in the Synchronous or Ordered lists? how do you traverse the objFeats collection as i am not sure what object is contained in the collection. i can't find any feature type object.

 

 

4 REPLIES

Re: Features

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

I found a features collection for a part, 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?

 

Re: Features

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

i am coding in C++ so what would be right way to iterate the collection?

 

Re: Features

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

Iterating through the ordered feature tree is quite simple, as the DesignEdgeaarFeatures collection contains all features in their order of creation (like they appear in the PathFinder).

The following example iterates through all features and suppresses all Round features:

//----------------------------------------------------------------------
// PAR: Suppress all "Round" features
//----------------------------------------------------------------------
PartDocumentPtr pDoc = pSEApp->GetActiveDocument();
EdgebarFeaturesPtr pAllFeats = pDoc->GetDesignEdgebarFeatures();
for (int i=1; i<=pAllFeats->GetCount(); i++)
{
  IDispatchPtr pFeat = pAllFeats->Item(i);
  // Get the type of the feature
  FeatureTypeConstants featType;
  if (SUCCEEDED(ComGetProperty(pFeat, L"Type", VT_I4, (void*)&featType)))
  {
    if (featType == igRoundFeatureObject)
    {
      ComPutProperty(pFeat, L"Suppress", VARIANT_TRUE);
    }
  }
}

 To get the code running, you have to define the following two helper functions:

//=======================================================================
// Function  : ComGetProperty
//=======================================================================
HRESULT ComGetProperty(const LPDISPATCH pDisp, LPOLESTR szProperty, VARTYPE propType, void *property)
{
  if (pDisp == NULL)
  {
    return E_POINTER;
  }
  DISPID  rgDispId = 0;
  HRESULT hr = pDisp->GetIDsOfNames(IID_NULL, &szProperty, 1, LOCALE_USER_DEFAULT, &rgDispId);
  if (SUCCEEDED(hr))
  {
    hr = _com_dispatch_propget(pDisp, rgDispId, propType, property);
  }
  return hr;
}

//=======================================================================
// Function: ComPutProperty
//=======================================================================
HRESULT ComPutProperty(const LPDISPATCH pDisp, LPOLESTR szProperty, VARIANT_BOOL vBool)
{
  DISPID  rgDispId = 0;
  HRESULT hr = pDisp->GetIDsOfNames(IID_NULL, &szProperty, 1, LOCALE_USER_DEFAULT, &rgDispId);
  if (SUCCEEDED(hr))
  {
    hr = _com_dispatch_method(pDisp, rgDispId, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, L"\x000b", vBool);
  }
  return hr;
}

 PS: I forgot to say, that this code runs slow in a part with a lot of features, as each single suppress action causes a recompute of all subsequent features, so in practice you would probably GoTo only the features your are suppressing and at the end GoTo the last feature in the tree.

Re: Features

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

thank you so much for the clarification. my main difficulty with the programming part of SE is that i don't know what to look for. here was the solution i came up with that seems to work; i don't know if it is any better or worse being a Unix developer i am just hunting in the dark until something works:

 

pDoc is a  CComPtr<SolidEdgePart:Smiley TongueartDocument>
   
    CComQIPtr<SolidEdgePart::Models> pModels(pDoc->GetModels());
    int i,nummodels = pModels->GetCount();
    int j,numfeats;
    if(!nummodels) return 0;

    CComQIPtr<SolidEdgePart::Features> pFeats;
    CComPtr<SolidEdgePart::Model> tmpD;
    CComPtr<SolidEdgePart::ExtrudedProtrusion> eFeat;
    CComPtr<SolidEdgePart::RevolvedProtrusion> rFeat;
    CComPtr<SolidEdgePart:Smiley FrustratedweptProtrusion> wFeat;
    CComPtr<SolidEdgePart::Chamfer> cFeat;
    CComPtr<SolidEdgePart::Round> roFeat;
    CComPtr<SolidEdgePart::Hole> hFeat;

    CComPtr<IDispatch> tt;

    for(i=0;i<nummodels;i++) {
        tmpD = pModels->Item(i+1);

        if(!tmpD)
            continue;

        pFeats = tmpD->GetFeatures();

        numfeats = pFeats->GetCount();

        for(j=0;j<numfeats;j++) {
            tt = pFeats->Item(j+1);

            tt->QueryInterface(&eFeat);
            tt->QueryInterface(&rFeat);
            tt->QueryInterface(&wFeat);
            tt->QueryInterface(&cFeat);
            tt->QueryInterface(&roFeat);
            tt->QueryInterface(&hFeat);

            tt.Release();

 

then i can suppress whatever of these features i want. for example to suppress rounds:

 

if(roFeat)

     roFeat->Suppress = 1;