Hello,
I am working on making a electoral map for the upcoming elections. I was hoping to have a script handle the coloring of the individual states. I have come up with a code that Xpression can compile but doesn't seem to change anything. I want the script to go through all of the text objects with the state labels and return the value (eg. 'R' or 'B') and then change the corresponding state quad that color. Thanks for any help or insight!
' Declare materials for colors
Dim matBlue As xpMaterial
Dim matRed As xpMaterial
Dim matGrey As xpMaterial
Dim txtValue As xpTextObject
Dim quadState As xpBaseObject
' Initialize materials
Engine.GetMaterialByName("Election Blue", matBlue)
Engine.GetMaterialByName("Election Red", matRed)
Engine.GetMaterialByName("Grey Box", matGrey)
' Initialize the state list (53 states including DC and special cases)
Dim stateList() As String = {"ALABAMA", "ALASKA", "ARIZONA", "ARKANSAS", "CALIFORNIA", "COLORADO", "CONNECTICUT", "DELAWARE", _
"FLORIDA", "GEORGIA", "HAWAII", "IDAHO", "ILLINOIS", "INDIANA", "IOWA", "KANSAS", "KENTUCKY", _
"LOUISIANA", "MAINE 1", "MAINE 2", "MARYLAND", "MASSACHUSETTS", "MICHIGAN", "MINNESOTA", _
"MISSISSIPPI", "MISSOURI", "MONTANA", "NEBRASKA 1", "NEBRASKA 2", "NEVADA", "NEW HAMPSHIRE", _
"NEW JERSEY", "NEW MEXICO", "NEW YORK", "NORTH CAROLINA", "NORTH DAKOTA", "OHIO", "OKLAHOMA", _
"OREGON", "PENNSYLVANIA", "RHODE ISLAND", "SOUTH CAROLINA", "SOUTH DAKOTA", "TENNESSEE", "TEXAS", _
"UTAH", "VERMONT", "VIRGINIA", "WASHINGTON", "WASHINGTON DC", "WEST VIRGINIA", "WISCONSIN", "WYOMING"}
' Loop through all 53 states
For Each stateName As String In stateList
' Get the text object
Self.GetObjectByName(stateName, txtValue)
' Get the state shape
Self.GetObjectByName(stateName & " QUAD", quadState)
' Set the state color based on the text value
If txtValue = "R" Then
quadState.SetMaterial(0, matRed) ' Set to red
ElseIf txtValue = "B" Then
quadState.SetMaterial(0, matBlue) ' Set to blue
Else
quadState.SetMaterial(0, matGrey) ' Default to grey
End If
Next
------------------------------
Darren Johnson
Director
WFFT
------------------------------