Is it possible to start editing of a specific featureClass programmatically?

3237
8
05-21-2014 04:45 AM
FossiG_
New Contributor III
Hello,

as described here (http://forums.arcgis.com/threads/109876-Start-editing-programmatically-how-to-get-the-workspace-to-e...) I start an editing session in ArcMap from another application. Furthermore I would like to preselect a specific featureClass for the "Create Features"-dialog.

My question: Is this even possible?
Alternative or even better: Is it possible to filter the featureClasses in the "Create Features"-dialog, so that there is only one available?

I will be grateful for any hint, since I found no point to start.

In my (poor) understanding, edit-sessions always relate to a workspace and a workspace includes one or more featureClasses. In this edit-session the user selects a class in which he wants to create a new feature. I want this featureClass to be set from another application. Perhaps this is a silly idea or a totally wrong approach, so I appreciate your thoughts. Thank you very much.

Regards
Fossi
0 Kudos
8 Replies
FossiG_
New Contributor III
Hello Sol,

thanks for your anwser. Could you give me hint, where or how I can set the edit layer? Perhaps I am just looking at the wrong place. Is the editorClass the right origin? Thank you very much.

Regards
Fossi
0 Kudos
FossiG_
New Contributor III
Very sorry. I must be dumb, but I don't get it. :confused:

Dim pMxDoc as IMxDocument
Dim pFeatureLayer as IFeatureLayer
Dim pDataset as IDataset
Dim pEditor as IEditor
Dim pUID as new UID

Set pMxDoc = ThisDocument
Set pFeatureLayer = pMxDoc.FocusMap.Layer(0)
Set pDataset = pFeatureLayer.FeatureClass

pUID.Value = "esriCore.Editor"
Set pEditor = Application.FindExtensionByCLSID(pUID)

pEditor.StartEditing pDataset.Workspace


As far as I understand this, the 1st featureClass is only used to determine the workspace. And in this workspace an edit-session is started  (that is quite similar to what I achieved with the sample linked above).

But how do I point the "create feature" dialog to one specific featureClass when the workspace contains several featureClasses?
0 Kudos
FossiG_
New Contributor III
Hi Sol,
sorry for the delay. I called it a day last night, when this topic gave me a headache. Still working on it. The snippet you provided looks very promising, but I had no luck so far, getting this to work.

Here is my current try:
private void startEditingAndSelectEditLayer(ESRI.ArcGIS.Framework.IApplication ArcMap)
        {
            //derived from http://resources.esri.com/help/9.3/ArcGISDesktop/dotnet/2626201e-de60-4bab-bb1c-d16fcd4f8c4b.htm#NETFeature
            ESRI.ArcGIS.Geodatabase.IFeatureClass m_featureClass;
            ESRI.ArcGIS.Carto.IFeatureLayer m_featureLayer;
            ESRI.ArcGIS.Editor.IEditor m_editor;

            //get current document from ArcMap-Application
            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = (ESRI.ArcGIS.ArcMapUI.IMxDocument)ArcMap.Document;
            //get current contentsview
            ESRI.ArcGIS.ArcMapUI.IContentsView curTOC = mxDocument.CurrentContentsView;

            //get select featureLayer in contents view
            //http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000016000000
            m_featureLayer = ArcMapHelperFunctions.GetSelectedFeatureLayerInContentsView(mxDocument.CurrentContentsView);

            //get featureClass of this layer
            m_featureClass = m_featureLayer.FeatureClass;

            //Once the feature class has been referenced, get the workspace to edit by creating an IFeatureWorkspace
            //and setting an IWorkspace object to the feature workspace using a cast. 
            ESRI.ArcGIS.Geodatabase.IWorkspace editWorkspace = (m_featureClass as ESRI.ArcGIS.Geodatabase.IDataset).Workspace;

            //Start an edit session on the workspace holding the feature class
            ESRI.ArcGIS.esriSystem.UID editorUid = new ESRI.ArcGIS.esriSystem.UID();
            editorUid.Value = "esriEditor.Editor";
            m_editor = ArcMapHelperFunctions.app.FindExtensionByCLSID(editorUid) as ESRI.ArcGIS.Editor.IEditor3;

            //define edit layer, to set the editor selecting a specific layer
            //http://forums.arcgis.com/threads/110456-Is-it-possible-to-start-editing-of-a-specific-featureClass-programmatically
            //http://forums.esri.com/Thread.asp?c=93&f=992&t=58618&mc=10#msgid147954
            ESRI.ArcGIS.Editor.IEditLayers EditLayer;
            EditLayer = (m_editor as ESRI.ArcGIS.Editor.IEditLayers);
            MessageBox.Show(m_featureLayer.Name); //did I get the right layer?
            MessageBox.Show(EditLayer.IsEditable(m_featureLayer).ToString()); //is it editable?
            //EditLayer.SetCurrentLayer(m_featureLayer, 0); //set current layer before start editing -- no success

            m_editor.StartEditing(editWorkspace);
            m_editor.StartOperation();
            EditLayer.SetCurrentLayer(m_featureLayer, 0); //set current layer after start editing -- no success
        }


In the screenshot below you see Layer2 active in the TOC. This is correctly identified by m_featureLayer in the code above (cross-checked with the messagebox). But in the "create feature" dialog none of the layer becomes active. layer1 has a grey background but is not really activated, if you click on it, it gets a blue background and not till then you can start the sketch. And besides the 2nd layer should be the one activated.

[ATTACH=CONFIG]33998[/ATTACH]

Thanks for your help. Any hint is appreciated.

Regards
Fossi
0 Kudos
FossiG_
New Contributor III
Thanks but no, UpdateContents or Refresh gives no improvement.

Umm, could it be we got a vocabulary and version issue here?

As I know meanwhile the element I am playing with is called "feature template". Perhaps I just asked the wrong questions due to my poor knowledge of the technical terms.:o Memo to myself: Install the english version of the product to get the right terms!

Further I belief I read somewhere, that these feature templates are rather new (ArcMap 10). So could it be SetCurrentLayer only works with ArcMap version 9 or below?!

Here is a little code I wrapped around the m_editor.StartEditing(editWorkspace) of the snippet above. Which allows to select a feature template. I think I will look further into this, perhaps I find a way, to remote-control the "filter"-feature of this dialog.

[...]
ESRI.ArcGIS.Carto.IEditTemplate EditTemplate;
EditTemplate = m_editor.CurrentTemplate;
EditTemplate = (m_editor as ESRI.ArcGIS.Carto.IEditTemplate);
MessageBox.Show(m_editor.TemplateCount.ToString());

m_editor.StartEditing(editWorkspace);
MessageBox.Show(m_editor.TemplateCount.ToString());

for (int i = 0; i < m_editor.TemplateCount - 1; i++)
{
    EditTemplate = m_editor.get_Template(i);
    m_editor.CurrentTemplate = EditTemplate;
    MessageBox.Show(EditTemplate.Layer.Name);
}
[...]


Thanks so far. Further comments are still appreciated.

Regards
Fossi
0 Kudos
AhmedEl-Sisi
Occasional Contributor III
Hi Fossi,

You should read this topic about Using feature templates.

Basically you will use IEditor3.RemoveAllTemplatesInMap Method
to remove all existing layer templates and then start adding your template(s) via IEditor3.AddTemplates Method.

Quick Sample:
private void FilterEditTemplates()
        {
            try
            {
                //Start an edit session on the workspace holding the feature class.
                IWorkspace editWorkspace = GetWorkspace() as IWorkspace;
                ESRI.ArcGIS.esriSystem.UID editorUid = new ESRI.ArcGIS.esriSystem.UID();
                editorUid.Value = "esriEditor.Editor";
                ESRI.ArcGIS.Editor.IEditor3 m_editor = ArcMap.Application.FindExtensionByCLSID(editorUid) as ESRI.ArcGIS.Editor.IEditor3;

                m_editor.StartEditing(editWorkspace);
                //Remove All Existing Templates
                m_editor.RemoveAllTemplatesInMap(ArcMap.Document.FocusMap);

                //Get your edit layer (Layer belongs to edit workspace)
                ILayer editLayer = GisHelper.GetLayerByName("YourLayerName");
                //Make new template
                IEditTemplateFactory editTemplateFact = new EditTemplateFactoryClass();
                IEditTemplate newEditTemplate = editTemplateFact.Create("MyTemplateName", editLayer);

                //Add the template to editor.
                IArray templateArray = new ArrayClass();
                templateArray.Add(newEditTemplate);
                m_editor.AddTemplates(templateArray);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }


Regards,
Ahmed
FossiG_
New Contributor III
Hello Ahmed,

your sample works nice as described, but removing templates permanently is not what I intended. Any idea about just temporarily filtering those templates?

Thanks and Regards
Fossi
0 Kudos
AhmedEl-Sisi
Occasional Contributor III
Hello Ahmed,

your sample works nice as described, but removing templates permanently is not what I intended. Any idea about just temporarily filtering those templates?

Thanks and Regards
Fossi


I didn't find a way to access filter window yet. It's included in the create feature dockable window and I don't think that you can access it.
Check this sample for a custom feature template box,It may help you.
http://blogs.esri.com/esri/arcgis/2011/12/13/implementing-a-feature-template-dialog-box-in-your-code...
0 Kudos
FossiG_
New Contributor III
Hello Ahmed,

for now I postponed the attempt to access the filter window programmatically. I agree with you that there is probably no way to access it in the current version.

Working with a custom feature template window looks like a promising approach. But due to a tight schedule that way is a bit to oversized for now. Will try it anyway out of curiosity as soon as there is a little spare time and post back here with my findings.

Thank you for your ideas.

Regards
Fossi
0 Kudos