Forum Discussion

RickMaranta's avatar
RickMaranta
Community Member
25 days ago
Solved

Accessing Text from a Text box using new API

Now that we have the new API, does anyone know how to access the actual text from a text box object?

I can currently do this by finding the textbox using the "data-acc-text" but this should be much simpler. I want to pass it into a variable using JavaScript. 

  • I did some digging. If you want to access the text from a storyline textbox object, you can use the object ID. Which in the DOM, is the "data-model-id" Once you search for that, you should be able to find the text box and get the text. Here is some script that will allow you to copy onscreen text into a variable dynamically.  Therea are things that this could be useful for. Once is to have offscreen text that you could feed to AI as a source of content. 

    setTimeout(() => {
      // Replace '6lfv6DK2C7k' with the actual data-model-id value
      const container = document.querySelector('[data-model-id="6lfv6DK2C7k"]');
      if (!container) return;
    
      // Then search for the <tspan> (or <text>) that actually contains your text
      const textElem = container.querySelector('text tspan');
      if (!textElem) return;
    
      const rawText = textElem.textContent.trim();
      console.log('Extracted text:', rawText);
    
      // If you want to set a Storyline variable:
      const player = GetPlayer();
      player.SetVar('myBox', rawText);
    }, 100);

     

1 Reply

  • RickMaranta's avatar
    RickMaranta
    Community Member

    I did some digging. If you want to access the text from a storyline textbox object, you can use the object ID. Which in the DOM, is the "data-model-id" Once you search for that, you should be able to find the text box and get the text. Here is some script that will allow you to copy onscreen text into a variable dynamically.  Therea are things that this could be useful for. Once is to have offscreen text that you could feed to AI as a source of content. 

    setTimeout(() => {
      // Replace '6lfv6DK2C7k' with the actual data-model-id value
      const container = document.querySelector('[data-model-id="6lfv6DK2C7k"]');
      if (!container) return;
    
      // Then search for the <tspan> (or <text>) that actually contains your text
      const textElem = container.querySelector('text tspan');
      if (!textElem) return;
    
      const rawText = textElem.textContent.trim();
      console.log('Extracted text:', rawText);
    
      // If you want to set a Storyline variable:
      const player = GetPlayer();
      player.SetVar('myBox', rawText);
    }, 100);