sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🛣️ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Text , X , Y , Z import

    Scheduled Pinned Locked Moved Plugins
    23 Posts 4 Posters 1.4k Views 4 Watching
    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.
    • thomthomT Offline
      thomthom
      last edited by

      And what unit is the data in?

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • K Offline
        khallgren
        last edited by

        The unit is in millimeters.

        Regards Kristoffer

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          Try this... copy/paste code into a file called cptstxt.rb in Plugins.

          =begin
          To run type 'cptstxt' into the Ruby Console...
          =end
          require 'sketchup.rb'
          def cptstxt()
            model=Sketchup.active_model
            ents=model.active_entities
            layers=model.layers
            lay=layers.add("CPTS")
            vec=[1,1,1]## change this to alter text-location/leader-length
            file=UI.openpanel("Select the DAT File...","*.dat")
            return nil if not file
            model.start_operation("cpointstxt")
            text=IO.readlines(file)
            0.upto(text.length-1) do |i|
              line=text[i]
              line.strip! if line
          	line.chomp! if line
              data=line.split(",")
              next if not data[3]
              txt=data[0]
              x=data[1].to_f.mm
              y=data[2].to_f.mm
              z=data[3].to_f.mm
              pt=[x,y,z]
              cp=ents.add_cpoint(pt)
              cp.layer=lay
              tx=ents.add_text(txt,pt,vec)
              tx.layer=lay
            end#do
            model.commit_operation
          end
          ###
          

          TIG

          1 Reply Last reply Reply Quote 0
          • K Offline
            khallgren
            last edited by

            Hi
            I cant get it to work properly , I only get this error message from the ruby console, And I get some errors when starting up SketchUp

            cptstxt
            Error: #<NameError: (eval):894: undefined local variable or method `cptstxt' for main:Object>
            (eval):894

            Your script says " require 'sketchup.rb' "
            Does that mean that I have to copy/paste the file from the "tools" folder and into the "plugin" folder?

            Regards
            Kristoffer

            1 Reply Last reply Reply Quote 0
            • K Offline
              khallgren
              last edited by

              Hi , I managed to fix it
              It was just missing the "#" on the 3 first lines

              The plugin works perfect 😄 Thank you so mutch for your help .

              Best regards'
              Kristoffer

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                You need to 'select all' and copy/paste it - you must have missed something off ?
                The =begin...=end is the same as putting # at the start of each line - these are 'comments', not read by the Ruby interpreter. As there's only one line of 'comments' I could have omitted the =begin and =end lines completely and put a # at the start of the line of instructions - it'd been simpler! I just made the script from my own template that already has that format in it as multiple lines of comments/notes are often needed...
                Do not move sketchup.rb from the Tools folder. It loads automatically from there.
                It is good practice to add the line require 'sketchup.rb' at the start - most scripts need Sketchup's functions to run and will report an error if they load before it does; the ' require' waits for the specified file to load first... It's an instruction to the Ruby interpreter, not you !
                Glad it's working - did you notice that you can adjust the location of the text and leader length by playing with the vec=[1,1,1] numbers ?
                🤓

                TIG

                1 Reply Last reply Reply Quote 0
                • K Offline
                  khallgren
                  last edited by

                  Hi , Thanks for the Text and Leader tip

                  If I want to import Y, X ,Z rather than X,Y,Z

                  Can I just switch around the
                  x=data[1].to_f.mm
                  y=data[2].to_f.mm
                  z=data[3].to_f.mm
                  pt=[x,y,z]

                  To
                  y=data[1].to_f.mm
                  x=data[2].to_f.mm
                  z=data[3].to_f.mm
                  pt=[y,x,z]

                  Best Regards
                  Kristoffer

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    Yes.
                    The data[] order is the order typed in each line in the .dat file.
                    The original code assumed the first was the 'text', then x, y and z values, as in the .dat file supplied.
                    You can have the .dat file's entries in any order as long as the code's data[] values are adjusted accordingly - for example if the format were x,y,z,text then the values would all change around to suit with txt=data[3], and then x=data[0], y=data[1] and z=data[2]...
                    The code I gave you was only a basis for .dat file reading - it's very flexible...

                    PS: DON'T swap the point's values around use pt[x,y,z] always, no matter what the order they were read from the file ! 😒

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • K Offline
                      khallgren
                      last edited by

                      Hi again
                      When I try to import a file Negative Co-ordinates I cet an error
                      Is this an easy fix ?

                      See the example file

                      Best Regards
                      Kristoffer


                      Example_negative.txt

                      1 Reply Last reply Reply Quote 0
                      • TIGT Offline
                        TIG Moderator
                        last edited by

                        What's the error ? Please post examples...
                        The code x.to_f.mm should take the text 'string' of 'x' and make it into a 'number' [+/-] and then tell SUp it's in 'mm', not the default 'inches'?

                        TIG

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @khallgren said:

                          When I try to import a file Negative Co-ordinates I cet an error

                          Exactly what does the error say?

                          Thomas Thomassen — SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • K Offline
                            khallgren
                            last edited by

                            Hi , I tried to make my own file for testing and the negative co-ordinates workes fine, so the problem is not the negative co-ordinates. But when I export a file from my calculation program and try it import it I get an error, but the files sceems identical to me?

                            Here is the error i get

                            and the file is attached below

                            Error: #<Errno::ENOENT: C:/Programfiler/Google/Google SketchUp 7/Plugins/cptstxt.rb:14:in `readlines': No such file or directory - C:\Documents and Settings\krh\Skrivebord\BeregnetHøyderfile8.txt>
                            C:/Programfiler/Google/Google SketchUp 7/Plugins/cptstxt.rb:14

                            Best Regards
                            KRistoffer


                            BeregnetHøyderfile8.txt

                            1 Reply Last reply Reply Quote 0
                            • K Offline
                              khallgren
                              last edited by

                              I think I know what the problem is . Its the dicimales.... Its fine importing a file that says:

                              example: text,200.0,200.0,200.0

                              But when the file has a desimale value thats larger than 0 i get an error

                              example: text,200.5,200.5,200.5

                              Best regards
                              Kristoffer

                              1 Reply Last reply Reply Quote 0
                              • thomthomT Offline
                                thomthom
                                last edited by

                                Ah!
                                I know why that is - because you are Norwegian! Sketchup's ruby doesn't read files that has characters which isn't ASCII (A-Z). So our beloved æøå makes SU's file functions go belly up.

                                I struggled for ages with this some time ago. Found no good solution for that. You can work around be renaming your file.

                                Hilsen fra Bartehovedstaden! 😉

                                Thomas Thomassen — SketchUp Monkey & Coding addict
                                List of my plugins and link to the CookieWare fund

                                1 Reply Last reply Reply Quote 0
                                • thomthomT Offline
                                  thomthom
                                  last edited by

                                  @khallgren said:

                                  I think I know what the problem is . Its the dicimales.... Its fine importing a file that says:

                                  example: text,200.0,200.0,200.0

                                  But when the file has a desimale value thats larger than 0 i get an error

                                  example: text,200.5,200.5,200.5

                                  Best regards
                                  Kristoffer

                                  ?? With the same file you tried earlier? Or did you create a new test file with just ASCII chars in the file name & path?

                                  Thomas Thomassen — SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 Reply Last reply Reply Quote 0
                                  • TIGT Offline
                                    TIG Moderator
                                    last edited by

                                    As Thomthom said -
                                    It's an 'unrelated' error to the code itself... you have 'special characters' in the filepath - this always causes Ruby / Sketchup problems [it can be trapped form but it's a bit complex for this simple example code!].
                                    So please do it without the 'ø' etc in filename 'BeregnetHøyderfile8.txt' >>> 'BeregnetHoyderfile8.txt' ? it should then work !
                                    😒

                                    TIG

                                    1 Reply Last reply Reply Quote 0
                                    • Didier BurD Offline
                                      Didier Bur
                                      last edited by

                                      Hi,
                                      @Khallgren: I'm just about to modify my points cloud script to achieve what you want. Stay tuned....

                                      DB

                                      1 Reply Last reply Reply Quote 0
                                      • K Offline
                                        khallgren
                                        last edited by

                                        Hi , Oppps I missed that issue 😄
                                        Diddler Bur: It would be great if your point cloud importer had a "text" option
                                        Thanks for all your help 😄

                                        Berst regards "fra regn byen"
                                        Kristoffer

                                        1 Reply Last reply Reply Quote 0
                                        • 1
                                        • 2
                                        • 1 / 2
                                        • First post
                                          Last post
                                        Buy SketchPlus
                                        Buy SUbD
                                        Buy WrapR
                                        Buy eBook
                                        Buy Modelur
                                        Buy Vertex Tools
                                        Buy SketchCuisine
                                        Buy FormFonts

                                        Advertisement