sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Ruby and special characters

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 11 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.
    • A Offline
      areal3d Newcomers
      last edited by

      hi,

      i get ifc-fields from german cad-programs, which have "ä, Ü, " etc. in the ifc-descriptions.

      ho can i handle this in ruby, when i want to check them?

      example:

      iterate key / value...

      if key == "Fläche" then...

      saving this the ruby do not work...

      thanx
      stan

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

        In the very first line of your Ruby RB file add this.

        # encoding; UTF-8
        

        This should ensure your own code is properly formatted.

        Additionally, if needed, to force your 'read' ifc data file's text into the correct encoding try this...

        text_string_read from_ifc_file.force_encoding("UTF-8")
        

        TIG

        1 Reply Last reply Reply Quote 0
        • artmusicstudioA Offline
          artmusicstudio
          last edited by

          thanx a lot. perfect-:)

          1 Reply Last reply Reply Quote 0
          • A Offline
            areal3d Newcomers
            last edited by

            hi tig,
            first : thanx for your help.
            but
            i am doing something wrong.

            i placed the utf info at the very first line (above "Module")

            ` # encoding: UTF-8
            module ZF_ifc

            #########################################################################################
            class ZF_BIM_version
            #######################################`

            but i still get

            Error:
            #<SyntaxError: C:/Users/zdene/AppData/Roaming/SketchUp/SketchUp 2023/SketchUp/Plugins/zf_areal3d_bim/areal3d_bim_prg.rb:6743: invalid multibyte char (UTF-8)>

            so i cannot search in keys for german letters (ä,ü,ö).

            in the key of the hash there is an "ä"

            i want to check with ruby, if there is an "ä" in ite key:

            elsif tt[0].to_s.include?("L&#228;nge")

            elsif tt[0].to_s.include?("L&auml;nge")

            elsif tt[0].to_s.include?("Länge")

            i just stick.....

            stan

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

              #<SyntaxError: C:/Users/zdene/AppData/Roaming/SketchUp/SketchUp 2023/SketchUp/Plugins/zf_areal3d_bim/areal3d_bim_prg.rb:6743: invalid multibyte char (UTF-8)>

              Tells you the line where the error is...

              Have you tried simply copy/pasting the same string with the ä ü ö characters
              into your script, so as to sidestep the issue ?
              e.g.

              elsif tt[0].to_s.include?("Länge")

              an alternative format could be

              elsif tt[0].to_s=~/Länge/

              If the RB is specifically defined as using UTF-8 then it should work...

              TIG

              1 Reply Last reply Reply Quote 0
              • A Offline
                areal3d Newcomers
                last edited by

                the alternativ format is perfectly working !

                thanx a lot for this, i di not know this syntax yet 😄

                stan

                1 Reply Last reply Reply Quote 0
                • A Offline
                  areal3d Newcomers
                  last edited by

                  hi tig,
                  just a small add to this toppic:

                  situation:
                  i imported a ifc from a german cad with special chatacters "ä,ö,ü..."
                  in the "key" of the ifc-parameter

                  we solved the handling for ruby by using ift-8

                  so far, so good.

                  now i tried to export this file from skp to ifc
                  and reimport ( to see, if my attributes are passed correctly).

                  can it be , that sketchup exports the code of the special character in some special way?

                  in reimport the ifc-key contents the code itself now, not the original special character - somehow...

                  screenshots show the display in the original file and after the re-import.

                  i want to try to detect those codes by ruby again to be able to differ between areas, length and so on.

                  regards
                  stan


                  Screenshot 2023-12-15 162518.jpg


                  Screenshot 2023-12-15 162852.jpg

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

                    What text encoding does the original ifc file use ?

                    Once you know that you can try to convert the encoding of the final edited string you want to put into that file, encoding it into the appropriate format...

                    https://www.educative.io/answers/how-to-use-the-encoding-class-in-ruby
                    https://www.cloudbees.com/blog/how-ruby-string-encoding-benefits-developers

                    There are lots or resources on the http://www...

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • A Offline
                      areal3d Newcomers
                      last edited by

                      hi tig,
                      ok, if it depends on the encoding of the original file imported to skp, i will have to study it.
                      thanx and merry x-mas!

                      stan

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @tig said:

                        In the very first line of your Ruby RB file add this.

                        # encoding; UTF-8
                        

                        This should ensure your own code is properly formatted.

                        This magic comment does not ensure that the code file is saved as UTF-8 w/o BOM.
                        This must be set in whatever code editor is being used.

                        I'm not here much anymore.

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

                        Advertisement