Graphics

 View Only
  • 1.  Load file by Index via Script - assistance needed

    Posted 10-05-2023 20:04

    Hi All,

    This is round two of building off the success of an earlier script, where I was able to assign a texture from a file of numbered image files. I'm trying to "level up" and have it import from a folder of randomly named images, but by the index from it's list location. This compiles, but something just isn't connecting to pull the image. I've been looking at it too long and would appreciate any assistance. It's under OnSetText in the text editor and typing in a URL triggers the Scene update:

    ' Declare variables and initialize as Nothing
    Dim path As xpTextObject
    path = Nothing

    Dim Quad As xpBaseObject
    Quad = Nothing

    ' Get the ItemIndex
    Dim ItemIndex As Integer
    ItemIndex = 1 ' Replace with your desired ItemIndex

    ' Establish a text object for the file path
    Scene.GetObjectByName("Source Folder", path)

    ' Get the image path from the TextObject
    Dim imagePath As String
    imagePath = path.Text

    ' Declare variables to cover all possible file extensions 
    Dim extName1, extName2, extName3 As String
    extName1 = ".jpg"
    extName2 = ".jpeg"
    extName3 = ".png"

    ' Get all files in the folder
    Dim fs As Object
    fs = CreateObject("Scripting.FileSystemObject")

    ' Declare folder here before using it
    Dim folder As Object
    folder = fs.GetFolder(imagePath)
    Dim files As Object
    files = folder.Files

    ' Create a Quad object
    Scene.GetObjectByName("Image2", Quad)

    ' Check if the ItemIndex is within bounds
    If ItemIndex >= 1 And ItemIndex <= files.Count Then
        ' Get the file at the specified index
        Dim file As Object
        file = files.Item(ItemIndex - 1) ' Adjust index to start from 0

        ' Get the file name and set the volatile texture files for the Quad object
        Dim fileName As String
        fileName = file.Name

        ' Set the volatile texture files for the Quad object, and applies regardless of file name extension.
        Self.GetParent(Quad)
        Quad.SetVolatileTextureFile(0, imagePath & "\" & fileName + extName1)
        Quad.SetVolatileTextureFile(0, imagePath & "\" & fileName + extName2)
        Quad.SetVolatileTextureFile(0, imagePath & "\" & fileName + extName3)
    Else

    End If



    ------------------------------
    Chris Jordan
    Graphic Artist in Charge
    NBCUniversal
    ------------------------------


  • 2.  RE: Load file by Index via Script - assistance needed

    Posted 10-06-2023 03:48

    At the end, if the last 1 fails doesn't it push out an image even if it succeeds earlier?



    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 3.  RE: Load file by Index via Script - assistance needed

    Posted 10-06-2023 12:42

    Hi Simon,

    It's interesting for sure, something is tripping it up somehow. The index number chosen for the folder file name isn't finding it's way to be associated with the "fileName" string. I can plug in the actual file name text and it maps to the quad, so now I'm working on finding the disconnect. Not sure if the issue is where folder and files are declared, or something within the If/Else.

    Chris



    ------------------------------
    Chris Jordan
    Graphic Artist in Charge
    NBCUniversal
    ------------------------------