• Products
    • Isadora
    • Get It
    • ADD-ONS
    • IzzyCast
    • Get It
  • Forum
  • Help
  • Werkstatt
  • Newsletter
  • Impressum
  • Dsgvo
  • Press
  • Isadora
  • Get It
  • ADD-ONS
  • IzzyCast
  • Get It
  • Press
  • Dsgvo
  • Impressum
FORUM

Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags

    Use Javascript to select a line of Text

    How To... ?
    7
    22
    13126
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • DusX
      DusX Tech Staff last edited by

      I recently had a user trying to add quick titling to a show.
      He was using the old Text/ure actor (cpu only) and having some troubles.
      As a solution I put together this VERY short Javascript script.

      Inputs:

      1. TEXT (MultiLine from 'Text' actor, or other source)
      2. Integer (the line to output, Zero indexed)

      Output:

      1. the single line of Text you selected

      ================================================

      function main()
      {
      // arguments[0] = text in
      // arguments[1] = line to select

      var lines = arguments[0].split("\r");  // note "\n" is another possible option
      return lines[arguments[1]];
      }

      ================================================

      Troikatronix Technical Support

      • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
      • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
      • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

      Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

      DusX 1 Reply Last reply Reply Quote 4
      • bonemap
        bonemap Izzy Guru last edited by

        @dusx said:

        or other source

         And from an external text file?

        best wishes

        bonemap

        http://bonemap.com | Australia
        Izzy STD 4.2 | USB 3.6 | + Beta
        MBP 16” 2019 2.4 GHz Intel i9 64GB AMD Radeon Pro 5500 8 GB 4TB SSD | 14.5 Sonoma
        Mac Studio 2023 M2 Ultra 128GB | OSX 15.3 Sequoia
        A range of deployable older Macs

        mark_m 1 Reply Last reply Reply Quote 0
        • mark_m
          mark_m @bonemap last edited by

          @bonemap said:

          @dusx said:
          or other source
           And from an external text file?



           Yes, that'd be great. I'm sure you can whip that up in a trice can't your Ryan?!
          I've been using this excellent actor, but a Javascript solution seems more elegant...

          Intel NUC8i7HVK Hades Canyon VR Gaming NUC, i7-8809G w/ Radeon RX Vega M GH 4GB Graphics, 32GB RAM, 2 x NVMe SSD
          Gigabyte Aero 15 OLED XD. Intel Core i7-11800H, NVidia RTX3070, 32GB RAM 2 x NVMe SSD
          PC Specialist Desktop: i9-14900K, RTX4070Ti, 64GB RAM, Win11Pro
          www.natalieinsideout.com

          1 Reply Last reply Reply Quote 0
          • DusX
            DusX Tech Staff @DusX last edited by DusX

            And now from an external file

            I recently had a user trying to add quick titling to a show.
            He was using the old Text/ure actor (cpu only) and having some troubles.
            As a solution I put together this VERY short Javascript script.
            Inputs:
            1. Integer (the line to output, Zero indexed)
            Output:
            1. the single line of Text you selected
            ================================================
            function main(){


            // arguments[0] = line to select
            var txt = read ("file.txt");
            var lines = txt.split("\r");  // note "\n" is another possible option
            return lines[arguments[0]];
            }
            ================================================
            Oof course this is only reading the hard coded file name.
            Just use 2 inputs if you want theo pass in the filename

            My phone was making this difficult 😐 

            [EDIT] Addition (use dynamic text to load file):

            Inputs:

            1. Text file name or path (requires either a relative path, or absolute path)
            2. Integer (the line to output, Zero indexed)

            Output:

            1. the single line of Text you selected

            ================================================

            function main() 

            { 

            // arguments[0] = text file name or path

            // arguments[1] = line to select

            var txt = read (arguments[0]);

            var lines = txt.split("\r");  // note "\r\n" is another possible option, this may be operating system dependant

            return lines[arguments[1]]; 

            }

            ================================================

            Troikatronix Technical Support

            • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
            • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
            • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

            Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

            1 Reply Last reply Reply Quote 2
            • mark_m
              mark_m last edited by mark_m

              @DusX

              Thanks for that. Brilliant.
              But I'm having the oddest experience with this: Here's the Isadora test file I created:
              Javascript test file

              and the associated text file
              Which should go in the same directory as the Isadora file.

              Isadora loads the file fine, but the second and subsequent lines of the text are placed in a lower position on the stage than the first line.
              I've tried encoding in ANSI and in UTF-8 in case that's the issue, but there's no difference...
              Am sure it's me doing something wrong, but I'd be grateful if you could have a look and see if you can spot the problem.
              Cheers
              Mark





              Intel NUC8i7HVK Hades Canyon VR Gaming NUC, i7-8809G w/ Radeon RX Vega M GH 4GB Graphics, 32GB RAM, 2 x NVMe SSD
              Gigabyte Aero 15 OLED XD. Intel Core i7-11800H, NVidia RTX3070, 32GB RAM 2 x NVMe SSD
              PC Specialist Desktop: i9-14900K, RTX4070Ti, 64GB RAM, Win11Pro
              www.natalieinsideout.com

              DusX 1 Reply Last reply Reply Quote 0
              • DusX
                DusX Tech Staff @mark_m last edited by

                @mark_m

                I can dig in right now, but I did look at your txt file and your lines end with CR LF (opened notepad++ and set view / symbols to all)

                So I suggest changing the line break to use the \r\n option as listed in the comments.

                The split is probably removing the  \n and leaving the \r on the beginning of the next line.

                Troikatronix Technical Support

                • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                mark_m 1 Reply Last reply Reply Quote 0
                • mark_m
                  mark_m @DusX last edited by

                  @dusx

                  Yes, I see... (I mean I see the CR LF thing, I don't speak Javascript well enough to really understand). Anyhow, by making the first line blank - or to be precise containing nothing but a CRLF -  I can get a consistent placement of all the lines of text from line 2 onwards.
                  Thanks!
                  Mark (not...)




                  Intel NUC8i7HVK Hades Canyon VR Gaming NUC, i7-8809G w/ Radeon RX Vega M GH 4GB Graphics, 32GB RAM, 2 x NVMe SSD
                  Gigabyte Aero 15 OLED XD. Intel Core i7-11800H, NVidia RTX3070, 32GB RAM 2 x NVMe SSD
                  PC Specialist Desktop: i9-14900K, RTX4070Ti, 64GB RAM, Win11Pro
                  www.natalieinsideout.com

                  DusX 1 Reply Last reply Reply Quote 0
                  • DusX
                    DusX Tech Staff @mark_m last edited by

                    @mark_m

                    Does it not work as expected if you change the line:

                    var lines = txt.split("\r");

                    to 

                    var lines = txt.split("\r\n");

                    Troikatronix Technical Support

                    • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                    • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                    • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                    Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                    mark_m 1 Reply Last reply Reply Quote 1
                    • mark_m
                      mark_m @DusX last edited by

                      @dusx

                      Brilliant, Ryan, that did the trick.

                      Thanks!

                      Intel NUC8i7HVK Hades Canyon VR Gaming NUC, i7-8809G w/ Radeon RX Vega M GH 4GB Graphics, 32GB RAM, 2 x NVMe SSD
                      Gigabyte Aero 15 OLED XD. Intel Core i7-11800H, NVidia RTX3070, 32GB RAM 2 x NVMe SSD
                      PC Specialist Desktop: i9-14900K, RTX4070Ti, 64GB RAM, Win11Pro
                      www.natalieinsideout.com

                      1 Reply Last reply Reply Quote 1
                      • DusX
                        DusX Tech Staff last edited by

                        Performance Note: It may be preferred to load the text file once before the Main function (requires moving just the read() line to the top of the script).
                        This would stop the Javascript from issuing a read() File command everytime a line is requested.
                        This might be important for large files.
                        It will also cause refreshing the text only to occur on enterscene.

                        Troikatronix Technical Support

                        • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                        • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                        • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                        Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                        1 Reply Last reply Reply Quote 1
                        • eight
                          eight last edited by

                          There are two scenes in this file, having to do with the text. Please have a look.

                          https://www.dropbox.com/sh/2gw...

                          --8

                          Analysis: http://post.scriptum.ru | Synthesis: http://onewaytheater.us
                          Twitter: https://twitter.com/eight_io | Flickr: http://www.flickr.com/photos/eight_io/
                          Github: https://github.com/eighteight | MulchCam: https//mulchcam.com
                          MulchTune: https://itunes.apple.com/us/app/mulch-tune/id1070973465 | Augmented Theatre: https://augmentedtheatre.com

                          DusX 1 Reply Last reply Reply Quote 0
                          • DusX
                            DusX Tech Staff @eight last edited by

                            @eight
                            I took a look, it seems you are using a slight variation and its working well for you.

                            Troikatronix Technical Support

                            • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                            • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                            • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                            Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                            1 Reply Last reply Reply Quote 0
                            • T
                              TonariNoSeinfeld last edited by

                              I have a list of numbers in the Text actor. Sometimes Javascript does not output the correct number. I think it may be related to editing the Text, but I made sure the Javascript input is updated.

                              1 Reply Last reply Reply Quote 0
                              • D
                                DillTheKraut last edited by

                                Hello Guys,

                                I liked the Java Script solution a lot and wanted to modify it a bit.

                                I would like to split the text lines only at two or more line breaks or along empty lines.

                                I already tried a lot of combinations found at other Scripting forums like txt.split("\n\n"), txt.split("\n{2}"), txt.split("\\n\\n") and others. All of those solutions gave me errors while it worked for other people.

                                Is it maybe a limitation of the Java Version Izzy is using?

                                Does any of you maybe have a solution for this?

                                1 Reply Last reply Reply Quote 1
                                • Juriaan
                                  Juriaan Tech Staff last edited by

                                  Hi there @DillTheKraut,


                                  Any reason why you prefer the JavaScript option ? The Data Array actor has support for Text files since Izzy 2.6. Really nice actor that I use a lot for external file communication :)

                                  Isadora 3.1.1, Dell XPS 17 9710, Windows 10
                                  Interactive Performance Designer, Freelance Artist, Scenographer, Lighting Designer, TroikaTronix Community moderator
                                  Always in for chatting about interaction in space / performance design. Drop me an email at hello@juriaan.me

                                  D 1 Reply Last reply Reply Quote 2
                                  • D
                                    DillTheKraut @Juriaan last edited by

                                    @juriaan

                                    Yes, there is a reason. I try to read data from a pre defined text file. Named .edl files, containing cue data stretched sometimes over two lines, some times only one.

                                    As the data array needs specifically defined separation and works by single line only. It doesn't realy help.

                                    1 Reply Last reply Reply Quote 1
                                    • Juriaan
                                      Juriaan Tech Staff last edited by

                                      Okay, could you share the file that you wish to read. So that we can give you hand finding the right  way ;)

                                      Isadora 3.1.1, Dell XPS 17 9710, Windows 10
                                      Interactive Performance Designer, Freelance Artist, Scenographer, Lighting Designer, TroikaTronix Community moderator
                                      Always in for chatting about interaction in space / performance design. Drop me an email at hello@juriaan.me

                                      D 1 Reply Last reply Reply Quote 1
                                      • D
                                        DillTheKraut @Juriaan last edited by

                                        @juriaan

                                        I will, but I'm on not at my computer at the moment.

                                        But I as well would like to understand if the way I tried should be right, or if there are differences between java versions. But maybe there is something else wrong.

                                        DusX 1 Reply Last reply Reply Quote 1
                                        • DusX
                                          DusX Tech Staff @DillTheKraut last edited by DusX

                                          @dillthekraut

                                          It's not any difference between Javascript versions. It is likely that your text file is using additional line breaks.

                                          Opening it in a text editor like notepad++ will allow you to turn on viewing of invisible characters. Then you can edit the JS code to suite.

                                          It will likely be something like:  txt.split("\n\r")

                                          Troikatronix Technical Support

                                          • New Support Ticket Link: https://support.troikatronix.com/support/tickets/new
                                          • My Add-ons: https://troikatronix.com/add-ons/?u=dusx
                                          • Profession Services: https://support.troikatronix.com/support/solutions/articles/13000109444-professional-services

                                          Running: Win 11 64bit, i7, M.2 PCIe SSD's, 32gb DDR4, nVidia GTX 4070 | located in Ontario Canada.

                                          D 1 Reply Last reply Reply Quote 1
                                          • D
                                            DillTheKraut @DusX last edited by

                                            @dusx Thanks, though I was sure to have tried it already. Strange enough, I had following experience:

                                            As you see in the picture, notepad++ is showing all breaks are equally CR/LF. But in the Java actor single \n worked as well as single \r. But giving me every single line, including empty ones as separate Array Items.

                                            I thought to have tried \n\r with the same result (but probably did \r\n instead of \n\r). While trying it again after your post, it now gives me the exactly wanted result, filling the array items with combined Data lines ignoring empty ones. Interestingly it seems to keeps the break between the data lines. See the results in the pictures...

                                            Honestly I don't really understand, what's happening here!

                                            ----

                                            DusX 1 Reply Last reply Reply Quote 1
                                            • First post
                                              Last post