Graphics

 View Only
Expand all | Collapse all

XPression - Scripting positions

  • 1.  XPression - Scripting positions

    Posted 08-04-2015 19:20
    I have 2 text objects ([I]a,b[/I] for this purpose). I have the position of [I]a[/I] set and need to position [I]b[/I] based off the x-pos of [I]a[/I]. Is there a way to script like b.xpos=a.xpos+200?


  • 2.  RE: XPression - Scripting positions

    Posted 08-04-2015 21:17
    Yes, that is very easy with Visual Logic. Take a look at the visual logic tutorial on the XPression U section of the website. (It is also very similar to the VL screenshot I posted yesterday in response to a different question).

    #XPression


  • 3.  RE: XPression - Scripting positions

    Posted 08-05-2015 14:46
    This is also quite easy to do with scripting.

    `dim obja as xpBaseObject

    dim objb as xpBaseObject

    Self.GetObjectByName("Object a", obja)

    Self.GetObjectByName("Object b", objb)

    objb.PosX=(obja.PosX+200)`

    #XPression


  • 4.  RE: XPression - Scripting positions

    Posted 08-05-2015 14:58
    Thanks Dan. That's what I was looking for. Where would I put the script though? On the settext script? I have lots of programming knowledge and was wondering if this script is based off of any languages?

    #XPression


  • 5.  RE: XPression - Scripting positions

    Posted 08-05-2015 15:24
    It's mostly Visual Basic, as far as I can tell.

    #XPression


  • 6.  RE: XPression - Scripting positions

    Posted 08-05-2015 15:25
    Oh, and to answer your other question as to where to put it:

    On the scene itself for this script. Right click on the scene object and Edit Scene Scripts to get there.

    #XPression


  • 7.  RE: XPression - Scripting positions

    Posted 08-05-2015 15:29
    The advantage to visual logic in this case is the objects will always stay locked together even if the parent is animated. Using scripting, if it is in the OnOnline script it only sets the position once when the scene goes on air. You could put it in the OnRender script to update it every field but that is far more performance intensive than using visual logic. I'm not trying to dissuade you from using scripting, but I feel it's important to understand the use of VL as well as it is hugely powerful as well.

    #XPression


  • 8.  RE: XPression - Scripting positions

    Posted 08-05-2015 17:03
    I would like to second Brian in this.

    I'm used to use the API for just about anything, but recently I started using VL to do exactly what you are trying to do.

    In my case I was building some voting graphics with bars moving up and down with a textfield attached to the bar that had to move along with the bar and the value that needed to be updated depending on the scale of the bar. Through the API was very difficult to achieve, using VL everything went perfectly fine.

    The only downside, if I may add, is that some functions are not accessible inside VL. For example to get the textwidth of a textfield. Another remark I have is that when you copy a VL-block to use on a second element, that you have to drag all of the properties back in the field and make the connections again. It would be a lot easier if you could make a copy and then change the object but keeping the same property. But maybe Brian can have the guys take a look at that ;-)

    In my case I had 4 bars to animate with 4 different textfields, so I could copy the logic, but I had to replace the element-related blocks and make the connections again. But other than that, I'm a fan!



    #XPression


  • 9.  RE: XPression - Scripting positions

    Posted 08-05-2015 17:09
    Hi Kenneth, I haven't double checked but isn't there a bounding box width property for the text objects? Or is it something different you need?

    #XPression


  • 10.  RE: XPression - Scripting positions

    Posted 08-05-2015 17:14
    Well in my case I needed to determine an offset to my bar so that my textobject always stays inside the bar. TO determine that offset I needed the width of "0% ", but without actually putting it in the textfield.

    In the api there's a function called xpTextObject.getTextWidth("string to determine the width of") and that gets you the width without actually putting it in the textfield. So that's why in this case, I checked it before and put it in as a fixed value. In this case the 62. I do understand that it might be difficult to put all of the API-functionality in the VL, but maybe it might be an idea to add a script-block? That way you can still use scripting inside VL, and you can do virtually anything?

    Cheers,

    Kenneth

    #XPression


  • 11.  RE: XPression - Scripting positions

    Posted 08-05-2015 17:16
    Thanks for clarifying, we will think about approaches that could be taken.

    #XPression


  • 12.  RE: XPression - Scripting positions

    Posted 08-05-2015 17:18
    No problem!

    #XPression