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

Upgrading plugins to Ruby 2.0 for SketchUp 2014

Scheduled Pinned Locked Moved Developers' Forum
43 Posts 7 Posters 7.2k Views
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.
  • M Offline
    marksup
    last edited by 3 Mar 2014, 14:43

    Upgrade addition...
    Hash-array indexhas been replaced by key...
    key = ( Sketchup.version.to_i > 13 ) ? hash-array.key(value) : hash-array.index(value)

    re: Encoding...
    I have tried notepad++ Encoding convert to UTF-8 without BOM but now get...
    Error: #<Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT>

    Also, what might a (newly supported) unicode string look like?!

    1 Reply Last reply Reply Quote 0
    • T Offline
      TIG Moderator
      last edited by 3 Mar 2014, 14:47

      Once you have converted your script file to UFT8-without-BOM and saved [don't just view it with that encoding - it needs converting!]... then you need to replace earlier special characters [if any] in it that are no longer compatible.
      Simply retype the desired text and it should encode properly e.g. m²

      TIG

      1 Reply Last reply Reply Quote 0
      • T Offline
        tt_su
        last edited by 3 Mar 2014, 15:46

        @marksup said:

        Upgrade addition...
        Hash-array indexhas been replaced by key...
        key = ( Sketchup.version.to_i > 13 ) ? hash-array.key(value) : hash-array.index(value)

        Easier to just use key as that works on both versions. Less code branching.

        @marksup said:

        re: Encoding...
        I have tried notepad++ Encoding convert to UTF-8 without BOM but now get...
        Error: #<Encoding::CompatibilityError: incompatible character encodings: UTF-8 and ASCII-8BIT>

        Can you provide context around this error.

        @marksup said:

        Also, what might a (newly supported) unicode string look like?!

        It should look like anything different, but under the hood, all characters that is outside the ASCII range (0-127) will be multi-byte characters.

        1 Reply Last reply Reply Quote 0
        • M Offline
          marksup
          last edited by 3 Mar 2014, 16:46

          Hi TT,
          Are you sure about key (and not key?) being valid previously...
          ha = {"A"=>"ABC"}
          ha.key("ABC")
          Error: #<NoMethodError: undefined method `key' for {"A"=>"ABC"}:Hash>
          (eval)

          1 Reply Last reply Reply Quote 0
          • T Offline
            tt_su
            last edited by 3 Mar 2014, 17:06

            @marksup said:

            Hi TT,
            Are you sure about key (and not key?) being valid previously...
            ha = {"A"=>"ABC"}
            ha.key("ABC")
            Error: #<NoMethodError: undefined method `key' for {"A"=>"ABC"}:Hash>
            (eval)

            Ah! My bad, I misread that. I stand corrected.

            1 Reply Last reply Reply Quote 0
            • B Offline
              Brighter3D
              last edited by 4 Mar 2014, 12:43

              Win32API.so seems to no longer works on SU2014, instead we should use build in Win32API.rb.

              When passing
              Sketchup.active_model.skpdoc
              pointer,
              I've got error:

              Error: #<TypeError: no implicit conversion of Fixnum into String>
              C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:23:in pack' C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:23:in block in call'
              C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:22:in each' C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:22:in each_with_index'
              C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:22:in call' C:/Users/l/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/BrighterSU/BrighterSU.rb:68:in mydll_render'
              C:/Users/l/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/BrighterSU/BrighterSU.rb:248:in block in InitToolbar' -e:1:in call'

              funciton definition:
              BRrender = Win32API.new(mydll,"RenderScene",["P","P","I","I","I"],"I")

              function call:
              BRrender.call(Sketchup.active_model.skpdoc,Sketchup.active_model.path,width.to_i,height.to_i,nFromSett.to_i)

              Is it because of SU 64bit version?
              Does anyone have similar problem or anyone succeed to pass
              Sketchup.active_model.skpdoc pointer into c++ dll with SU2014?

              1 Reply Last reply Reply Quote 0
              • T Offline
                tt_su
                last edited by 4 Mar 2014, 13:17

                @brighter3d said:

                When passing
                Sketchup.active_model.skpdoc
                pointer,
                I've got error:

                Error: #<TypeError: no implicit conversion of Fixnum into String>
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:23:in pack' C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:23:in block in call'
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:22:in each' C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:22:in each_with_index'
                C:/Program Files (x86)/SketchUp/SketchUp 2014/Tools/RubyStdLib/Win32API.rb:22:in call' C:/Users/l/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/BrighterSU/BrighterSU.rb:68:in mydll_render'
                C:/Users/l/AppData/Roaming/SketchUp/SketchUp 2014/SketchUp/Plugins/BrighterSU/BrighterSU.rb:248:in block in InitToolbar' -e:1:in call'

                funciton definition:
                BRrender = Win32API.new(mydll,"RenderScene",["P","P","I","I","I"],"I")

                function call:
                BRrender.call(Sketchup.active_model.skpdoc,Sketchup.active_model.path,width.to_i,height.to_i,nFromSett.to_i)

                Is it because of SU 64bit version?
                Does anyone have similar problem or anyone succeed to pass
                Sketchup.active_model.skpdoc pointer into c++ dll with SU2014?

                SketchUp is still 32bit.

                The error you are getting is from the Win32API module. Seems to not like it that you feed it integer. It's expecting strings. Maybe you'll get some hints if you dig into Win32API.rb at the line number that raised the error. This Win32API compatibility shim might not be 100% compatible with the old Ruby 1.8. I'm not sure how much it changed between Ruby 1.8 and Ruby 2.0.

                1 Reply Last reply Reply Quote 0
                • B Offline
                  Brighter3D
                  last edited by 4 Mar 2014, 18:27

                  @unknownuser said:

                  SketchUp is still 32bit.

                  What a pity, I thought this version is 64bit already 😞.
                  There is still no possibility to load 64bit's dlls 😞.

                  @unknownuser said:

                  The error you are getting is from the Win32API module. Seems to not like it that you feed it integer. It's expecting strings. Maybe you'll get some hints if you dig into Win32API.rb at the line number that raised the error. This Win32API compatibility shim might not be 100% compatible with the old Ruby 1.8. I'm not sure how much it changed between Ruby 1.8 and Ruby 2.0.

                  Thank you, you put my thoughts into right direction.

                  changing
                  BRrender = Win32API.new(mydll,"RenderScene",["P","P","I","I","I"],"I")
                  into
                  BRrender = Win32API.new(mydll,"RenderScene",["I","P","I","I","I"],"I")

                  solves the problem.
                  Looks like "P" is char* now, and "I" can be int or void*...

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    tt_su
                    last edited by 5 Mar 2014, 11:25

                    @brighter3d said:

                    What a pity, I thought this version is 64bit already 😞.
                    There is still no possibility to load 64bit's dlls 😞.

                    Yea unfortunately it's not. I know it's a pain for render engines. The workaround would be to use a 64bit helper process to host the render engine.

                    @brighter3d said:

                    @unknownuser said:

                    The error you are getting is from the Win32API module. Seems to not like it that you feed it integer. It's expecting strings. Maybe you'll get some hints if you dig into Win32API.rb at the line number that raised the error. This Win32API compatibility shim might not be 100% compatible with the old Ruby 1.8. I'm not sure how much it changed between Ruby 1.8 and Ruby 2.0.

                    Thank you, you put my thoughts into right direction.

                    changing
                    BRrender = Win32API.new(mydll,"RenderScene",["P","P","I","I","I"],"I")
                    into
                    BRrender = Win32API.new(mydll,"RenderScene",["I","P","I","I","I"],"I")

                    solves the problem.
                    Looks like "P" is char* now, and "I" can be int or void*...

                    Oh good! Glad that worked. I think there has been some tweaks made between Ruby 1.8 and 1.9 in that respect.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      marksup
                      last edited by 18 Mar 2014, 12:37

                      I have written a CSV format file SketchUp Importer which includes the following lines...

                      File.foreach(csv_filepath) do |file_data|
                      next if file_data.match(/\A#/)

                      The CSV file includes the following comment line: # Room-Name, Floor Nr, Area m², Length

                      Sketchup 2014 Bugsplats on processing the CSV file (at the match statement) if it is not UTF-8 encoded and includes the squared character.

                      Does this need to be fixed by SketchUp and/or is there anything I can do to detect/avoid the issue (since I can not control either the selected CSV file content or its encoding)?

                      These UTF-8 errors are insidious, and a definitive guide to their avoidance would be very helpful. What have other Ruby programmers been doing (prior to SketchUp 2014) to adjust to the new Ruby version?, are there no existing resources?

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        tt_su
                        last edited by 18 Mar 2014, 13:03

                        @marksup said:

                        Does this need to be fixed by SketchUp and/or is there anything I can do to detect/avoid the issue (since I can not control either the selected CSV file content or its encoding)?

                        Bugsplats should not happen and is something we should fix. Have you submitted the splats? With any information we can use to look it up?

                        @marksup said:

                        These UTF-8 errors are insidious, and a definitive guide to their avoidance would be very helpful. What have other Ruby programmers been doing (prior to SketchUp 2014) to adjust to the new Ruby version?, are there no existing resources?

                        If you search on Ruby in general, without the context of SketchUp, you find a number of articles and forum posts with people migrating from Ruby 1.8 to 1.9/2.0.

                        The bugsplat here is troublesome, because it should just raise an error. If it had raised an error you would have been able to try again with a different encoding. Now, I haven't read arbitrary files with ruby yet, but I would have thought there would be a methods in the Ruby StdLib to detect encoding of a given string/file?

                        Back to the bugsplat, can you provide a small snippet that reads a file and a file that will cause it to crash? Smallest possible snippet to reproduce this?

                        1 Reply Last reply Reply Quote 0
                        • T Offline
                          TIG Moderator
                          last edited by 18 Mar 2014, 13:16

                          If the .CSV file is not in UTF8-without-BOM encoding, but say ANSI, and also since it may include characters like 'm²', these both might cause you issues.
                          It's easy enough to [re]encode any file appropriately using Notepad++.exe...
                          However if the 'm²' were typed in say Unicode, then it might then be converted to a strange looking character combo when re-encoded.
                          In that case you need to retype the character[s] and it should convert automatically to display in UTF8 encoding...
                          Save and retry.

                          Of course, the .RB file itself must of course be properly encoded as UTF8-without-BOM to be compatible with v2014's Ruby2.0, and remember that any special characters [like 'm²'] which you had in any earlier encoding might have to be corrected if already UTF8 compliant... as outlined above...

                          TIG

                          1 Reply Last reply Reply Quote 0
                          • M Offline
                            marksup
                            last edited by 18 Mar 2014, 13:37

                            Notepad++ is great, but customers of plugins can not be expected to use it to investigate and correct the encoding of their data files.

                            Is the encoding of a scrambled Ruby file significant? - since a scrambled UTF-8 .rb is reported by Notepad++ as ANSI.

                            1 Reply Last reply Reply Quote 0
                            • T Offline
                              TIG Moderator
                              last edited by 18 Mar 2014, 13:53

                              It is unfortunate that the encoding of a PC's plain Notepad file is in ANSI.
                              However a txt/csv file made in Excel or through a Ruby script should be encoded as compatible UFT8-without-BOM...

                              If you have made the RBS from an incorrectly encoded RB it will fail in v2014.
                              If you make the RB correctly encoded than encrypt the RBS from that is should be compatible.
                              What Notepad++ sees the contents as is somewhat academic as isn't it a binary file ?

                              Files encoded as UFT8-without-BOM should be compatible with v2014 Ruby2.0 AND all earlier versions of SketchUp and their Ruby version...

                              You could try trapping for the Sketchup.version >= 14 then re-encoding the string got from any data file.
                              You should still be able to 'read' the contents of an ANSI encoded data file [or any type of data file - even binary is 'readable'], but to then use that string in Ruby2.0 you probably need to force some recoding...

                              if Sketchup.version.to_i >= 14
                                lines = IO.read(csv_file_path).force_encoding('UTF-8')
                              else
                                lines = IO.read(csv_file_path)
                              end
                              lines.split("\n").each{|line|
                                ### process the line...
                              }
                              

                              I typed this without reference and it is untested, but you get the idea...

                              TIG

                              1 Reply Last reply Reply Quote 0
                              • Dan RathbunD Offline
                                Dan Rathbun
                                last edited by 18 Mar 2014, 14:10

                                Making the first statements of the block:

                                if defined?(Encoding)
                                  file_data.encode!("UTF-8") unless file_data.encoding == Encoding;;UTF_8
                                end
                                

                                💭

                                I'm not here much anymore.

                                1 Reply Last reply Reply Quote 0
                                • T Offline
                                  tt_su
                                  last edited by 18 Mar 2014, 14:43

                                  You could try to open the file as ASCII-8bit - then attempt to convert the data afterwards. But in general you need to know what encoding a file is in. You'll see editors often provide this option, even Notepad.

                                  After reading the file as ASCII-8bit - which is in effect what Ruby 1.8 did - then you could try to change the encoding to UTF-8 - if that fails it's a good chance the file is ANSI encoded in which you can retry with that. (Though there are many variants of ANSI, US-ANSI is most normal one.)

                                  As for the crashes - as I mentioned, that should not happen. Did you submit those report? This is important for us in order to address the crash.

                                  1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    marksup
                                    last edited by 18 Mar 2014, 14:56

                                    Bugsplat report duly filed.

                                    1 Reply Last reply Reply Quote 0
                                    • T Offline
                                      tt_su
                                      last edited by 18 Mar 2014, 16:25

                                      @marksup said:

                                      Bugsplat report duly filed.

                                      Keywords we can search for?

                                      1 Reply Last reply Reply Quote 0
                                      • M Offline
                                        marksup
                                        last edited by 18 Mar 2014, 17:06

                                        I used the original post above as the scenario description, so... Ruby, Importer, UTF-8 and/or m² should find it.

                                        1 Reply Last reply Reply Quote 0
                                        • T Offline
                                          tt_su
                                          last edited by 19 Mar 2014, 09:40

                                          hm... this crashes deep into the Ruby interpreter...

                                          Can you provide a small code snippet to reproduce it?

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

                                          Advertisement