HOW TO
Code:
'--- Script: node.ave
'--- This script converts a polyline theme into a new point shapefile theme,
'-- where each point represents the end points of every polyline.
'-- This script supports multi-part shapes so that if a polyline is made up
'-- of several parts, end points will be created for each polyline multi-part.
'-- The script exits gracefully if active theme does not contain polylines.
theView = av.getactivedoc
theTheme = theView.GetActiveThemes.Get(0)
inFTab = theTheme.GetFTab
inNumRecs = inFTab.GetNumRecords
inShapeFld = inFTab.FindField("Shape")
outPointList = {}
if ((inShapeFld.gettype = #FIELD_SHAPELINE).Not)then
MsgBox.Warning("Active theme is not polyline","")
return nil
end
outfile = FileDialog.Put("*.shp".AsFileName, "*.shp",
"Output Point Shapefile")
outFTab = FTab.MakeNew(outfile, point)
outIDfld = Field.Make("myID",#FIELD_SHORT,6,0)
outShapeFld = outFTab.FindField("Shape")
outFTab.AddFields({outIDfld})
for each rec in inFTab
av.ShowMsg("Creating point theme of nodes...")
av.SetStatus(((rec+1)/inNumRecs) * 100)
aPolyline = inFTab.ReturnValue(inShapeFld, rec)
for each polypiece in aPolyline.AsList
pt = polypiece.Get(0)
outPointList.Add(pt)
pt = polypiece.Get((polypiece.AsList.Count) - 1)
outPointList.Add(pt)
end
end
for each aPoint in outPointList
recnum = outFTab.AddRecord
outFTab.SetValue(outShapeFld, recnum, aPoint)
outFTab.SetValue(outIDfld, recnum, recnum)
end
outFTab.SetEditable(false)
av.ShowMsg("Done")
av.ClearStatus
newTheme = FTheme.Make(outFTab)
theView.AddTheme(newTheme)
newTheme.SetVisible(true)
'--- End of Script
Get help from ArcGIS experts
Download the Esri Support App