• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Error when using "split()"

Scheduled Pinned Locked Moved Developers' Forum
9 Posts 4 Posters 624 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.
  • B Offline
    bender
    last edited by 11 Jul 2008, 19:36

    I am reading a log file and need to fix the path, as in windows I get a "" and using this code I can convert it to "/" so that it is a recognizable path. I however get this error:

    Error Loading File tester.rb
    private method `split' called for nil:NilClass

    From this code:

    readLog(File.join(@logPath.split('\')))

    Note that I have no issues when using the split method through the ruby console. Am I missing some sort of header up to? (ie 'require'....) This is simply a String method.

    Any help on this would be greatly appreciated!

    Also, on another topic, can anyone link me to some helper on animations? I'm reading a log file and need to move a 3d object in relation to some specific coordinates, and don't really know how to "move" them.

    Thank you!!

    1 Reply Last reply Reply Quote 0
    • J Offline
      Jim
      last edited by 11 Jul 2008, 21:14

      bender, I've moved your post to the Ruby Forum so it will be seen by the Rubyists.

      Hi

      1 Reply Last reply Reply Quote 0
      • R Offline
        RickW
        last edited by 12 Jul 2008, 04:47

        It's not a problem with split(), but with value assignments: somewhere in your code, there's a problem assigning a value to "@logPath. Since @logPath is 'nil', then it isn't anything that can be acted upon.

        RickW
        [www.smustard.com](http://www.smustard.com)

        1 Reply Last reply Reply Quote 0
        • B Offline
          bender
          last edited by 14 Jul 2008, 15:39

          I see what you are saying. However, @logPath does have something only when the user chooses to open a file. So, essentially @logPath is the path that is recorded by the "open file" window, and then through the use of the "split()" and "join" functions, I change it so that it has the proper separators.

          So, I'd really only like to call the code readLog(File.join(@logPath.split('\'))) ONLY when @logPath is not nil. (ie. the user has chosen a file, hence @logPath has something in it).

          So, I had a while loop around that saying to keep checking until the user chooses a file, but sketchup freezes (it goes into an infinite loop). If it makes it any easier, I can paste some of the code.

          Hopefully someone understands the problem and can help me.
          Thank you

          1 Reply Last reply Reply Quote 0
          • R Offline
            RickW
            last edited by 14 Jul 2008, 16:00

            readLog(File.join(@logPath.split('\'))) if @logPath

            would do the trick, but I suspect you have a block of things to do if @logPath is valid, hence

            if @logPath
               readLog(File.join(@logPath.split('\\')))
               # other stuff here...
            end
            

            RickW
            [www.smustard.com](http://www.smustard.com)

            1 Reply Last reply Reply Quote 0
            • B Offline
              bender
              last edited by 14 Jul 2008, 16:59

              Thanks for the quick reply. That part of the code works now, as it does not crash anymore, however it does not solve the problem because:

              -when the file is actually loaded, it does not go "back" and check that if statement in order to execute that block of code.

              Upon startup, it goes through the script and obviously at that time @logPath is nil as nothing has yet been loaded into it, and so that if statement is not executed.
              But: Now, that sketchup has started up and everything is loaded, I now click on my open file button, choose a file to be opened (sample.txt for example) and once I click open, @logPath holds the path to that file. (ie, if I open the ruby console, and print it, it actually stores that path...which is good news, almost)

              But, the issue is here: Now, that @logPath actually HAS a value, I now want it to check the if statement, and execute that block of code. (since now @logPath is valid). But it does not do that! I do not know how the script is read and if I had a debugger I'd be able to see exactly where it is going. I am pasting that block of code to make it easier to see:

              def gui()
              plugins = Sketchup.find_support_file("Plugins")
              icon = File.join(plugins, "pictures", "log.jpg")
              icon2 = File.join(plugins, "pictures", "ma.jpg")
              icon3 = File.join(plugins, "pictures", "execute.jpg")
              tb = UI::Toolbar.new("CD++")
              log = UI::Command.new("Load log file") { @logPath = UI.openpanel("Open Log File")}
              ###(the above line is the one I am referring to...once I open a file, @logPath
              ### holds the path, and I expect it then to check the condition below here
              if @logPath
              x = File.join(@logPath.split('\'))
              readLog(File.join(@logPath.split('\')))
              end
              log.large_icon = icon
              #File.join(@logPath.split('\'))
              #ma = UI::Command.new("Load MA file") { maPath = UI.openpanel("Open Ma File")}

              #ma.large_icon = icon2
              #execute= UI::Command.new("Execute event") {UI.messagebox("This will execute")}
              #execute.large_icon = icon3
              tb.add_item(log)
              #tb.add_item(ma)
              #tb.add_item(execute)
              tb.show
              end

              1 Reply Last reply Reply Quote 0
              • R Offline
                RickW
                last edited by 14 Jul 2008, 22:07

                you need a few more def's and wrap it all up in a class.

                
                class MyClass #replace with your preferred name
                
                def gui()
                  #...code
                  log = UI;;Command.new("Load log file") { load_log_file() }
                  #...code
                end
                
                def load_log_file()
                  @logPath = UI.openpanel("Open Log File")
                  if @logPath
                    x = File.join(@logPath.split('\\'))
                    readLog(File.join(@logPath.split('\\')))
                  end
                end
                
                #... other defs
                
                end #class MyClass
                
                

                RickW
                [www.smustard.com](http://www.smustard.com)

                1 Reply Last reply Reply Quote 0
                • T Offline
                  todd burch
                  last edited by 16 Jul 2008, 02:01

                  If the character you are looking for is the platform dependent file separator character, you could use this to make your code portable:

                  
                  readLog(File.join(@logPath.split(File;;Separator)))
                  
                  

                  Todd

                  1 Reply Last reply Reply Quote 0
                  • B Offline
                    bender
                    last edited by 16 Jul 2008, 17:31

                    Thanks for the replies everyone.

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

                    Advertisement