sketchucation logo sketchucation
    • Login
    1. Home
    2. Myhand
    3. Posts
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 89
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: JSON in Ruby

      @dan rathbun said:

      At the SketchUp Ruby Console:
      ` puts "Betty's pie shop"
      >> Betty's pie shop

      puts "Betty's pie shop".inspect()
      >> "Betty's pie shop"

      puts "Betty's pie shop".inspect().inspect()
      >> ""Betty's pie shop""`

      This works for me today on my work PC. So must be something specific with my Sketchup installation/version at home. Both are Version 8 out of the box installations on Windows. The one that corrupts the "'" char is the Pro addition, while the one at work is the Standard edition.

      posted in Developers' Forum
      M
      Myhand
    • RE: JSON in Ruby

      @driven said:

      May be your encoding... only fails with single quotes here
      john

      Thought so too initially. But I got the same results by typing straight into the Sketchup Ruby console... Can you set encoding at the Sketchup level?

      posted in Developers' Forum
      M
      Myhand
    • RE: JSON in Ruby

      Hi guys,

      I need some help. I have run into problems creating a json encoding where a string contains a single quote char. e.g. "Betty's pie shop"

      somehow ruby creates a new char which replaces the y and the '. You can see this by executing the following command:

      puts "Betty's pie shop"

      and I get

      Betts pie shops pie shop
      

      if you past this into an editor that supports UTF8 you see that a special char has been added into where the y and ' was. Also note that the last bit of the string is now duplicated.

      I can escape it, but this is then not a valid json string as json does not allow you to escape the ' char.

      posted in Developers' Forum
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      Bug fix version V2.1.1 released.

      Can be found here:

      http://www.keepingmyhandin.com/Downhome/Sketchup/material_maintenance_2

      CMD this should fix your problem also as the trace code that had the bug in is also now removed.

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @tig said:

      But params.each{|p|puts "p1 = >>#{p}<<"}
      should be the way ?
      NOT p.puts

      😳 thanks TIG!

      Still strange it worked on windows and driven's MAC and that the second parameter comes looks wrong but as long as it works.

      I am making a new build without the trace code which I will upload soon.

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @tig said:

      The text file when opened in 'Notepad++.exe' as 'UTF-8 without BOM' shows this: [attachment=0:2y0lvhlv]<!-- ia0 -->Capture.PNG<!-- ia0 -->[/attachment:2y0lvhlv] BUT when the same text is pasted into here it displays differently...
      !!!=> fromUIHandler: parameter string = 73-0__vzrefreshMaterialstruefalsefalse Error: #<NoMethodError: private methodputs' called for "73-0":String>`
      Presumably the 'RS' record-separator character [ASCII-030] is non-printing...
      Not sure how 'puts' seems broken 😕
      Are you parsing the string using split and the 'RS' as at splitter ?
      You should then be able to 'puts' the array elements ??

      Yes I am splitting the string with the 'RS' char. Very strange error message indeed. The code snippet where it fails is:

      ` puts "!!!=> fromUIHandler: parameter string = #{parameterString}";

        params = unmarshalParams(parameterString);
        
        params.each { |p|
          p.puts "p1 = >>#{p}<<";   // This is line 109
        }`
      

      Again this works fine on Windows, and appears to now also work for driven on his MAC so at a bit of a loss here.

      One other strange thing with this is that the output should look like this:

      
      !!!=> fromUIHandler; parameter string = 75-0__materialsRefreshedrefreshMaterialstruefalsefalse
      p1 = >>75-0<<
      p1 = >>__materialsRefreshed<<
      p1 = >>refreshMaterials<<
      p1 = >>true<<
      p1 = >>false<<
      p1 = >>false<<
      calling function >>refreshMaterials<<
      
      

      i.e. the second parameter should be "__materialsRefreshed" not "__vz" which it appears to be for both the MAC implementations. Strictly speaking this should not work even for driven.

      CMD, are you sure you have done a clean uninstall and install?

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      Thank you everyone for your help and good advice. Here is a version with noth of the protocol chars in the normal ascii range. I have chosen 30, and 31 the record and unit separator characters. They are not printable so there is a small chance there might again be problems on the MAC I guess, but this works fine on Windows.

      John, CMD do you mind trying again please? Debug is still on, so if this works I will publish a version without the tracing code.

      Debug version

      posted in Plugins
      M
      Myhand
    • RE: JSON in Ruby

      Hi OricAtmos,

      I got it to work now thank you. It seems that it can only serialise Hash and Array objects though, which is good enough for most cases I guess. Given the non-trivial install and given the fact that it uses binary libraries, I suspect it will not work on a MAC either without libraries built for that.

      I will therefore continue with my simple JSON encoder, which while probably much slower, is simple to install and should work out of the box on a MAC as it is pure RUBY. It can also encode standard objects which can be useful.

      Thanks for your help in getting this working though. I will keep it in mind if I ever have to do large data sets.

      posted in Developers' Forum
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      John, CMD, do you mind testing the attached version please?

      The previous debug version did not change the JS code as I thought it did. This one does. It is the last try with the current control chars, and if this does not work I will create a patch with a multiple chars in the standard ascii range.

      Again this requires a uninstall of the old plugin, restart of Sketchup and a install of the new debug version.

      Again please send me the output.

      Debug version

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @thomthom said:

      When I send parameters back from WebDialogs I've used combo characters like || or ||| which I know is very unlikely to appear in the data I send. (In the context of what I've done I've been sure they'd not appear.)

      In a system where there is user input you'd want to create your own escape sequence where you pick a character as array separator and ensure to escape any occurrence in the data - which then is un-escaped when you receive it on the other end.

      Escaping is the best way, and also what I am using in my Simple Jason serializer. I'll probably just implement the de-serialiser and then this whole problem will go away.

      Your short cut of using ||| etc. is also a good option and I will probably use that in the short term if my latest attempt to fix the problem does not work.

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @tig said:

      Another way is to restrict what a user can enter - e.g.
      <input type="text" id="project_name" value="" style="font-size:7pt; width:300px;" onKeyup="(this.value=this.value.replace(/[^-_0-9A-Za-z]/,''));" ... >
      This example limits the user's INPUT for the 'project_name' to letters, numbers, _, - etc... Then you can be sure that any 'separator' like '|' won't get replicated in the entered text... Obviously you need to change the regexp to suit your needs...

      yes I agree you always want to constrain at the input. In this case though the input in question is the Sketchup material editor, so I unfortunately have no control over that input.

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @driven said:

      next error... !!!=> fromUIHandler: parameter string = 73-0|__vE|findComponents|·147713020 p1 = >>73-0<< p1 = >>__vE<< p1 = >>findComponents<< p1 = >>·147713020<< calling function >>findComponents<< Error: #<ArgumentError: invalid value for Integer: "·147713020">

      Good work! This one is because the "·" char (183) char is used as an array token, and is also passed as a double byte char. So you would need to change that also.

      BTW, I have just seen that the debug.rbz I attached earlier was not built properly. So it might well be that the fix I put in earlier will work, but I cannot get the build to work yet.

      Appologies for wasting your time with testing that version! 😳

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @driven said:

      !!!=> fromUIHandler: parameter string = 73-0¶__vz¶refreshMaterials¶true¶false¶false p1 = >>73-0Â<< p1 = >>__vzÂ<< p1 = >>refreshMaterialsÂ<< p1 = >>trueÂ<< p1 = >>falseÂ<< p1 = >>false<< calling function >>refreshMaterialsÂ<< Error: #<NoMethodError: undefined methodrefreshMaterials' for #<MH_KeepingMyHandIn::MaterialMaintenance:0x11b2f898>>
      /Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:121:in send' /Users/johns_iMac/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/Material_Maintenance/Material_Maintenance.rb:121:in fromUIHandler'`

      Hi John, thanks for testing is this output from the latest Material_Maintenance_debug.rbz file?

      If so did you fully delete the previous version, install and restart Sketchup?

      posted in Plugins
      M
      Myhand
    • RE: JSON in Ruby

      @oricatmos said:

      @myhand said:

      Thanks OricAtmos! Will give it a try.

      Did you get it to work? Unfortunately I've been unsuccessful in finding out where I got it from.

      Sorry, I got a bit tied up with trying to solve the MAC bug in my Material_Maintenance Plugin.

      Thank you, I have now got it to not throw an error, but my test code does not seem to serialise objects, so will need to read the library docs to see what I am doing wrong

      ` require 'yajl'

      h = {"key1", "val1", "key2", "val2"};

      obj = ["Hello", "world", "I am here", ["where", "what", "are", "you"]];

      class TestClass

      @name = nil;
      @adress = nil;
      @list = nil;

      def initialize(p1, p2)
      @name, @adress = p1, p2;
      @list = [1,2,3.01,-4.35];
      end

      end

      t = TestClass.new("Richo", "37 Scotland Rd, Buckhurst Hill, IG9 5NP");

      obj = ["Hello", "world", t, "I am here", ["where", "what", "are", "you"]];

      str = Yajl::Encoder.encode(obj);

      puts str;`

      Produces

      
      ["Hello","world","#<TestClass;0x144d9cc0>","I am here",["where","what","are","you"]]
      
      

      Instead of the

      
      ["Hello","world",{"@list";[1,2,3.01,-4.35],"@name";"Richo","@adress";"37 Scotland Rd, Buckhurst Hill, IG9 5NP"},"I am here",["where","what","are","you"]]
      
      

      I would expect and which is what my simple JSON Serializer produces.

      posted in Developers' Forum
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      Ok so here is a debug version with the the token chars explicitly specified in both JS and Ruby. Unfortunately you will have to un-install the whole plugin and install the debug version.

      It still has tracing code in, so will still be a bit slow.

      John, CMD can you test again please?

      Debug version

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @thomthom said:

      SketchUp return strings in UTF-8. Anything above the ASCII character range will be multi-byte characters - which is easily mangled by Ruby 1.8's string manipulation methods as it treats 'characters' as single bytes.

      But my characters are well within the ASCII range...? i.e. they still fit within a byte. from which value does it convert them to multi byte?

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @driven said:

      ` > 183.chr
      ·

      182.chr
      ¶`
      they are not the same as the original chars, I was seeing in my script editor, and the script is now saying it's encoded uft8, which it wasn't
      john

      Hi John, these are the actual char codes, I have not changed the JS side and these codes still work for me on windows.

      I will now also change them in JS to explicit ASCII values. Unfortunately I have to repackage the whole plugin then, so will take me a bit of time, but then again it is likely to work.

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @tig said:

      You are returning a string divided up with some unique character.
      You then parse that string into bits, splitting it with that character.
      Unfortunately that character seems not to be a simple 1 bit ASCII character when passed over, so the split ends with the weird extra character that's left over at the end.
      This causes the issue.
      MAC and PC Ruby are different in the way they handle text-encoding...
      Are your various files encoded as ' UTF-8 without BOM' ?
      If you have Notepad++ it's a simple setting.
      This makes files 'cross-platform' [hopefully!].
      AND/or can you use a less 'exotic' dividing character - perhaps '|' ?

      TIG, I think your description is spot-on. I have now encoded the attached version of the file with UTF-8 without BOM (yes I use Notepad++ 😄) The JS file is already was already encoded in the that format.

      I would not have thought that the ruby file encoding should make a difference anymore as I am now explicitly setting the character codes (which are in the ascii range) I suspect JS is passing the character in as UTF-8. The reason for the exotic chars is that Sketchup does not seem to constrain chars users can enter in material names so in theory you can get conflict in the lower ascii range.

      I should probably write the simple JSON parser to complement my simple JSON serializer and get rid of the current char token approach in my bridge.

      driven, cmd, can you test again please?

      Debug version

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @mistro11 said:

      I'm having such a great month upgrading my Sketchup! Artisan, SketchUV, ProfileBuilder Pro, 1001Bits, and now this VERY useful plugin.

      Managing materials was always a major headache for me, especially when building multi-story houses with downloaded furniture. I tend to forget the fact that the downloaded furniture may have some of the same materials I assigned to what I already have in the model. I once waited for a long KT render to find out the pillows on one of the beds were made of chrome. This looks like it will save me a lot of material scanning time before export.

      Your first Ruby is a shiner 😎

      Thanks Mistro11! 😄

      posted in Plugins
      M
      Myhand
    • RE: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      CMD, here is the next iteration of the debug script. It might fix the problem as I have changed the way I specify the special characters I use from literals to providing the actual character codes. Even though they are special they are extended ascii so should work fine. As the .js file is UTF8 encoded I have not changed how I specify the chars there yet, but again it might just work.

      Either way I have also added extra trace code, so if it does not work it will give us further info to help pin down the problem.

      Do you mind trying it out and sending me the output again? Same procedure as before, just replace the .rb file with the attached version.

      Debug version

      posted in Plugins
      M
      Myhand
    • 1 / 1