English

How To: Use the SetAttrUpdateRules request

Summary

The following example shows how to use the SettAttrUpdateRules request.

Procedure

  • You can set up the attribute updating rules through the AttrUpdate class and its AttrSingle and AttrRange subclasses:

    1. Make a 'rule' for each field in the theme's ftab using attrSingle.Make or attrRange.Make, depending on which type of field it is.

    Code:
    attrSingle.Make(anFTab,aField,aUnionRuleEnum,aSplitRuleEnum)


    Code:
    attrRange.Make(anFTab,aField,PairedField,aRangeTypeEnum)

    2. Set the theme's attribute rules using these rules with:

    Code:
    anFTheme.SetAttrUpdateRules(Rules)

    where Rules is a list of the rules you just made for the fields.

    Refer to the classes help for more information regarding these classes.

  • The following code creates a rule for each of the fields in the FTab and then passes these rules to the fTheme. The code assumes a view named View1 that contains states.shp. You can modify this code to use any view and theme.

    1. Open a new script window.

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



    2. Copy he code into the script window.
    Code:
    theView = av.FindDoc("View1")
    theTheme = theView.FindTheme("States.shp")
    theFTab = theTheme.GetFTab

    '-- Create the rule list
    theRuleList = {}

    '-- Get the list of fields and loop through the list
    For Each f in theFtab.GetFields
    '-- Check for an Area field
    If (f.AsString.Contains("area")) then
    r = AttrSingle.Make(theFTab, f, #ATTR_UNIONRULE_SHAPEAREA, #ATTR_SPLITRULE_SHAPEAREA)
    theRuleList.Add(r)
    '-- Set the rules for all string fields
    ElseIf (f.GetType = #FIELD_CHAR) then
    r = AttrSingle.Make(theFTab, f, #ATTR_UNIONRULE_BLANK, #ATTR_SPLITRULE_COPY)
    theRuleList.Add(r)
    '-- Set the rules for all date fields
    ElseIf (f.GetType = #FIELD_DATE) then
    r = AttrSingle.Make(theFTab, f, #ATTR_UNIONRULE_COPY, #ATTR_SPLITRULE_COPY)
    theRuleList.Add(r)
    '-- Set the rules for all number fields
    Else
    r = AttrSingle.Make(theFTab, f, #ATTR_UNIONRULE_ADD, #ATTR_SPLITRULE_PROPORTION)
    theRuleList.Add(r)
    End
    End

    theTheme.SetAttrUpdateRules(theRuleList)

    3. Click the Compile button.
    [O-Image] Script compile button

    4. Click the Run button.
    [O-Image] Run compiled script button
    For information on attribute updating, see the online Help > Index tab > themes > attribute updating.