Created
September 6, 2017 09:17
-
-
Save AlexArcPy/65f83c901a89e879f8d42a6e4f786aad to your computer and use it in GitHub Desktop.
Execute Copy Parallel on a selected line feature with the set offset value while in the editing session in ArcMap. Will create multiple features using the interval values set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.IO; | |
using ESRI.ArcGIS.esriSystem; | |
using ESRI.ArcGIS.Framework; | |
using ESRI.ArcGIS.Editor; | |
using ESRI.ArcGIS.Geodatabase; | |
using ESRI.ArcGIS.Geometry; | |
namespace CopyParallels | |
{ | |
public class CopyParallelsExecuteClass : ESRI.ArcGIS.Desktop.AddIns.Button | |
{ | |
public CopyParallelsExecuteClass() | |
{ | |
} | |
private void DoCopyParallel(IFeatureClass fc, IFeature f, int startValue, int endValue, int stepValue, int side) | |
{ | |
for (int offsetValue = startValue; offsetValue <= endValue; offsetValue = offsetValue + stepValue) | |
{ | |
//Interface to do a "copy parallel" | |
IConstructCurve3 construct = new PolylineClass(); | |
//How to construct | |
object offset = esriConstructOffsetEnum.esriConstructOffsetMitered; | |
IPolyline source = f.Shape as IPolyline; | |
//Side determines left/right with -1/+1 | |
construct.ConstructOffset(source, offsetValue * side, ref offset); | |
//Storing output shape | |
IFeature newFeature = fc.CreateFeature(); | |
newFeature.Shape = (IGeometry)construct; | |
newFeature.Store(); | |
} | |
return; | |
} | |
protected override void OnClick() | |
{ | |
//Read and parse user values | |
string V = IntervalsSetterComboBox.comboValue; | |
string[] Arr = V.Split(','); | |
int startValue = Convert.ToInt16(Arr[0]); | |
int endValue = Convert.ToInt16(Arr[1]); | |
int stepValue = Convert.ToInt16(Arr[2]); | |
//Get the editor | |
UID uid = new UIDClass(); | |
uid.Value = "esriEditor.Editor"; | |
IEditor editor; | |
editor = (IEditor)ArcMap.Application.FindExtensionByCLSID(uid); | |
//Get selected feature | |
IEnumFeature enumfeature = editor.EditSelection; | |
IFeature f = enumfeature.Next(); | |
//For adding a new feature | |
IFeatureClass fc = f.Class as IFeatureClass; | |
//Start an editing operation for undo/redo | |
editor.StartOperation(); | |
DoCopyParallel(fc, f, startValue, endValue, stepValue, 1); | |
DoCopyParallel(fc, f, startValue, endValue, stepValue, -1); | |
editor.StopOperation("Copy Parallel"); | |
//Refresh map | |
ArcMap.Document.ActiveView.Refresh(); | |
} | |
protected override void OnUpdate() | |
{ | |
Enabled = ArcMap.Application != null; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
using System.IO; | |
namespace CopyParallels | |
{ | |
public class IntervalsSetterComboBox : ESRI.ArcGIS.Desktop.AddIns.ComboBox | |
{ | |
public static string comboValue; | |
public IntervalsSetterComboBox() | |
{ | |
} | |
protected override void OnUpdate() | |
{ | |
Enabled = ArcMap.Application != null; | |
comboValue = Value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment