TitlePages

Thursday 22 January 2015

ArcFm Auto Updaters to Update the Shape Length of the Feature

Schneider electric

Update the Shape Length of the Poly line Feature

Special Auto Up-daters

A special Auto Up-daters differs from the attribute Auto Up-daters in that it is not associated with a field/event combination but rather a feature/event combination. A special Auto Up-daters can be associated to the On Feature Create, On Feature Update, or On Feature Delete events of a feature.

Special Auto Up-daters are not limited to simple field updates like attribute Auto Up-daters. Rather, they can be written to perform a wide array of tasks such as writing out text files, updating records in a remote database, sending emails - just about anything that you would need to programmatically do in response to a feature/object.

IMMSpecialAUStrategyEx Interface




  1. Do the following steps to start with AutoUpdaters.
  2. Start your Visual Studio 2010 or More 
  3. Create a New Project of Type base Command from ArcGIS tab .Choose the Programming Language of your comfort(VB or C#.Net)
  4. Give a Name to the Project and your can see base class library with your dll registered function with Unique Code GUID.
  1. To get the Functionality of the Special AutoUpdaters in your code implement the Specific Interface ie. IMMSpecialAUStrategyEx Interface


public class ShapeLengthAU : IMMSpecialAUStrategyEx
    {

        private string _name;
//Name is a required parameter for the Implemented Interface
        public string Name
        {
            get
            {
                if (string.IsNullOrEmpty(_name))
                {
                    _name =”Name of your Autoupdater
                }
                return _name;
            }
        }

        
        public void Execute(IObject obj, mmAutoUpdaterMode eAUMode, mmEditEvent editEvent)
        {
            IPCursor pCursor = null;
            try
            {
//Autoupdater will update only when the EditEvent is of Type like FeatureCreate,FeatureSplit,FeatureUpdate
                if (editEvent == mmEditEvent.mmEventFeatureCreate || editEvent == mmEditEvent.mmEventFeatureSplit || editEvent == mmEditEvent.mmEventFeatureUpdate)
                {
                    IFeature pFeature = obj as IFeature;
                    IPolyline pPolyLine = pFeature.Shape as IPolyline;
                    double ftLength = pPolyLine.Length;
//Place the length value in to the Pfeature respective field
                    pFeature.set_Value(pFeature.Fields.FindField(“ShapeFieldName”), ftLength);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (pCursor != null)
                {
//Use the Marshalling Method to release the Cursoer from the Memory
                    Marshal.ReleaseComObject(pCursor); 
                }
            }           
        }
//get_Enabled is a required Method for the Implemented Interface
        public bool get_Enabled(IObjectClass,pObjectClass, mmEditEvent eEvent)
        {
            return true;
        }

        
    }
}

Now Compile the Code and Execute.
Note:Set the Startup Project for Debugging as ArcCatalog.exe in the Project Properties.

Go to Arc-Catalog , Right Click on your ArcFM feature and Select ArcFm Properties Mangaer

Select the Object Tab.It will display the various event from the ArcFm for the Particular Object.
Assign your Auto Updaters to the various event you want to call.

Do the edit in the feature through ArcMap editor.This will trigger your Updaters.






Thursday 15 January 2015

Modifying the Vertices of a Polyline in ArcMap using ArcObjects

Modifying the Vertices of a Polyline using ArcObjects


1.Start the Editing Mode in the Editor Toolbar

2.This will create an edit session

3.Using the editor tool select the polyline feature you want to edit

4.Click on our Custom tool

5.The vertices of our polyline will be visible

6.Save the edits

7.Stop editing and complete the session

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;


namespace ToolTest
{
    public class poli : ESRI.ArcGIS.Desktop.AddIns.Tool
    {
        public static Boolean mousedown = false;
        public static IEditor3 meditor=null;
        IEditSketch3 editsketch = meditor as IEditSketch3;

        public poli()
        {
        }

        protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            if (mousedown == false)
            {

                meditor = GetEditorFromArcMap(ArcMap.ThisApplication) as IEditor3;
                //IWorkspace workspace = (GetFeatureLayerFromLayerIndexNumber((ArcMap.Application.Document as IActiveView), 1).FeatureClass as IWorkspace);
                //if(meditor.EditState!=esriEditState.esriStateEditing)
                //meditor.StartEditing(workspace);






                IEditSketch3 editsketch = meditor as IEditSketch3;
                editsketch.GeometryType = esriGeometryType.esriGeometryPolyline;


                 IEditTaskSearch editTaskSearch = meditor as IEditTaskSearch;
 IEditTask editTask = editTaskSearch.get_TaskByUniqueName("GarciaUI_ModifyFeatureTask");

  //Set the task returned to the current edit task.
 if (editTask != null)
 {
     meditor.CurrentTask = editTask;
 }
                ISketchOperation sk = new SketchOperationClass();
                sk.Start(meditor);

             

             
            }
            if(mousedown==true)
            {
                if(editsketch.Geometry==null)
                {
                    IPolyline poly;
                    poly = editsketch as IPolyline;
                    editsketch.FinishSketch();

                }
                else
                {
                    mousedown=false;
                }


            }
       

         
        }


        protected override void OnMouseUp(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
         
        }

public ESRI.ArcGIS.Editor.IEditor2 GetEditorFromArcMap(ESRI.ArcGIS.ArcMapUI.IMxApplication mxApplication)
{
  if(mxApplication == null)
  {
    return null;
  }
  ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
  uid.Value = "{F8842F20-BB23-11D0-802B-0000F8037368}";
  ESRI.ArcGIS.Framework.IApplication application = mxApplication as ESRI.ArcGIS.Framework.IApplication; // Dynamic Cast
  ESRI.ArcGIS.esriSystem.IExtension extension = application.FindExtensionByCLSID(uid);
  ESRI.ArcGIS.Editor.IEditor2 editor2 = extension as ESRI.ArcGIS.Editor.IEditor2; // Dynamic Cast

  return editor2;
}




public ESRI.ArcGIS.Carto.IFeatureLayer GetFeatureLayerFromLayerIndexNumber(ESRI.ArcGIS.Carto.IActiveView activeView, System.Int32 layerIndex)
{
    if (activeView == null || layerIndex < 0)
    {
        return null;
    }
    ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap;
    if (layerIndex < map.LayerCount && map.get_Layer(layerIndex) is ESRI.ArcGIS.Carto.IFeatureLayer)
    {
        return (ESRI.ArcGIS.Carto.IFeatureLayer)activeView.FocusMap.get_Layer(layerIndex); // Explicit Cast
    }
    else
    {
        return null;
    }
}
public ESRI.ArcGIS.Geometry.IPointCollection4 modifyFirstVertexOfAPolyline
(ESRI.ArcGIS.Geometry.IGeometryCollection geometryCollection_Polyline,
System.Double searchRadius, System.Double offsetX, System.Double offsetY)
{
    ESRI.ArcGIS.Geometry.IPolyline polyline = (ESRI.ArcGIS.Geometry.IPolyline)
        geometryCollection_Polyline;
    ESRI.ArcGIS.Geometry.IPoint queryPoint = polyline.FromPoint;

    ESRI.ArcGIS.Geometry.IPoint hitPoint = new ESRI.ArcGIS.Geometry.PointClass();

    //Define and initialize the variables that will get populated from the .HitTest() method.
    System.Double hitDistance = 0;
    System.Int32 hitPartIndex = 0;
    System.Int32 hitSegmentIndex = 0;
    System.Boolean rightSide = false;

    ESRI.ArcGIS.Geometry.IHitTest hitTest = (ESRI.ArcGIS.Geometry.IHitTest)
        geometryCollection_Polyline;
    System.Boolean foundGeometry = hitTest.HitTest(queryPoint, searchRadius,
        ESRI.ArcGIS.Geometry.esriGeometryHitPartType.esriGeometryPartVertex,
        hitPoint, ref hitDistance, ref hitPartIndex, ref hitSegmentIndex, ref
        rightSide);

    if (foundGeometry == true)
    {
        ESRI.ArcGIS.Geometry.IGeometry geometry =
            geometryCollection_Polyline.get_Geometry(hitPartIndex);
        ESRI.ArcGIS.Geometry.IPointCollection4 pointCollection =
            (ESRI.ArcGIS.Geometry.IPointCollection4)geometry;
        ESRI.ArcGIS.Geometry.IPoint transformPoint = pointCollection.get_Point
            (hitSegmentIndex);

        ESRI.ArcGIS.Geometry.ITransform2D transform2D =
            (ESRI.ArcGIS.Geometry.ITransform2D)transformPoint;
        transform2D.Move(offsetX, offsetY);

        ESRI.ArcGIS.Geometry.IPoint afterMovePoint = (ESRI.ArcGIS.Geometry.IPoint)
            transform2D;

        //The point is not updated in the polyline until the next line is called.
        pointCollection.UpdatePoint(hitSegmentIndex, (ESRI.ArcGIS.Geometry.IPoint)
            transform2D);

        return pointCollection;
    }

    return null;

}

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

}