AnsweredAssumed Answered

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

Question asked by andreaspaulsen on Oct 7, 2013
Latest reply on Oct 7, 2013 by Neil
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