Select to view content in your preferred language

Using the FlipLineDirection Code snippet

735
0
05-19-2011 12:49 PM
ChrisNelsen
Occasional Contributor
I'm trying to use the provided Flip Line Direction Code Snippet, but don't really know much programming. I created a button using C# in Vsual Studio and am trying to call it in the protected override void OnClick(). I realize I'm not getting to the command, but don't know the correct coding for the parameters. Any insight would be appreciated.

namespace FlipLine
{
    public class FlipLine : ESRI.ArcGIS.Desktop.AddIns.Button
    {
        #region Class Fields
        private IEditor3 editor;
        private IEditEvents_Event m_editEvents;
        private IEditEvents5_Event m_editEvents5;
        private IApplication application = ArcMap.Application;
        #endregion

        public FlipLine()
        {
            // Get the Editor
            UID editorUid = new UID();
            editorUid.Value = "esriEditor.Editor";
            editor = application.FindExtensionByCLSID(editorUid) as IEditor3;
            m_editEvents = editor as IEditEvents_Event;
            m_editEvents5 = editor as IEditEvents5_Event;
        }

        protected override void OnClick()
        {

           
            FlipLineDirection(application, editor);

        }

        protected override void OnUpdate()
        {
            Enabled = ArcMap.Application != null;
        }
        

#region "Flip Line Direction"

///<summary>The edit sketch direction of all of the selected polyline features is changed or flipped.</summary>
///
///<param name="application">An IApplication interface.</param>
///<param name="editor">An IEditor interface.</param>
/// 
///<remarks>Already must have a reference to IApplication and get the editor and start an edit session in the edit session you must have an edit selection, the code checks to make sure it is a line feature class and makes sure that there is an edit selection.</remarks>
public void FlipLineDirection(IApplication application, IEditor editor)
{
 
  if(application == null || editor == null)
  {
    System.Windows.Forms.MessageBox.Show("Flip operation aborted");
    return;
  }
  IEditLayers editLayers = editor as IEditLayers;
 
  // set up the progress bar and convert the number of selected features into an integer value.
  Int32 step = Convert.ToInt32(editor.SelectionCount / 100);
  ESRI.ArcGIS.esriSystem.IStatusBar statusBar = application.StatusBar;
  ESRI.ArcGIS.esriSystem.IStepProgressor stepProrogressor = statusBar.ProgressBar;



  stepProrogressor.MinRange = 1;
  stepProrogressor.MaxRange = 100;
  stepProrogressor.Message = "Flipping features...";
  stepProrogressor.Position = 0;
  stepProrogressor.StepValue = 1;
  stepProrogressor.Show();

  try
  {
    // flip all the selected features in an edit operation
    editor.StartOperation();

    IEnumFeature enumFeature = editor.EditSelection;
    enumFeature.Reset();

   
    for (Int32 featCount = 0; featCount <= editor.SelectionCount - 1; featCount++)
    {
      IFeature feature = enumFeature.Next();
      if(!(feature is ICurve))
      {
        continue;
      }
      ICurve curve = feature.Shape as ICurve;
     
      curve.ReverseOrientation();
      feature.Shape = curve;
      feature.Store();

      if (featCount == step)
      {
        stepProrogressor.Step();
        step = step + Convert.ToInt32(editor.SelectionCount / 100);
      }
    }

    editor.StopOperation("Flip");
    stepProrogressor.Hide();
    return;
  }
  catch(Exception e)
  {
    editor.AbortOperation();
    System.Windows.Forms.MessageBox.Show("Flip operation aborted");
    return;
  }
 
}
#endregion
    }

}
0 Kudos
0 Replies