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: [Plugin] Material_Maintenance v2.2 - 2013-01-13

      @cmd said:

      @myhand said:

      Bug fix version V2.1.1 released.

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

      Myhand,

      Good stuff! no more errors!

      .... but I am not getting material thumbnails nor am I getting component images to display.

      Is this due to the change for mac?

      Sorry this took so long but have been in the middle of something else. Here is a debug version that will trace the file paths the Javascript code is trying to load into the ruby console. Same install procedure as before.

      Please send me the console output.

      Thumbnail debug

      posted in Plugins
      M
      Myhand
    • RE: Html multiline, js to SketchUp

      @dan rathbun said:

      (1) I said inside your module (not your directory!) Messing with require would not be good idea. But you can do whatever inside your own module. Override the method your module inherited. You can always call Kernel.require() to use the original, but this all sounds silly.

      Sorry Dan, I am being really thick here πŸ˜•. Are you saying I should cut and paste the code in common.rb into MyPlugin.rb file...?

      btw it appears that I can use the URI.escape() method without doing a require or even having the common.rb file in my plugin directory. Does Sketchup not maybe support it now out of the box?

      @dan rathbun said:

      There is a code example here I wrote that shows using the SketchupExtension class, and dealing with paths. (Check the Code Snippets index.)

      Again being a bit slow... 😞 but where is the code example you refer to?

      Thanks for the help.

      posted in Developers' Forum
      M
      Myhand
    • RE: Html multiline, js to SketchUp

      @dan rathbun said:

      [*]cut and paste the "Ruby186/lib/ruby/1.8/uri/common.rb" INSIDE your plugin sub-module

      Thanks Dan, this works well. I know another basic question, but is it possible to have the "require" statement in my plugin specify a relative path to common.rb i.e. I currently have to use require 'MyPlugin/common.rb' from the MyPlugin.rb file, even though they are both in the same folder, i.e. the plugins/MyPlugin folder.

      @dan rathbun said:

      On the Javascript-side you might be able to get away with using the built-in %(#8000BF)[escape()] and %(#8000BF)[unescape()] functions.

      Do you know if it is possible to port the 1.9.2 version of the common.rb library to work in Sketchup. This would allow you to use the new encode_www_form and encode_www_form_component methods which also have corresponding methods in JS.

      posted in Developers' Forum
      M
      Myhand
    • RE: Using object ids to restore object instance references?

      @thomthom said:

      Notice that after the Ruby object has been GC's and you then again request new references it's all new object instances.

      It does seem like that SketchUp will ensure there is only ever one Ruby object per entity - so as long as anything is holding on to the reference to an entity SketchUp will reuse this. But once garbage collected it'll generate a new one when needed.

      Very good detective work! πŸ‘ Come to think of it I have seen similar behavior in JNI (Java Native Interface) where Java will garbage collect references to "proxy objects" when there are no longer java side references. This is because the C++ objects are not managed code running in a VM, and therefore Java does not have access the C++ object lifecycle (without custom hooks added on the C++ side).

      posted in Developers' Forum
      M
      Myhand
    • Using object ids to restore object instance references?

      @myhand said:

      Is there a reason I not just use the the material's object_id.to_s() as key and also as thumbnail file name etc. It seems unnecessary to concatenate with display_name and then hash, when object_id should be unique within one session...?

      I seem to have found the answer to this question the hard way... The object_id seem to expire after a while and I am getting "The object has been garbage collected" errors on a very large model when listing component definitions. It is all still in the same Sketchup session and all the component definitions are still in Sketchup, but somehow the id's you get from ComponentDefinition.object_id can no longer be used to lookup those objects with ObjectSpace._id2ref.

      Does anyone know of a good key to use to uniquely reference Materials and ComponentDefinitions which can later (in the same Sketchup session) be used to reference them again. I could use Entity.entityID but then would have to iterate over all materials or component definitions to find the instance again.

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

      @thomthom said:

      @myhand said:

      Need 7 '''s for a "!

      ❓ ❓

      What?

      Sorry, meant you need

      "a JSON escaped double quote need to be specified like this \\\\\\\" in Ruby for a WebDialog call"

      to produce

      "a JSON escaped double quote need to be specified like this \" in Ruby for a WebDialog call"
      

      as the parameter of the JS function called.

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

      @dan rathbun said:

      And you are kinda re-inventing the wheel. Js has %(#8000BF)[escape()] and %(#8000BF)[unescape()], and Ruby has them in the URI library.

      See topic: http://sketchucation.com/forums/viewtopic.php?f=180&t=49183#p442102

      Thanks for this Dan! It works well, and I do not need to remember the number of slashes. πŸ˜„

      I see that escape() and unescape() are deprecated though and that you are recommended to use

      decodeURI()
      
      decodeURIComponent()
      

      Which do you recommend or should I continue with unescape()?

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

      @aerilius said:

      1. You need to escape \ characters in the double-quoted javascript code that you want to bring into the webdialog (this first escaping is what makes a valid Ruby string).
        %(#000000)["alert('C:\users')"] # bad Ruby string
        %(#000000)["alert('C:\\users')"] # good Ruby string
      2. In the webdialog, the string arrives written in a script element. As always, the same escaping rules apply again:
        %(#000000)[alert('C:\users')] // bad JavaScript code
        %(#000000)[alert('C:\\users')] // good JavaScript code

      => So finally this means we need double escaping on the Ruby side!
      %(#000000)["alert('C:\\\\users')"] # Ruby string

      Thanks for a very clear explanation. πŸ‘ I tried this last night and it worked. Need 7 '''s for a "!

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

      @dan rathbun said:

      Sorry, it is a 5-slot private repository at this time, and we really need very experienced Rubyists for the slots.

      No problem Dan, I only looked there as Aerilius recommended I do so.

      @dan rathbun said:

      And you are kinda re-inventing the wheel. Js has %(#8000BF)[escape()] and %(#8000BF)[unescape()], and Ruby has them in the URI library.

      See topic: http://sketchucation.com/forums/viewtopic.php?f=180&t=49183#p442102

      In fact I would vote for Ruby's URI::Escape module to be mixed into the SketchUp API UI::WebDialog class.

      Thank you, I will try the URI library (I already use escape() in my latest JS code). I do not really want to reinvent the wheel, hence me asking the question here.

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

      @tig said:

      How are you to show the display-name AND its matching thumbnail in the dialog etc ? Unless you have both to refer to ?

      I pass in both the name(as is without any manipulation), and the object_id to the WebDialog. This also allows me to uniquely identify which materials to change. i.e. I only pass the object_id (key) back to Ruby.

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

      @tig said:

      You could make a ruby hash of each material 'display-name'/'id' [rather than it's Sketchup name which will involve [], <> etc if it has been 'imported' etc; this 'display-name' is used in the dialog, and it is then linked to the material's 'id' in the hash. That 'id' is then used for the temp thumbnail png file-name. They are both already unique.

      The same applies to the component-thumbnail etc.

      You can then use the linked name/id to find the material/defn / id, to associate the right png with the material/defn etc...

      Is there a reason I not just use the the material's object_id.to_s() as key and also as thumbnail file name etc. It seems unnecessary to concatenate with display_name and then hash, when object_id should be unique within one session...?

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

      @tig said:

      Why no just remove the miscreant character OR use an _ ?

      Three reasons (none valid anymore)

      • I wanted descriptive file names (help with debugging)
      • I wanted to be clear which chars I replaced (helped with debugging)
      • I also have an OCD nerve and in theory by just deleting or replacing with a "ordinary" character could clash two similarly names materials that only differed in special characters (and yes it could still happen if each string have the same number of special characters all in the same positions but different characters or if someone actually used the ΒΆ) but I felt the chances were sufficiently small.

      I will probably go for using object_id as it will be exact(which I did not know existed when I wrote this part if the code initially).

      posted in Plugins
      M
      Myhand
    • RE: JSON in Ruby

      @aerilius said:

      => So finally this means we need double escaping on the Ruby side!
      %(#000000)["alert('C:\\\\users')"] # Ruby string

      I am sure I tried this last night, but will do some further tests again tonight.

      @aerilius said:

      In order to get control of such errors, we could send the code as a JavaScript string and eval() it:
      %(#000000)[webdialog.execute_script("try{eval(\"}bad_$yn7aX{\")}catch(e){}")]
      [/size]

      Nice idea, I might use this going forward.

      @aerilius said:

      please take a look and make use of the WebDialogX project.

      I cannot access the content. I get "You do not have access to the wiki." message, even after I have registered.

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

      @tig said:

      So the folder/subfolder is OK and the images exist.

      The image naming seems unduly convoluted, as it's adding some special characters etc...
      Why not use each material.display_name [with some replacement of characters like \ / : * ? " < > | etc] linked to a hash of the display-name containing its 'id' ?
      The thumbnail-images names match the 'display-names' ?

      This is sort of what I have done. i.e.

      display_name + "_" + object_id + ".png"

      with invalid windows file name characters replaced with the ΒΆ character. I know this character caused us problems in the marshaling on OSX, but forgot to remove it here. I will do so in the next patch.

      I do not think this is the problem though as some of the .png files do not have this character in the name...

      I will add some trace code (and remove the ΒΆ character) if you do not mind testing again CMD.

      posted in Plugins
      M
      Myhand
    • RE: JSON in Ruby

      OK, with the single quote now working, I have run into the next (and hopefully the last) problem. It appears as if the

      WebDialog.execute_script

      method strips all \ characters from its arguments as it passes it into JavaScript. I think it is because it does a eval() call on the JS.

      e.g.

      js_command = "material_maintenance.Sketchup.callUI(\"a string >\\< with a \\\" in the middle\")"; puts "js_command = #{js_command}";

      produces this in the Ruby console:

      
      js_command = material_maintenance.Sketchup.callUI("a string >\< with a \" in the middle")
      
      

      and this when you print the parameter to the callUI function as it hits JS.

      
      a string >< with a " in the middle 
      
      

      replacing js_command with

      js_command = "material_maintenance.Sketchup.callUI(\"a string >\\u005c\\u0022< with a \\u005c\\u0022 in the middle\")"

      works and produces the desired output in JS

      
      a string >\"< with a \" in the middle
      
      

      but this feels a bit clunky. Any other ideas?

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

      @oxer said:

      I have the same problem like cmd, the material thumbnails don't appear, I work on Mac OSX.

      Can you please follow TIG's instructions below and let us know the results?

      @tig said:

      @cmd
      If you write this in the Ruby Console ENV['TMPDIR'] + <enter> it gives the path to your 'temp' folder.
      In that folder ought to be a subfolder named 'material_maintenance' and in that the xxx.png material thumbnails and xxx.comp.png component thumbnails ? They might have weird looking 'id' type names...
      The subfolder is emptied when the tool runs, or it's made if it is missing.
      It could be that the files are getting made but some enduring issue in the html/js on MAC is preventing them displaying ??
      Can you confirm if the subfolder/files exist...

      Can you also please run

      ENV.sort.each{|e|p e};p

      and attach the console output.

      posted in Plugins
      M
      Myhand
    • RE: JSON in Ruby

      @thomthom said:

      @myhand said:

      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.

      Do you have the SketchUp Developer Tools installed? (https://github.com/thomthom/sketchup-developer-tools) Might be that it's interfering.

      Try with just your plugin installed.

      Yup it was the SketchUp Developer Tools. Disabling that fixed the problem thanks.

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

      Thanks guys, I will give this a go tonight. Yes I do have the SketchUp Developer Tools installed.

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

      @cmd said:

      Myhand,

      Good stuff! no more errors!

      .... but I am not getting material thumbnails nor am I getting component images to display.

      Is this due to the change for mac?

      I suspect it can be to do with the temp folder location on your MAC. I save the thumbs in a folder I create within the system temp folder. I use a technique (from ThomThom's very good article on materials http://www.thomthom.net/thoughts/2012/03/the-secrets-of-sketchups-materials/)
      to "guess" the temp folder.

      temp_path = File.expand_path( ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] )

      It might be that this does not work on your system and we might have to add some options to the list.

      driven, did you see the thumbs on your system?

      posted in Plugins
      M
      Myhand
    • RE: JSON in Ruby

      @dan rathbun said:

      s = %q(Dan's friggin' advice, "Hey, use Ruby's % lowercase 'q' interpretive delimiter. It's a great help when your bleepin' strings have "'" and '"' characters in them!")
      

      %Q and % is a double-quoted string. You can choose any 2 delimeters you want.

      name = %$MyHand$

      str = %q{I want some quotes right "HERE"! Let's go.}

      Thank you Dan, I will give this a go tonight. As you might have guessed though the actual string I am having problems with (not the pie shop one πŸ˜‰) is ComponentDefinition name field. Something like "Bath 6'x34"x54"". So I never actually input the string, I am just reading it. So I am not sure how I will use the above technique to step around the problem. Will have to give it some thought.

      posted in Developers' Forum
      M
      Myhand
    • 1 / 1