How to instantiate IWorkspace

838
4
Jump to solution
11-18-2013 04:43 AM
StevenMumby
New Contributor
Hi guys

I'm writing an ArcMap class library.  This will add a menu item to ArcMap.  Once the menu option is clicked, I need to set my ArcMaps document into edit mode.  I've found a sample piece of code to help me accomplish this, but need to pass in a reference to an object of type IWorkspace.  This is being written with ArcObjects 9.3.  I currently have access to instances of IApplication and IMaps in my solution.  How can I accomplish this?

Tks
0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor
pFeatureLayer is the pointer to a layer. So you would get a handle on a layer in a map through IMap.Layer.  This returns a ILayer pointer. You would typically cast that into an IFeatureLayer which gives you access to many other properties such as the FeatureClass.

Duncan

View solution in original post

0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor
You can get a handle on the Workspace of a layer in the map document through IDataset.  So something like:

Dim pDS as IDataset
pDS = pFeaturelayer
Dim pWS as IWorkspace
pWS = pDS.Workspace


Duncan
0 Kudos
StevenMumby
New Contributor
Thanks Duncan.  Sorry for additional question, but what is pFeatureLayer?  I'm a web developer primarily and this is my first go at woring with arcGIS.
0 Kudos
DuncanHornby
MVP Notable Contributor
pFeatureLayer is the pointer to a layer. So you would get a handle on a layer in a map through IMap.Layer.  This returns a ILayer pointer. You would typically cast that into an IFeatureLayer which gives you access to many other properties such as the FeatureClass.

Duncan
0 Kudos
StevenMumby
New Contributor
Ah, it was the casting that was throwing me off.  This seems to work:

            // set the map into edit mode//
            IMap mMap = mMaps.get_Item(0);
            ILayer mLayer = mMap.get_Layer(0);
            IFeatureLayer mFeatureLater = (IFeatureLayer)mLayer;
            IDataset mDataSet = mFeatureLater.FeatureClass.FeatureDataset;
            IWorkspace mWorkSpace = mDataSet.Workspace;
            startEditing(mWorkSpace);

Tks for the help, Duncan.  Much appreciated.
0 Kudos