Ruby and special characters

Ruby and special characters

Postby areal3d » Sun Dec 03, 2023 10:58 am

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
0

areal3d 
PluginStore Author
PluginStore Author
 

Re: Ruby and special characters

Postby TIG » Sun Dec 03, 2023 2:21 pm

In the very first line of your Ruby RB file add this.
Code: Select all
# 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...
Code: Select all
text_string_read from_ifc_file.force_encoding("UTF-8")
1
TIG
User avatar
TIG 
Global Moderator
 

Re: Ruby and special characters

Postby artmusicstudio » Tue Dec 12, 2023 10:19 am

thanx a lot. perfect-:)
0
User avatar
artmusicstudio 
PluginStore Author
PluginStore Author
 

Re: Ruby and special characters

Postby areal3d » Wed Dec 13, 2023 6:01 pm

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
0

areal3d 
PluginStore Author
PluginStore Author
 

Re: Ruby and special characters

Postby TIG » Wed Dec 13, 2023 6:26 pm

#<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...
1
TIG
User avatar
TIG 
Global Moderator
 

Re: Ruby and special characters

Postby areal3d » Fri Dec 15, 2023 12:17 am

the alternativ format is perfectly working !

thanx a lot for this, i di not know this syntax yet :-)

stan
0

areal3d 
PluginStore Author
PluginStore Author
 

Re: Ruby and special characters

Postby areal3d » Fri Dec 15, 2023 4:29 pm

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
0

areal3d 
PluginStore Author
PluginStore Author
 

Re: Ruby and special characters

Postby TIG » Fri Dec 15, 2023 5:50 pm

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 ... ss-in-ruby
https://www.cloudbees.com/blog/how-ruby ... developers

There are lots or resources on the www...
0
TIG
User avatar
TIG 
Global Moderator
 

Re: Ruby and special characters

Postby areal3d » Sun Dec 24, 2023 9:08 pm

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
0

areal3d 
PluginStore Author
PluginStore Author
 

Re: Ruby and special characters

Postby Dan Rathbun » Sun Feb 25, 2024 12:29 am

TIG wrote:In the very first line of your Ruby RB file add this.
Code: Select all
# 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.
0
    I'm not here much anymore. But a PM will fire email notifications.
    User avatar
    Dan Rathbun 
    PluginStore Author
    PluginStore Author
     

    SketchUcation One-Liner Adverts

    by Ad Machine » 5 minutes ago



    Ad Machine 
    Robot
     



     

    Return to Developers' Forum

    Who is online

    Users browsing this forum: Rich O Brien and 8 guests