HOW TO
This article describes how to add to the View GUI a tool that rotates features within a shapefile.
Code:
'-- Script: RotateShapeApply.ave
'-- Determine the selected features
theView = av.GetActiveDoc
theTheme = theView.GetEditableTheme
theFTab = theTheme.GetFTab
fldShape = theFTab.FindField("Shape")
theSel = theFTab.GetSelection
'-- Set the rotation angle
rotAngle = System.GetEnvVar("Angle").AsNumber
if (System.IsShiftKeyDown.Not) then
rotAngle = -1 * rotAngle
end
'-- Get the centre of rotation from the mouse click
rotPt = theView.GetDisplay.ReturnUserPoint
xs = rotPt.GetX
ys = rotPt.GetY
'-- If the theme is a polyline or polygon theme...
'-- Rotate the selected shapes
if ((fldShape.GetType = #FIELD_SHAPELINE) or
(fldShape.GetType = #FIELD_SHAPEPOLY))
then
if (theFTab.StartEditingWithRecovery) then
for each r in theSel
shpIn = theFTab.ReturnValue(fldShape,r)
lstPoints = shpIn.AsList.Get(0)
newPoints = List.Make
for each pt in lstPoints
x1 = pt.GetX - xs
y1 = pt.Gety - ys
a1 = (y1 / x1).Atan
c = y1 / (a1.Sin)
a2 = (rotAngle * 0.01745329) + a1
x2 = a2.Cos * c
y2 = a2.Sin * c
xf = xs + x2
yf = ys + y2
newPt = Point.Make(xf,yf)
newPoints.Add(newPt)
end
if (shpIn.Is(Polygon)) then
shpOut = Polygon.Make({newPoints})
elseif (shpIn.Is(Polyline)) then
shpOut = Polyline.Make({newPoints})
else
exit
end
shpOut.Clean
theFTab.SetValue(fldShape,r,shpOut)
theFTab.EndTransaction
end
theView.SetSelectMode(#GRAPHICS_SELECT_NORMAL)
theTheme.Invalidate(True)
end
end
if (fldShape.GetType = #FIELD_SHAPEPOINT)
then
for each r in theSel
shpIn = theFTab.ReturnValue(fldShape,r)
pt = shpIn
x1 = pt.GetX - xs
y1 = pt.Gety - ys
a1 = (y1 / x1).Atan
c = y1 / (a1.Sin)
a2 = (rotAngle * 0.01745329) + a1
x2 = a2.Cos * c
y2 = a2.Sin * c
xf = xs + x2
yf = ys + y2
newPt = Point.Make(xf,yf)
shpOut = newPt
theFTab.SetValue(fldShape,r,shpOut)
theFTab.EndTransaction
end
theView.SetSelectMode(#GRAPHICS_SELECT_NORMAL)
theTheme.Invalidate(True)
end
'-- End of script: RotateShapeApply.ave
Code:
'-- Script: RotateShapeClick.ave
rotAngle = System.GetEnvVar("Angle")
if (rotAngle = nil) then
rotAngle = "0"
end
response = msgBox.Input("Enter rotation angle", "Rotate Shape",rotAngle)
if (response = nil) then
exit
else
System.SetEnvVar("Angle",response)
end
'-- End of Script: RotateShapeClick.ave
Code:
'-- Script: RotateShapeUpdate.ave
theTheme = av.GetActiveDoc.GetEditableTheme
if (theTheme = nil) then
selCount = 0
else
selCount = theTheme.GetFTab.GetSelection.Count
end
SELF.SetEnabled(selCount > 0)
'-- End of script: RotateShapeUpdate.ave
Apply: RotateShapeApply.ave
Click: RotateShapeClick.ave
Cursor: Cursors.Bullseye
Disabled: true
Icon: Switch Select
Invisible: False
Update: RotateShapeUpdate.ave
Note:
The script uses this point as the axis of rotation.
Article ID:000003714
Get help from ArcGIS experts
Download the Esri Support App