AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add FeatureReader to acSelection

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
828 Views, 2 Replies

Add FeatureReader to acSelection

Hi there, 

 

I'm trying to add all fdo layer features to MgSelectionBase so I can turn on/off map layer features depending on the selection query.

 

here is what I have: 

 

AcMapLayer maplayer = AcMapFeatureEntityService.GetLayer(objId); //objId is from prompt selection

MgFeatureQueryOptions queryOpts = new MgFeatureQueryOptions(); 
queryOpts.SetFilter("PRIMARYINDEX > 0"); //select everything on the layer

MgResourceIdentifier fsId = new MgResourceIdentifier(maplayer.GetFeatureSourceId());
MgFeatureService fs = AcMapServiceFactory.GetService(MgServiceType.FeatureService) as MgFeatureService; 

MgFeatureReader featureReader = fs.SelectFeatures(fsId, maplayer.FeatureClassName, queryOpts);

AcMapSelection selBaseAll = new AcMapSelection(AcMapMap.GetCurrentMap());

//populate selection with all features
selBaseAll.AddFeatures(maplayer, featureReader, 0);

//hide all features
maplayer.SetFeatureVisibility(selBaseAll, false);
.
.
//turn on features that is passed as parameter to fn.

 

 

This works if the layer source is SDF file, but if the layer source is sql spatial, i get an error "An exceotion occured in FDO component. Property "GwsId" not defined for class "Classname"".  this is on line: selBase.AddFeatures(..);

That field "GwsId" doesn't exists in database, if you open it in sql studio.. what am I doing wrong?

 

Thank you, 

-dm

 

2 REPLIES 2
Message 2 of 3
Daniel.Du
in reply to: Anonymous

When Map 3D connects to FDO data stores like Oracle/Sql Server and add layers to map, it will cache the data and use "GwsId" as identity key. Following code snippet works fine for Sql Server Spatial data store : 

 

        [CommandMethod("SetVisible")]

        public void SetVisible()

        {

            SetFeatureVisibility(true);

        }

 

        [CommandMethod("setInvisible")]

        public void SetInvisible()

        {

            SetFeatureVisibility(false);

        }

 

 

        public void SetFeatureVisibility( bool visible )

        {

            AcMapMap map = AcMapMap.GetCurrentMap();

            MgLayerCollection layers = map.GetLayers();

            MgLayerBase layer = layers.GetItem("FeatureClass1");

            AcMapLayer mapLayer = layer as AcMapLayer;

 

            MgFeatureQueryOptions opts = new MgFeatureQueryOptions();

            opts.SetFilter("ID > 0");

            MgResourceIdentifier featureId = new MgResourceIdentifier(mapLayer.GetFeatureSourceId());

            MgFeatureReader reader = mapLayer.SelectFeatures(opts);

            AcMapSelection selection = new AcMapSelection(map);

            selection.AddFeatures(mapLayer, reader, 0);

            reader.Close();

 

            mapLayer.SetFeatureVisibility(selection, visible);

        }



Daniel Du
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
dr5156
in reply to: Anonymous

Hi

 

I have a question.

 

i would like to turn OFF/ON some set of FDO layers(Enterprises(Topobase Layers)).

 

The code is not working for me. Please help me

 

AcMapMap acMap = AcMapMap.GetCurrentMap();

 

MgLayerCollectionlayers = acMap.GetLayers();

 

if (layers != null&& layers.Count > 0)

{

foreach (MgLayerBase layer inlayers)

{

if(layer.GetVisible())

{

layer.SetVisible(

false);

 

//layer.Visible = false;//layer.ForceRefresh();

}

//if (layer.GetDisplayInLegend())//{// layer.DisplayInLegend = false;// layer.SetDisplayInLegend(false);// layer.ForceRefresh();//}

}

}

//AcMapMap.ForceScreenRefresh();

 

 

Regards,
Dayalan

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost