HOW TO
This sample script allows you to create a new tool that will move polygon vertices to specified coordinates.
Code: '-- Script: MoveVertex2Coord.ave ' '-- This script is to used on the "Apply" property of a new '-- tool on the View GUI. The script works on the selected '-- polygon of the active theme. Use the tool to click on '-- one of the selected polygon's vertices, then enter the '-- coordinates of where you want that vertex moved, when '-- prompted. ' '-- The polygon shapefile theme does not have to be in '-- edit-mode, but the user must have write-permissions to '-- the shapefile data, or the tool will not work. '-- Set up the initial objects theView = av.getactivedoc theDisplay = theView.GetDisplay clickedPoint = theDisplay.ReturnUserPoint theTheme = theView.GetActiveThemes.Get(0) theFTab = theTheme.GetFTab theFTab.SetEditable(true) shapeFld = theFTab.FindField("Shape") '- Make sure the user can edit this shapefile if (theFTab.CanEdit.Not) then MsgBox.Warning("The active theme cannot be edited","Stop") end '-- Make sure a polygon is selected selectedPolygonRecord = theFTab.GetSelection.GetNextSet(-1) if (selectedPolygonRecord = -1) then MsgBox.Warning("You must have one polygon selected","Stop") return nil end '-- Get the new vertex coordinates from the user newVertex = MsgBox.MultiInput ("Enter new vertex coordinates","",{"X:","Y:"},{"",""}) '-- Find which vertex is closet to the clicked point thePolygon = theFTab.ReturnValue(shapeFld,selectedPolygonRecord) listofPoints = {} for each polypiece in thePolygon.AsList for each aPt in polypiece.AsList listofPoints.Add(aPt) end end closestDist = 999999999 for each aPt in listofPoints thisDist = clickedPoint.Distance(aPt) if (thisDist < closestDist) then closestDist = thisDist closestPoint = aPt end end '-- Make a new polygon. Test each vertext to determine which is selected, '-- if it is, change its location to the XY coordinate specified by the user newPolygonList = {} for each polypiece in thePolygon.AsList newPolypiece = {} for each aPt in polypiece if ((aPt.GetX = closestPoint.GetX) and (aPt.GetY = closestPoint.GetY)) then aPt.SetX(newVertex.Get(0).AsNumber) aPt.SetY(newVertex.Get(1).AsNumber) end newPolypiece.Add(aPt) end newPolygonList.Add(newPolyPiece) end '-- Make the modified polygon newPolygon = Polygon.Make(newPolygonList) '- Replace the old polygon with the new one theFTab.SetValue(shapeFld,selectedPolygonRecord,newPolygon) '-- Stop editing the theme's FTab theFTab.SetEditable(false) '-- Redraw the view theView.Invalidate '-- End of Script: MoveVertex2Coord.ave
Note: For more information, refer to the ArcView Help topic "Customize (dialog box)."
Get help from ArcGIS experts
Download the Esri Support App