Graphics

 View Only
  • 1.  Visual Logic and CSV strings

    Posted 09-16-2018 22:50
    So, through datalinq I have a rather long string of comma separated values.

    Ex: 235,125,895,-245,85,-4,56

    So as you see, I dont know if there are 1 digit, or 4 (-245). In javascript this would be a simple split() and Split by commas. But I figure there must be a way to do this in XPression VL?

    How do I get each individual value from the CSVs?


  • 2.  RE: Visual Logic and CSV strings

    Posted 09-17-2018 13:08
    This would be better in script than in VL. The scripting engine (vbscript) has a split function also.

    https://www.w3schools.com/asp/func_split.asp

    #XPression


  • 3.  RE: Visual Logic and CSV strings

    Posted 09-17-2018 20:36
    @bford So... I completly get why you would recommend VBScript...
    However I have no idea where to even begin, and quite honestly, the examples in the Xpression SDK documentation are horrible. They are waaaaaay more advanced than for ayone at a beginner level even begin to fathom what they do...

    I've kinda figured what I need to do down into a few steps, but honeslty, I have no friggin clue as to how I would do this in VBScript and Xpression... [LIST=1]
  • Get and define the string value property from a text object as a variable (let's say x).
  • Split the X on every , sign in order to get the different values...
  • Itterate through each and every value and give the first two (0,1) as X and Y position of Quad 1. Next two (2,3) as X and Y position of Quad 2. Next two (4,5) as X and Y position of Quad 3, so on and so forth...
  • That's about as simple as I can dumb it down... And if this was in JavaScript, I'd be done in less than 30 min... VBScript... I dont even know how to define a variable man, much less how to grab the string value from a text object... Hell, I dont even know/understand where to put this script? Do I put it in the Global Methods script? Do I put it in the text object that holds the string? And in that case? Do I put it in the OnSetText? OnAddText? OnSetLine? All I ever get when I try to get anywhere seems to be "declaration expected"? Appereantly missing something, or tried to put a simple script somewhere it wasnt supposed to be?

    Plus, I need to teach this to students, that doesnt even know what a variable is... Any more pointers?
    #XPression


  • 4.  RE: Visual Logic and CSV strings

    Posted 09-18-2018 03:49
    Put this script in OnSetText of the text object that contains your comma separated coordinates. The script will run anytime that text object data changes (not in layout mode; only in sequencer or via datalinq). The script assumes you have a bunch of precreated hidden Spheres in the scene named Sphere1 through SphereX. (In the preference menu, enable debug monitor for scripting, and restart XPression, if it is not already enabled).

    Hope this helps.

    dim sphere as xpSphereObject
    dim values as array
    dim str as string
    dim X as string
    dim y as string
    dim i as integer
    dim index as integer

    ' Split the comma separated string
    values = split(text,",")

    engine.DebugMessage("Found " & UBound(values) & " items in comma string", 2)

    index = 0
    ' Loop over all comma separated elements of array
    for i = 0 to UBound(values)-1

    ' Retrieve object names SphereX from scene
    if scene.GetObjectByName("Sphere" & (I+1), sphere) then
    ' Fetch the two coordinates from array elements
    x = values(index)
    y = values(index + 1)

    ' Convert strings to floating point and assign to object X,Y positions
    sphere.PosX = CDbl(x)
    sphere.PosY = CDbl(y)

    ' make the sphere visible (we set them all hidden in scene by default)
    sphere.visible = true

    engine.DebugMessage("Sphere" & (i+1) & " set to " & X & " " & y,2)

    ' advance to the next items in array
    index = index + 2
    end if

    next


    #XPression


  • 5.  RE: Visual Logic and CSV strings

    Posted 09-19-2018 13:20
    @bford REALLY appreciate it!
    Now in an example like this, is there any way to change this from a Sphere to position a group instead?

    I've looked through the Xpression SDK Help, but I cannot find how to define a group object?
    I can only find SceneGroup and Sequencer group, but not the group object in a scene?
    #XPression


  • 6.  RE: Visual Logic and CSV strings

    Posted 09-19-2018 13:35
    All objects (including groups) inherit from xpBaseObject. So you can define it as xpBaseObject. Even in my above example of using spheres, I could have defined it as xpBaseObject and it would still work for Spheres (since they too inherit from xpBaseObject). The xpBaseObject contains all the transform properties (PosX, PosY, RotX, ScaleZ, etc).

    There are no specific properties that exist only for a group object, and that is why there is no subclass called xpGroupObject.



    #XPression


  • 7.  RE: Visual Logic and CSV strings

    Posted 09-19-2018 17:48
    AHA! Ok... So.. change it do "dim player as xpBaseObject"... change the occurances of "sphere" in the code to "player", and look for the different groups now named "player#".
    Tested, aaaaaand, it works! Thanks man! I should definetly learn more of VBScript... But I just dont get it. Or, I "get" it, but I need to find some real inspiration for learning it...
    #XPression