programmatically change snap environment and targetLayer in Editor arcMap

1715
2
02-16-2011 03:04 AM
cristiansanabria
New Contributor
Hi,

I want to change programmatically change the target layer and the snapEnvironment(vertex, edge, end) of a layer(s) I knew how to do it in arcMap 9.3 using IEditor, ISnapEnvironment and IEditLayers but since EditorToolbar has changed it seems that that code doesn't work in arcMap 10 could you please tell me how to do it???


regards.
Tags (2)
0 Kudos
2 Replies
by Anonymous User
Not applicable
Your code should work, but you will need to revert back to the classic snapping environment via IEditProperties4.ClassicSnapping or assume this is done on the editor options UI.
0 Kudos
cristiansanabria
New Contributor
Your code should work, but you will need to revert back to the classic snapping environment via IEditProperties4.ClassicSnapping or assume this is done on the editor options UI.


hi, this is the code I am using:

public void SetSnapEnvironment(string targetlayer)
        {
            bool stopEditingAtFinish = false;
            UIDClass edUID = new UIDClass();
            edUID.Value = ToolBarsNameIds.EsriEditorUId;
          
            //edUID.Value = "esriEditor.Editor";<-this is the id
            ESRI.ArcGIS.Editor.IEditor editor = MyExtension.Extension.m_app.FindExtensionByCLSID(edUID) as ESRI.ArcGIS.Editor.IEditor;
            ESRI.ArcGIS.Editor.ISnapEnvironment env = (ESRI.ArcGIS.Editor.ISnapEnvironment)editor;
            UIDClass eUID = new UIDClass();
            edUID.Value = ToolBarsNameIds.EsriEditorUId;
           
            ESRI.ArcGIS.ArcMapUI.IMxDocument document = (ESRI.ArcGIS.ArcMapUI.IMxDocument)MyExtension.Extension.m_app.Document;
            try
            {
                if (document.FocusMap != null && document.FocusMap.LayerCount > 0)
                {
                    ILayer selectedLayer = null;
                    if ( document.SelectedLayer != null )
                        selectedLayer = document.SelectedLayer;
                    else
                      
                        selectedLayer = GetTarguetLayer( targetlayer );
                    if (editor.EditState != esriEditState.esriStateEditing)
                    {
                        editor.StartEditing((((ESRI.ArcGIS.Carto.IFeatureLayer)selectedLayer).FeatureClass as ESRI.ArcGIS.Geodatabase.IDataset).Workspace);
                        stopEditingAtFinish = true;
                    }
                }
            }
            catch (Exception exc) { clsLog.MsgLog(exc.Message); }
            ISnappingWindow window=null;
            IFeatureSnapAgent agent=null;
            try
            {
                UID snapWindowid=new UID();
                snapWindowid.Value=ToolBarsNameIds.EsriEditorSnappingWindowsUid;
                window=(ISnappingWindow)editor.FindExtension(snapWindowid);
                for (int i = 0; i < env.SnapAgentCount; i++)
                {
                    agent = (IFeatureSnapAgent)env.get_SnapAgent(i);
                    UILayer layer = GetUILayerByName(agent.Name);
                    if (layer != null)
                    {
                        if (!layer.IsVertex && !layer.IsEdge && !layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartNone;
                        }
                        if (!layer.IsVertex && !layer.IsEdge && layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartEndpoint;
                        }
                        if (!layer.IsVertex && layer.IsEdge && !layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartBoundary;
                        }
                        if (!layer.IsVertex && layer.IsEdge && layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartBoundary | esriGeometryHitPartType.esriGeometryPartEndpoint;
                        }
                        if (layer.IsVertex && !layer.IsEdge && !layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartVertex;
                        }
                        if (layer.IsVertex && !layer.IsEdge && layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartVertex | esriGeometryHitPartType.esriGeometryPartEndpoint;
                        }
                        if (layer.IsVertex && layer.IsEdge && !layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartVertex | esriGeometryHitPartType.esriGeometryPartBoundary;
                        }
                        if (layer.IsVertex && layer.IsEdge && layer.IsEnd)
                        {
                            agent.HitType = esriGeometryHitPartType.esriGeometryPartVertex | esriGeometryHitPartType.esriGeometryPartBoundary | esriGeometryHitPartType.esriGeometryPartEndpoint;
                        }
                    }
                }
                /*************for target layer********************/
                if (!string.IsNullOrEmpty(step.TargetLayer))
                {
                    ILayer itargetlayer = GetTarguetLayer(targetlayer);
                    if (itargetlayer != null)
                    {
                        ((IEditLayers)editor).SetCurrentLayer((IFeatureLayer)itargetlayer, 0);
                    }
                }
                /******************************************/
                window.RefreshContents();
               
                if(stopEditingAtFinish)
                editor.StopEditing(true);
             
            }
            catch (Exception exc)
            {
                clsLog.MsgLog(exc.Message);
            }
        }

this method is used to set targetLayer in  editor(target layer comboBox in arcMap9.3) and set the snap environment, this code doesn't throw any exception but it doesn't work,  could you tell me please what things I should change to get this working in arcMap 10??

also could you tell me how to programmatically start a EditTask.?

regards.
0 Kudos