ARCVIEW 3.0 BUFFER BUTTON Buffer selected features. This routine is a rewrite of the sample script "buffer.ave", included with AV3.0 -- this rewrite saves the resulting buffer to a shapefile. ======================================================================= INSTALLING THE BUFFER BUTTON IN THE DEFAULT PROJECT Note: this script is not in the default.apr maintained at my Web page. 1) Begin a NEW ArcView 3.0 session. 2) Create a new script by double-clicking on the "Scripts" icon 3) Use "Properties..." under the "Script" menu to rename Script1 to View.Buffer 4) Paste the following text: '====================================================================== 'View.Buffer 'Buffers selected features to new theme TheView=av.getactivedoc theTheme=theView.getactivethemes.get(0) TheType=TheTheme.GetSrcName.getsubname theftab=theTheme.getftab thebitmap=theftab.getselection theShape=theFtab.findfield("Shape") '**** get buffer distance thedisplay=theview.getdisplay theunits=thedisplay.getunits if (thebitmap.count<1) then exit end 'Test if the Map Units have been set uses Distance units if they are set, 'otherwise uses distance units if (theunits=#UNITS_LINEAR_UNKNOWN) then msgbox.warning("Sorry no map units defined. Please define the map units in the View, Properties dialog.","Warning") exit end check=TRUE Distunits=TheDisplay.GetDistanceUnits if (distunits = #UNITS_LINEAR_UNKNOWN) then distunits=theunits check=FALSE end theunitname=distunits.asstring.astokens("_").get(2).lcase anum=(MsgBox.Input("Enter the buffer distance in "+theunitname+".","Buffer","100")) if (anum=NIL) then exit end abuffernum=anum.asnumber if (check=TRUE) then answer=Units.Convert(abuffernum, Distunits, TheUnits) abuffernum=answer end '**** get output file out_name = av.GetProject.MakeFileName("theme", "shp") out_name = FileDialog.Put(out_name, "*.shp", "Output Shapefile") if (out_name = nil) then exit end PShape = FTab.MakeNew(out_name,Polygon) fields = List.Make fields.Add(Field.Make("id",#FIELD_LONG,11,0)) PShape.AddFields(fields) '**** create buffer shape list av.showmsg("Buffering...") count=0 BuffList=List.Make for each x in theBitmap count=count+1 progress = (count/thebitmap.count) * 100 doMore = av.SetStatus( progress ) av.usewaitcursor anewshape=theftab.returnvalue(theshape, x) if (theview.getprojection<>"") then newshape=anewshape.returnprojected(theview.getprojection) else newshape=anewshape end abufferdist=abuffernum if (theview.getprojection<>"") then tmpbuffshp=newshape.returnbuffered(abufferdist) thebuffshp=tmpbuffshp.returnunprojected(theview.getprojection) else thebuffshp=newshape.returnbuffered(abufferdist) end BuffList.Add(thebuffshp) end '**** dissolve buffer shapes and write to FTab av.showmsg("Dissolving...") count=0 thewhole = BuffList.Get(0) for each ashape in BuffList count=count+1 progress = (count/BuffList.count) * 100 doMore = av.SetStatus( progress ) av.usewaitcursor thing1=ashape thewhole1=thewhole.returnunion(thing1) thewhole=thewhole1 end theID = 1 recno = PShape.AddRecord PShape.SetValue(PShape.FindField("id"),recno,theID) PShape.SetValue(PShape.FindField("shape"),recno,thewhole) '**** add buffer theme to a view if (MsgBox.YesNo("Add shapefile as theme to a view?", "Buffer Theme", true).Not) then exit end viewList = {} for each d in av.GetProject.GetDocs if (d.Is(View)) then viewList.Add( d ) end end addToView = MsgBox.ListAsString( viewList,"Add Theme to:", "Buffer Theme" ) if (addToView <> nil) then if (addToView = "") then addToView = View.Make addToView.GetWin.Open end mergeTheme = FTheme.Make( PShape ) addToView.AddTheme( mergeTheme ) ' Bring the View to the front... addToView.GetWin.Activate end av.clearmsg '====================================================================== 5) Create a new script, named View.Buffer.Update, with the following text: '====================================================================== 'View.Buffer.Update if (av.getactivedoc.getactivethemes.Count > 0) then Self.SetEnabled( (av.getactivedoc.getactivethemes.get(0).getftab.getselection.count > 0) and (av.getactivedoc.getdisplay.getunits <> #UNITS_LINEAR_UNKNOWN) ) else Self.SetEnabled(false) end '====================================================================== 6) Compile and close both scripts 7) Double-click the tool bar, choose "View" and "Buttons", and create a new button 8) Double-click "Click" and select View.Buffer 9) Double-click "Update" and select View.Buffer.Update 10) Double-click "Help" and enter: Buffer//Buffer Selected Features 11) Double-click "Icon" and select SelectBuffer 12) Click the "Make Default Button" and then close the Customize dialog box 13) EXIT ArcView (do not save changes to "Untitled") and you're done! ======================================================================= INSTALLING THE BUTTON IN A SPECIFIC PROJECT 1) Open the desired project and follow steps 2-11 above 2) Close the "Customizer" and save the project ======================================================================= USING THE BUFFER BUTTON 1) The view's map units must be defined. 2) Make the desired theme active. 3) Select the features to be buffered. 4) Click the buffer button. 5) Enter the buffer distance. 6) Specify the output shapefile. 7) You will be asked if you want to add the shapefile to a view; if so, you will be asked to specify which one. ======================================================================= Mark Cederholm plp@pierssen.com http://www.pierssen.com/PC/arcinfo.htm http://www.pierssen.com/arcview/arcview.htm