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(); }
Solved! Go to Solution.