HOW TO

Buffer only selected graphics

Last Published: April 25, 2020

Summary

The following sample script buffers only selected graphics in a view.

Procedure



  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.


  2. Copy the following code into the script window.
    Code:
    ' -------------------------- BUFFER_GRAPHICS.AVE --------------------------
    ' In order to run, this script requires at least one selected graphic in
    ' the View. The script will not buffer features in an FTheme; only
    ' graphics in the View are buffered. If you need to buffer features in an
    ' FTheme (ie. shapefiles, coverages, CAD drawings, SDE layers, VPF data,
    ' etc..) then use the original sample script, buffer.ave, that comes with
    ' the ArcView product in the //esri/av_gis30/arcview/samples/scripts
    ' directory.
    '
    ' This script should be attached to a Button or Menu Choice to the View GUI.
    '
    '
    TheView=av.getactivedoc
    thegraphicx = theView.getGraphics
    thegraphics=theview.getgraphics.GetSelected
    if (thegraphics.count = 0) then
    Msgbox.Warning("You don't have any graphics selected!",
    "Terminating script")
    return nil
    end

    alistofgraphics={}

    thedisplay=theview.getdisplay
    theunits=thedisplay.getunits

    '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(
    "No map units defined. Set the map units in the View, Properties dialog.",
    "Warning")
    return nil
    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+
    ". Use negative numbers for"+
    " 'inside' buffers (for polygons only).","Buffer","100"))

    if (anum=NIL) then return nil end
    abuffernum=anum.asnumber

    if (check=TRUE) then
    answer=Units.Convert(abuffernum, Distunits, TheUnits)
    abuffernum=answer
    end

    for each x in thegraphics
    av.usewaitcursor
    anewgraphic = x.getshape
    if (theview.getprojection.IsNull.Not) then
    newgraphic=anewgraphic.returnprojected(theview.getprojection)
    else
    newgraphic=anewgraphic
    end
    abufferdist=abuffernum
    if ((newgraphic.Is(Polygon)) and (abufferdist < 0)) then
    thebuffshptd=newgraphic.asPolyLine.returnbuffered(abufferdist)
    thebuffshptd2=newgraphic.ReturnIntersection(thebuffshptd)
    thebuffshp=newgraphic.ReturnDifference(thebuffshptd2)
    thebuffshp=thebuffshp.asPolygon
    else
    abufferdist=abufferdist.abs
    thebuffshp=newgraphic.returnbuffered(abufferdist)
    end
    thebuffshp=newgraphic.returnbuffered(abufferdist)
    alistofgraphics.add(thebuffshp)
    end

    if (alistofgraphics.count>1) then
    yn=MsgBox.YesNo("Do you want to disolve the adjoining buffers?",
    "Disolve?",TRUE)
    if (yn=FALSE) then
    for each agraphic in alistofgraphics
    av.usewaitcursor
    newg=graphicshape.make(agraphic)
    theGraphicx.addbatch(newg)
    end
    theGraphicx.endbatch
    return nil
    end
    else
    for each agraphic in alistofgraphics
    newg=graphicshape.make(agraphic)
    theGraphicx.add(newg)
    end
    return nil
    end

    thewhole=alistofgraphics.get(0)
    for each agraphic in alistofgraphics
    av.usewaitcursor
    thing1=agraphic
    thewhole1=thewhole.returnunion(thing1)
    thewhole=thewhole1
    end

    newg=graphicshape.make(thewhole1)
    theGraphicx.add(newg)
    av.getproject.setmodified(true)
    ' ----------------------------------------------------------------------
    '
    'Notes:
    '
    '============================DISCLAIMER================================
    'You may use, copy, modify, merge, distribute, alter, reproduce and/or
    'create derivative works of this Avenue script for your own internal
    'use. All rights not specifically granted herein are reserved to ESRI.
    '
    'THIS AVENUE SCRIPT IS PROVIDED "AS-IS" WITHOUT WARRANTY OF ANY KIND,
    'EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    'WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
    'WITH RESPECT TO THE AVENUE SCRIPT.
    '
    'ESRI shall not be liable for any damages under any theory of law
    'related to your use of this Avenue script, even if ESRI is advised of
    'the possibilites of such damage.
    'This Avenue script is not supported by ESRI.
    '

  3. Compile the script.
    [O-Image] Script compile button
  4. Make the view the active document.
  5. Run the script.
    [O-Image] Run compiled script button

Article ID:000004713

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic