Graphics

 View Only
  • 1.  Scripting Material Change in Bar Graph

    Posted 05-27-2014 22:16

    Hi all,

    Recently made a Bar graph for a show that requires voting information to be displayed. I have been asked to make the leading bar (the bar with the highest value) a different colour.

    I have been searching the SDK, but am unsure on syntax. But currently don't have a scripting solution for this request.

    Does anyone have a solution or suggestion?

    Here is the script I am currently using to facilitate the Bar Graph:



    Dim cube1 as xpBaseObject

    Dim cube2 as xpBaseObject

    Dim cube3 as xpBaseObject

    Dim cube4 as xpBaseObject

    Dim cube5 as xpBaseObject

    Dim cube6 as xpBaseObject

    dim txtTitle1 as xpTextObject

    dim txtTitle2 as xpTextObject

    dim txtTitle3 as xpTextObject

    dim txtTitle4 as xpTextObject

    dim txtTitle5 as xpTextObject

    dim txtTitle6 as xpTextObject

    dim intTotal as integer

    dim intVal(6) as integer

    Self.GetObjectByName("Cube1",cube1)

    Self.GetObjectByName("Cube2",cube2)

    Self.GetObjectByName("Cube3",cube3)

    Self.GetObjectByName("Cube4",cube4)

    Self.GetObjectByName("Cube5",cube5)

    Self.GetObjectByName("Cube6",cube6)

    cube1.PivotY = cube1.height/-2

    cube2.PivotY = cube2.height/-2

    cube3.PivotY = cube3.height/-2

    cube4.PivotY = cube4.height/-2

    cube5.PivotY = cube5.height/-2

    cube6.PivotY = cube6.height/-2

    Self.GetObjectByName("Val1", txtTitle1)

    Self.GetObjectByName("Val2", txtTitle2)

    Self.GetObjectByName("Val3", txtTitle3)

    Self.GetObjectByName("Val4", txtTitle4)

    Self.GetObjectByName("Val5", txtTitle5)

    Self.GetObjectByName("Val6", txtTitle6)

    intVal(1) = cint (txtTitle1.text)

    intVal(2) = cint (txtTitle2.text)

    intVal(3) = cint (txtTitle3.text)

    intVal(4) = cint (txtTitle4.text)

    intVal(5) = cint (txtTitle5.text)

    intVal(6) = cint (txtTitle6.text)

    intTotal=intVal(1)+intVal(2)+intVal(3)+intVal(4)+intVal(5)+intVal(6)

    intval(0)=(intVal(0)/intTotal)*1250

    intval(1)=(intVal(1)/intTotal)*1250

    intval(2)=(intVal(2)/intTotal)*1250

    intval(3)=(intVal(3)/intTotal)*1250

    intval(4)=(intVal(4)/intTotal)*1250

    intval(5)=(intVal(5)/intTotal)*1250

    intval(6)=(intVal(6)/intTotal)*1250

    cube1.height = intVal(1)

    cube2.height = intVal(2)

    cube3.height = intVal(3)

    cube4.height = intVal(4)

    cube5.height = intVal(5)

    cube6.height = intVal(6)


  • 2.  RE: Scripting Material Change in Bar Graph

    Posted 05-28-2014 00:43
    Here you go.. I also simplified your script by using loops..

    This script gets a material called "Red", so make sure you create a material in the material manager..



    Dim cube as xpBaseObject

    dim txtTitle as xpTextObject

    dim intTotal as integer

    dim intVal as integer

    dim max as integer

    dim maxcube as integer

    dim i as integer

    dim j as integer

    dim material as xpMaterial

    intTotal = 0

    max = -9999

    for i = 1 to 6

    Self.GetObjectByName("Val" & i, txtTitle)

    intVal = CInt(txtTitle.text)

    intTotal = intTotal + intVal

    if intVal > max then

    max = intVal

    end if

    next

    for i = 1 to 6

    Self.GetObjectByName("Val" & i, txtTitle)

    Self.GetObjectByName("Cube" & i,cube)

    intVal = CInt(txtTitle.text)

    cube.height = 1250 * intVal / intTotal

    cube.PivotY = -cube.height/2

    ' Is this bar equal to the maximum?

    if intVal = max then

    ' Get a red material

    if engine.GetMaterialByName("Red", material) then

    ' Set all 6 faces of the cube

    for j = 0 to 5

    cube.SetMaterial(j, material)

    next

    end if

    end if

    next



    #XPression


  • 3.  RE: Scripting Material Change in Bar Graph

    Posted 05-28-2014 00:44
    Also, if you have multiple cubes that are tied for 1st place, they will all get set to red..

    #XPression


  • 4.  RE: Scripting Material Change in Bar Graph

    Posted 05-28-2014 00:52
    That's awesome!

    It works like a charm and you just taught me about loops. Thanks for letting me know about the result in a draw also.

    I really appreciate your help.

    Thank you

    #XPression