Select to view content in your preferred language

Problem with reading Feature Selection in ArcScene using ArcObjects C++

698
1
Jump to solution
10-07-2013 08:29 AM
Andreas_W_Paulsen
Occasional Contributor
I am experiencing some strange behaviour in my C++ code in ArcScene 10.1.
I have selected one Feature of type Simple Polygon.
The Feature has one field called "Name" of type text. I am trying to read the value of this field but just get an empty variant.
Also if I ask the feature about its object id; it returns -1, although the feature class has an OBJECTID field.
However if I start editing on the feature class with the 3D Editor, do nothing and save my code works!?
Just activating the 3D Editor from Customize->Toolbars do not work.
What is happening here?

Here is my code:
STDMETHODIMP CselectCubeCmd::OnClick() {   std::wstring fileName = L"";   CComBSTR fieldName(L"Name");   IDocumentPtr doc;   m_ipApp->get_Document( &doc );   ISxDocumentPtr sxdoc;   sxdoc = doc;   IScenePtr scene;   sxdoc->get_Scene( &scene );   esriCarto::ISelectionPtr selection;   scene->get_FeatureSelection( &selection );   IEnumFeaturePtr features = selection;   features->Reset();   IFeaturePtr feature;   for(;;) {     features->Next( &feature );     if(feature == NULL)       break;     long OID;     feature->get_OID(&OID); // usually = -1 :-(     IGeometryPtr shape;     feature->get_Shape( &shape );     if( shape == NULL )        continue;     esriGeometryType ftype;     shape->get_GeometryType(&ftype);      if(ftype == esriGeometryPolygon || ftype == esriGeometryPolyline)  {       IFieldsPtr fields;     feature->get_Fields( &fields );     long Index;     HRESULT res = fields->FindField( fieldName, &Index );     if( res == S_OK && Index > 0 ) {       IFieldPtr field;       fields->get_Field(Index, &field);       if(field != NULL) {         esriFieldType type;  field->get_Type(&type);           if(type == esriFieldTypeString ) {      VARIANT var;      HRESULT hr = feature->get_Value(Index, &var);      if(var.vt == VT_EMPTY) {        int stop = 1; // comes here usually :-(      }      else {        CComBSTR target_name(var.bstrVal); // name found :-)        turn_on_brick_layer(target_name); // do something       }    }         }       }     }   }   return updateTOC(); }


Thanks in advance for any answers!
Andreas W. Paulsen
0 Kudos
1 Solution

Accepted Solutions
NeilClemmons
Honored Contributor
You need to QI to IEnumFeatureSetup and set AllFields to true.  By default, only the geometry is set for the feature selection.  This is explained in the help topic for IMap.FeatureSelection, but doesn't appear to be repeated in the topic for IScene.FeatureSelection.

View solution in original post

0 Kudos
1 Reply
NeilClemmons
Honored Contributor
You need to QI to IEnumFeatureSetup and set AllFields to true.  By default, only the geometry is set for the feature selection.  This is explained in the help topic for IMap.FeatureSelection, but doesn't appear to be repeated in the topic for IScene.FeatureSelection.
0 Kudos