' ************************************************************ ' Explode to new file.ave ' Explodes multipart polygons, and writes output to new file. ' ' Modified by Tim Thomas on 12/6/01 ' ' Based on ' EXPLODE.AVE, which was a modification of ' part of EDTools. Modified slightly by Tim Thomas. ' ET.Explode ' Explode selected feature(s) ' ************************************************************ theView = av.GetActiveDoc theFTab = theView.GetActiveThemes.Get(0).GetFTab numRecs = theFTab.GetNumRecords shapeField = theFTab.FindField("Shape") ' ********************************************************** ' Create a new shapefile to hold the exploded shapes ' ********************************************************** ' Shows message in message bar av.ShowMsg("Creating exploded file") ' Creates file FTabFN = theFTab.GetSrcName.GetFileName baseString = FTabFN.GetBaseName extString = FTabFN.GetExtension newString = FTabFN.AsString.Substitute(baseString,"") new2String = baseString.Substitute(extString,"shp") newFTabFN = FileDialog.Put( (newString + "explode " + new2String).AsFileName, "*.shp","Shapefile name") newFTab = FTab.MakeNew(newFTabFN,Polygon) ' ********************************************************** ' Clone fields for newFTab ' ********************************************************** newshapeField = newFTab.FindField("Shape") inFields = theFTab.GetFields newFields = List.Make for each f in inFields if (f.GetName <> "shape") then newFields.Add(f.Clone) end end newFTab.AddFields(newFields) ' ********************************************************** ' Adding records to newFTab ' ********************************************************** av.ShowMsg("Exploding multi-part polygons") for each recnum in 0..(numRecs-1) theShape = theFTab.ReturnValue(shapeField,recnum) thePolyList = theShape.Explode for each aPoly in thePolyList rec = newFTab.AddRecord newFTab.SetValue ( newshapeField, rec, aPoly ) for each fld in theFTab.GetFields fldName = fld.GetName if (fldName <> "shape") then newfld = newFTab.FindField(fldName) val = theFTab.ReturnValue(fld,recnum) newFTab.SetValue(newfld,rec,val) end end end av.SetStatus(100*(recnum+1)/numrecs) end ' Clears message in message bar av.ClearMsg ' Turns off editing in the FTab newFTab.SetEditable(false) newFTheme = FTheme.Make ( newFTab ) theView.AddTheme ( newFTheme ) ' Removes garbage objects av.PurgeObjects