English

How To: Split a polygon using a line from a different theme

Summary

This article provides sample Avenue code that splits a polygon feature using a selected line from a different theme.

Procedure

  1. Open a new script window.

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

  2. Paste the following code into the new window:

    Code:
    theView = av.GetActiveDoc
    t = theView.GetThemes
    splitTheme = msgbox.choice(t,"","Choose the line theme with the selected line")

    theProjection = theView.GetProjection
    theFtab = splitTheme.GetFTab
    theShapeField = theFtab.FindField("Shape")

    thebit = theFtab.GetSelection

    for each x in thebit
    aShape = theFtab.ReturnValue(theShapeField, x)
    if (theProjection.IsNull) then
    aGraphic = GraphicShape.Make(aShape.ReturnProjected(theProjection))
    else
    aGraphic = GraphicShape.Make(aShape)
    end
    if (aShape.Is(Polygon)) then
    msgbox.info("You must choose a line theme","Warning")
    end
    end
    theTheme = theView.GetEditableTheme

    if (theTheme <> nil) then
    theTheme.GetFtab.BeginTransaction
    theField = theTheme.GetFTab.FindField("Shape")
    theType = theField.GetType
    if ((theType = #FIELD_SHAPEPOLY) or (theType = #FIELD_SHAPELINE)) then
    theTheme.Split(aShape)
    end
    theTheme.GetFtab.EndTransaction
    end
    av.GetProject.SetModified(true)

  3. Attach the script to a button on the View GUI.

    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. On the Customize dialog box, click the Type dropdown arrow and click View.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Type the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see "Customize dialog box" in ArcView Help.

  4. Open the view and make the polyline theme active.
  5. Select the line that will split the polygon.
  6. Make the polygon theme active and select Start Editing from the Theme menu.
  7. Click the new button.
  8. Select Stop Editing from the Theme menu.