Programmatically start edit session on workspace and display error/warning dialog

5267
9
Jump to solution
12-14-2012 07:42 AM
AllenPoling
New Contributor II
Is there a way to programmatically start an edit session on a feature layer in ArcMap and have the Start Editing warnings/errors dialog be displayed if there are any issues?

IEditor.StartEditing() does not display the dialog.

ICommandItem.Execute()  for the "esriEditor.StartEditingCommand" works - but it also requires my user to select the layer/workspace they want to operate on.

I'm really trying to replicate the behavior of the Edit Features -> Start Editing context menu item for a feature layer in the ArcMap TOC.

Any ideas?
0 Kudos
1 Solution

Accepted Solutions
AllenPoling
New Contributor II
Finally found the correct command items.
The featureLayer variable refers to an IFeatureLayer object.
The app variable refers to an IApplication object.

        If featureLayer IsNot Nothing Then             Dim menuUID As New ESRI.ArcGIS.esriSystem.UID             menuUID.Value = "esriArcMapUI.FeatureLayerEditMenu"             Dim commandBar As ICommandBar = app.Document.CommandBars.Find(menuUID)             If commandBar IsNot Nothing Then                 Dim itemUID As New ESRI.ArcGIS.esriSystem.UID                 itemUID.Value = "esriArcMapUI.LayerStartEditingCommand"                 Dim cmdItem As ICommandItem = commandBar.Find(itemUID)                 If cmdItem IsNot Nothing Then                     DirectCast(app.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument).ContextItem = featureLayer                     cmdItem.Execute()                 End If             End If         End If

View solution in original post

0 Kudos
9 Replies
LeoDonahue
Occasional Contributor III
Good question.

The docs for IEdtor.startEditing only indicate that the startEditing operation will fail if there are no feature layers in the workspace or if the data is read-only or non-versioned SDE data.

Could you set the current layer using the setCurrentLayer method on IEditor and then execute the command item?
0 Kudos
AllenPoling
New Contributor II
Interesting idea Leo.

I gave it a try but setting the Editors current layer didn't affect the behavior. It still prompts me for the layer/workspace to be edited.

I also tried setting the MxDoc's context item to the feature layer using IMxDocument.ContextItem - but this also didn't seem to work.

Thanks for the suggestion.
0 Kudos
LeoDonahue
Occasional Contributor III
Option #2.

Catch the IO or Automation Exception and force it to fail so you can get the error message and roll your own notification dialog.

Sorry for the Java example:

        if(workspace.getType() == com.esri.arcgis.geodatabase.esriWorkspaceType.esriLocalDatabaseWorkspace){
            
            Workspace workspaceLocalDB = new Workspace(dataset.getWorkspace());
            
            // Cast the workspace to an IWorkspaceEdit and start an edit session.
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspaceLocalDB;
            workspaceEdit.startEditing(true);  // you would get an automation exception here if it fails.
            
            // Start an edit operation.
            workspaceEdit.startEditOperation();
            
            feature.store();
            
            // Stop the edit operation.
            workspaceEdit.stopEditOperation();
            
            // Stop the edit session.
            workspaceEdit.stopEditing(true);

        }
0 Kudos
AllenPoling
New Contributor II
This would work if I wanted to display the error as to why an editing session couldn't be started.

When you start an editing session in ArcMap from the Editor Toolbar - you are first presented with a dialog to select the layer or workspace to begin editing. This dialog is NOT displayed if you start editing on a layer via its context menu. After making a selection, the layers in the data frame are checked for issues that might affect editing. If any are detected, they are displayed in a 'Start Editing' dialog. Often this dialog may only display warnings and the user is allowed to continue opening an editing session. I've attached a sample image of this dialog.

[ATTACH=CONFIG]19997[/ATTACH]

I'm looking for a way to access this data checking and dialog functionality.
0 Kudos
LeoDonahue
Occasional Contributor III
Now I understand what you want to do.

