Accessing current workspace using an ArcObjects add-in for ArcMap

7797
6
07-31-2011 12:02 PM
PaulLivingstone
New Contributor III
I am trying to create a point feature in ArcObjects for an ArcMap add-in in c#. To do this I need to get the feature class. To get the feature class I need to know the current workspace.

How do I find the current workspace opened from ArcMap from within the dockable window c# code?

Any help would be appreciated.

Thanks
Paul
0 Kudos
6 Replies
RichardWatson
Frequent Contributor
Application
MxDocument
FocusMap
Layers - IFeatureLayer
FeatureClass - IFeatureClass
IDataset
Workspace

If you search the samples, I suspect that you will find the code.
0 Kudos
PaulLivingstone
New Contributor III
Thanks for the quick response Richard.

To help anyone else that is looking, the current workspace can be found via:

   IWorkspace ws = ((IDataset)ArcMap.Document.ActiveView.FocusMap.Layer[0]).Workspace;
0 Kudos
OliverBurdekin
New Contributor


To help anyone else that is looking, the current workspace can be found via:

   IWorkspace ws = ((IDataset)ArcMap.Document.ActiveView.FocusMap.Layer[0]).Workspace;


Looks good.  Any ideas how to rewrite that for Java?
0 Kudos
LeoDonahue
Occasional Contributor III
Here is a sample for opening a shapefile.  Or did you want to get the workspace from an existing layer in the map?

        IWorkspace workspace;
        IWorkspaceFactory workspacefactory;
        IFeatureWorkspace featureworkspace;

            workspacefactory = new ShapefileWorkspaceFactory();
            
            workspace = workspacefactory.openFromFile(filePath, 0);
            
            featureworkspace = (IFeatureWorkspace) workspace;
0 Kudos
JacquesMary
New Contributor
Here is a sample for opening a shapefile.  Or did you want to get the workspace from an existing layer in the map?

        IWorkspace workspace;
        IWorkspaceFactory workspacefactory;
        IFeatureWorkspace featureworkspace;

            workspacefactory = new ShapefileWorkspaceFactory();
            
            workspace = workspacefactory.openFromFile(filePath, 0);
            
            featureworkspace = (IFeatureWorkspace) workspace;


yes i am very interested with  getting the workspace from an existing layer in the map , could you get it ?
LaurenPeckman
New Contributor III

Was this question ever fully answered, perhaps someplace else? 

0 Kudos