Thank you for your help! I'm glad I was 90% of the way there. This works as intended now.
Original Message:
Sent: 10-23-2024 00:18
From: Jeff Mayer
Subject: Election Scripting for Electoral Map
"txtValue" is declared as an xpTextObject, but when you set the state color based on the text value, you need to reference the text itself, not the object, so txtValue.text = "R" instead of just txtValue = "R"
If txtValue.text = "R" Then quadState.SetMaterial(0, matRed) ' Set to red ElseIf txtValue.text = "B" Then quadState.SetMaterial(0, matBlue) ' Set to blue Else quadState.SetMaterial(0, matGrey) ' Default to grey End If
Not sure if you're opening this project manually or running it through a MOS workflow, but you may also need to change the Engine.GetMaterialByName methods to use Self.Project.GetMaterialByName. This way, if the project isn't active in the engine, the script will still be able to get the project materials associated with the scene, rather than looking for whatever project materials are associated with the active project. If this project is always going to be opened manually and be the active project in XPression, that designation shouldn't matter.
------------------------------
Jeff Mayer
Ross Video
Original Message:
Sent: 10-22-2024 21:41
From: Darren Johnson
Subject: Election Scripting for Electoral Map
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 colorsDim matBlue As xpMaterialDim matRed As xpMaterialDim matGrey As xpMaterialDim txtValue As xpTextObjectDim quadState As xpBaseObject' Initialize materialsEngine.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 statesFor 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 IfNext
------------------------------
Darren Johnson
Director
WFFT
------------------------------