In your first post you mentioned that if you right click the layer, your solution works, but you did not want your users to be forced to select the layer.  Doesn't the Start Editing dialog do the same, if you have two layers from different worspaces, one being a shapefile and one being a featureclass from a read only SDE geodatabase, depending on which layer your user clicks in the first Start Editing dialog, depends on what they see in the second Start Editing dialog (if there is a second dialog).

If your user clicks on the shapefile workspace, you won't get a second Start Editing dialog.  If your user clicks on the read only SDE featureclass workspace, you will get a second Start Editing dialog that says something to the effect of no editable layer, and that the layer or table is not registered as versioned.

[ATTACH=CONFIG]20001[/ATTACH]
0 Kudos
AllenPoling
New Contributor II
In my first post, what I described as working - ICommandItem.Execute() is equivalent to clicking the Editor -> Start Editing menu item from the Editor toolbar. In this scenario the user is required to select a layer/workspace because ArcMap doesn't know what they wish to edit.

When the Edit Features -> Start Editing context menu item of a layer in the ArcMap TOC is clicked - ArcMap knows which layer to start editing on - and therefore doesn't need to present the user with the dialog to select which layer/workspace to start editing. It still evaluates all layers and presents the warning/error dialog if any issues are detected. This is what I'm trying to accomplish.

Interestingly, the warning/error dialog appears to display issues related to ALL layers in the active data frames table of contents - NOT just the ones being edited. The dialog attachment from my last post shows warnings for 5 layers. Two of these layers were from the workspace (FGDB) that I started an edit session on, the other three were from an SDE workspace.
0 Kudos
LeoDonahue
Occasional Contributor III

When the Edit Features -> Start Editing context menu item of a layer in the ArcMap TOC is clicked - ArcMap knows which layer to start editing on - and therefore doesn't need to present the user with the dialog to select which layer/workspace to start editing. It still evaluates all layers and presents the warning/error dialog if any issues are detected. This is what I'm trying to accomplish.


I'm using ArcGIS Desktop - ArcInfo 10.0 SP5.  When I click Start Editing from the context menu, you are correct, ArcMap knows which layer I'm working on. 

When I click Start Editing from the Editing Toolbar, which I thought you mentioned that in your previous post, if there are two layers from different workspaces, you still have to select a layer, before you get the second warnings and errors start editing dialog.

I don't know of a way to hook into this dialog, it doesn't seem like it's something ESRI provides us access to in ArcObjects. If they do, I don't see it in the API.


Interestingly, the warning/error dialog appears to display issues  related to ALL layers in the active data frames table of contents - NOT  just the ones being edited. The dialog attachment from my last post  shows warnings for 5 layers. Two of these layers were from the workspace  (FGDB) that I started an edit session on, the other three were from an  SDE workspace.

Then the account you are using must already have edit access to these.  Are the featureclasses versioned?  Is that an SDE Workgroup or Enterprise license?
0 Kudos
AllenPoling
New Contributor II
Then the account you are using must already have edit access to these.  Are the featureclasses versioned?  Is that an SDE Workgroup or Enterprise license?


The other feature classes are versioned feature classes from an SDE Workgroup.
0 Kudos
AllenPoling
New Contributor II
Finally found the correct command items.
The featureLayer variable refers to an IFeatureLayer object.
The app variable refers to an IApplication object.

        If featureLayer IsNot Nothing Then             Dim menuUID As New ESRI.ArcGIS.esriSystem.UID             menuUID.Value = "esriArcMapUI.FeatureLayerEditMenu"             Dim commandBar As ICommandBar = app.Document.CommandBars.Find(menuUID)             If commandBar IsNot Nothing Then                 Dim itemUID As New ESRI.ArcGIS.esriSystem.UID                 itemUID.Value = "esriArcMapUI.LayerStartEditingCommand"                 Dim cmdItem As ICommandItem = commandBar.Find(itemUID)                 If cmdItem IsNot Nothing Then                     DirectCast(app.Document, ESRI.ArcGIS.ArcMapUI.IMxDocument).ContextItem = featureLayer                     cmdItem.Execute()                 End If             End If         End If
0 Kudos