Graphics

 View Only
  • 1.  Visual Logic or Scripting to hide a background quad

    Posted 10-26-2015 22:08
    I have an election results template with 4 Candidate result groups in the scene. Each group has a layer and template link for a candidate name, vote totals and percentage, as well as a quad box behind this text. An XML Datalinq source will be used to update the info.

    In some cases, there may only be 2 or 3 candidates and I don't want the empty quad boxes to display if there is no info in them. I am new to scripting and Visual Logic and this is probably very simple. How do a "hide" the 4th quad box that is beneath the info, if there is no info in the text layers in the 4th group?

    Thanks.


  • 2.  RE: Visual Logic or Scripting to hide a background quad

    Posted 10-27-2015 14:21
    I've done this by simply checking to see if there's a name in for the group, and if there isn't, turning off the visibility. This is done by scripting. In my following example, I'm assuming your name objects are called "Name Object 1" through "Name Object 4," and your groups are "Group Object 1" through 4. You can edit the script to change this accordingly.

    dim name as xpTextObject

    dim group as xpBaseObject

    dim i as Integer

    for i = 1 to 4 'if you need more or less, change your loop to be longer or shorter

    Self.GetObjectByName("Name Object " & i, name) 'this is looking for the text in the quotes & i - if you have a space after your words before numbers, you need to include that in the text

    Self.GetObjectByName("Group Object " & i, group) 'same thing, but for the group - using numbers is best when needing to script something like this

    'we're going to use the Len() function to find out the length of a string of text, in this case, the name.Text we found early

    'this script says if the length is greater than zero (there is text), make the group visible

    'else if the length is zero (no text), do not make the group visible

    if Len(name.Text)>0 then

    group.Visible=True

    elseif Len(name.Text)=0 then

    group.Visible=False

    end if

    next i


    #XPression


  • 3.  RE: Visual Logic or Scripting to hide a background quad

    Posted 10-27-2015 14:37
    You can also go about this through Visual Logic.

    1. Grab the "Text" block for the candidate's name and run it into the String block called "String Length".

    2. Run the output of "String Length" into the bottom green dot of the Logic block called "Greater Than" and set the base to 0.

    3. Run the output of "Greater Than" into the "Visible" block of the item you want to toggle on/off.

    This basically figures out the length of the word and checks to see if it's greater than 0 characters. The logic blocks can only output a 0 or 1 (think of it as no/yes, false/true). Visibility works the same way, 0=not visible, 1=visible. If you have a person's name in the text object, the number of characters is greater than 0 and the quad will become visible.

    Scripting and VL will both accomplish what you're looking for.

    #XPression


  • 4.  RE: Visual Logic or Scripting to hide a background quad

    Posted 10-27-2015 14:48
    You can directly connect the String Length property to the Visible property without using the Greater Than block.. If the length is zero (string is empty) that would set the Visible property to False; if the length is anything other than zero that would make the visibility true. This saves a little time and blocks..

    #XPression


  • 5.  RE: Visual Logic or Scripting to hide a background quad

    Posted 10-27-2015 18:34
    Thank you all. I was pretty close with the Visual Logic to begin with, I was missing the string length. Works great.

    #XPression