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

    Posts

    Recent Best Controversial
    • RE: Working around "location=", for debugging

      My "way around the problem", described above, didn't quite work. Problem is, there's no reliable way to send code to the dialog until it has indicated (eg, via location=...) that it's alive. And, of course, the location=... code is what I'm trying to add.

      My current hack, which seems to be working (if ugly), is to write two copies of the HTML file (eg, main.html and DBG_main.html). If I use the latter in the browser, I can test for it, as:

      
      function set_loc(string) {
        var patt = /DBG_/;
        var url  = document.documentURI;
        if (!patt.test(url)) { location = string; }
      }
      
      
      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Working around "location=", for debugging

      No, the user agent strings are identical between the SU WebDialog and Safari.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Working around "location=", for debugging

      I figured out a way around the problem. I define an empty safe_loc function in my JS file, giving the browsers something safe to call. I then redefine it to (after the dialog is launched) from the plugin, making it work under SketchUp.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Working around "location=", for debugging

      Because I'm using WebDialog with temporary files (eg, *.{css,html,js), I can point a normal browser (eg, Safari, Firefox) at them and get useful debugging help. Unfortunately, these browsers get terribly confused if my code uses the "location='skp:...'" hack.

      I'd like to find a run-time way to get around this problem. If I could tell that I was running under a normal browser, I could avoid running the "location='skp:...'" command. Alternatively, maybe there's a way to intercept the event (or ???) that the command causes. I'm not particular (:-).

      I tried dumping the contents of the navigator object in an alert, under both SketchUp and Safari, but the results are the same, so no luck there. I also tried writing a JS function that would ignore the exception:

      
      safe_loc = function(string) {
        try       { location = string; }
        catch (e) { }  // Ignore errors.
      }
      
      

      Can someone suggest a way to handle this?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Mechanizing the model upload process?

      I'd like to be able to mechanize the process of uploading models to the 3D Warehouse. Has anyone here found any tricks that would help in this? For example, is there a way to initiate an upload from the Ruby API?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Ruby 1.8.6

      Using SketchUp Pro (Version 8.0.3161) on Mac OS X, I'm seeing a RUBY_VERSION of "1.8.5". Wazzup?

      -r

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: JS loading problem under Mac OS X SU

      It turns out that the relative paths to my library JS (and probably CSS) were working under the browsers, but not under SU. !@#$%^ (Thanks, Dan!)

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: JS loading problem under Mac OS X SU

      I'm only using Strict because ThomThom recommends it. That said, changing DOCTYPE to Transitional does not make any difference.

      Following the advice of a JS hacker, I changed the way I was telling the code to run in my JS file. Specifically, I added onload="main()" to the body tag and used main() as the name of the function in my foo.js file.

      I then performed a minimal test, without jQuery, to see if I could get that working. After adding id="foo" to my (only) h1 header, I tried:

      
      function main() {
        var foo = document.getElementById('foo');
        foo.innerHTML = 'Hello, World!';
      }
      
      

      This worked under SketchUp, proving that it could use JS from a file. I then added a number of lines of code (that worked in Firefox and Safari), to see what transpired:

      
      function main() {
        var foo = document.getElementById('foo');
        foo.innerHTML = 'Hello, World!';
        alert('main 1');
        $('h3').addClass('blue');        //T - Ignored
      
        var fc  = $('div.show_hide > ;first-child');
        var oc  = fc.nextAll();
        var sw  = ' (<a href="#">show</a>)';
      
        fc.append(sw);                   //T - Ignored
        oc.hide();                       //T - Ignored
        ...
      }
      
      

      As the comments indicate, at least some of my jQuery methods are being ignored by the WebDialog. I'm not sure how to proceed at the moment. One possibility is that the version of jQuery I'm using (1.4.2) is incompatible with SU 7.1. If anyone can speak to this question, please do!

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: JS loading problem under Mac OS X SU

      I already had the Developer Tools enabled. Clicking on "Enable Extensions" allows my JavaScript to run under Safari, but of course this doesn't help the WebDialog under SketchUp.

      So, I suppose I can either:

      • try to figure out what requires the extensions
      • wait for Google to add the extensions to SketchUp

      It looks like it doesn't like the :not() syntax. The following version works under Safari, but still fails (ie, no JS activity) under SU:

      
      $(document).ready(
        function() {
      //  alert(1);
      
          var fc  = $('div.show_hide > ;first-child'      );
          var oc  = fc.nextAll();
          var sw  = ' (<a href="#">show</a>)';
          fc.append(sw);
          oc.hide();
      
          $('a', fc).click(
            function(event) {
              var div  = $(this).parent().parent();
      		    var fc   = $('> ;first-child',       div);
      		    var fca  = $('a',                    fc);
              var oc   = fc.nextAll();
      
              if (fca.text() == 'show') {
                fca.text('hide'); oc.show();
              }
              else {
                fca.text('show'); oc.hide();
              }
            }
          );
        }
      );
      
      

      In fact, even this doesn't work under SU:

      
      $(document).ready(
        function() {
          $('h3').addClass('blue');
        }
      );
      
      

      Tracking this down with a number of cases, it appears that $(document).ready() never fires, whether in the HTML file or the invoked JS file.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: JS loading problem under Mac OS X SU

      Indeed, it fails under Safari, as well. Now what? 😄

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • JS loading problem under Mac OS X SU

      I'm having a JavaScript loading problem under Mac OS X SketchUp.

      My plugin generates an HTML file and then displays it, ala:

      
      foo_path = @file_base + '/dhtml/foo.html'
      write_html(foo_path)
      dialog.set_file(foo_path)
      dialog.show()
      
      

      The generated file looks like:

      
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
      <html>
        <!-- foo.html -->
      
        <head>
          <meta http-equiv="X-UA-Compatible" content="IE=8" />
      
          <script src="../../lib/jQuery/jquery-1.4.2.min.js"
                  type="text/javascript"></script>
          <script src="foo.js"
                  type="text/javascript"></script>
        </head>
      
        <body>
          <h1>Foozle</h1>
      
          <form action="???">
            <div class="show_hide">
              <h2>Bar</h2>
        ...
      
      

      Finally, here's my JavaScript:

      
      // foo.js
      
      $(document).ready(
        function() {
          alert(1)
          var fc  = $('div.show_hide > ;first-child'      )
          var oc  = $('div.show_hide > ;not(;first-child)')
          var sw  = ' (<a href="#">show</a>)';
          fc.append(sw)
          oc.hide();
      
          $('a', fc).click(
            function(event) {
              var div  = $(this).parent().parent()
      		    var fc   = $('> ;first-child',       div)
      		    var fca  = $('a',                    fc)
      		    var oc   = $('> ;not(;first-child)', div)
      
              if (fca.text() == 'show') {
                fca.text('hide'); oc.show();
              }
              else {
                fca.text('show'); oc.hide();
              }
            }
          );
        }
      );
      
      

      If I bring up the file in Firefox, the alert fires and all of the JS code works as expected. However, in the WebDialog that SU brings up, none of the JS seems to be executing. Help?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Saving components so they &quot;open&quot; nicely?

      Indeed, it turns out that calling refresh_thumbnail after the call to zoom_extents and before the call to save_as clears up the problem.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Saving components so they &quot;open&quot; nicely?

      It looks like refresh_thumbnail does the trick; thanks! I'll report back when I have done further testing...

      -r

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Saving components so they &quot;open&quot; nicely?

      I have a plugin which saves the component it has been working on in a file, as:

      comp_def.save_as(out_path)
      

      All of the saved components import nicely, but some of them don't "open" well. For example, they might not show the entire model, show the model in too large a space, etc.

      In some cases, things get really extreme: I have to scroll waaaay out (or use "Camera > ZoomExtents") to see the model properly.

      I have tried doing a ZoomExtents inside the plugin, as:

      Sketchup.send_action('ZoomExtents;')
      

      or

      
        am    = Sketchup.active_model
        av    = am.active_view
        av    = av.zoom_extents
      
      

      or

      Sketchup.active_model.active_view.
        zoom(Sketchup.active_model.entities)
      

      but this has no effect on the saved file. HOWEVER, the window adjusts itself as desired if I open the saved file and type the command into the Ruby Console, as:

      Sketchup.active_model.active_view.zoom_extents
      

      My impression is that zoom_extents is working, but that the extents aren't getting saved by the save_as method.

      Help?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Getting SketchUp to play nicely with RubyGems?

      I agree that it could be useful to have public references for configuration information (eg, directory trees, control files) used by SU on various platforms. I'm a little nervous, however, about posting these files without some sort of permission from Google. Can anyone comment on the legalities here? More generally, where should persistent resources such as this be posted?

      "Current" is a symbolic link, pointing at a directory (A). In general, a symlink can be used in place of the referenced item (eg, file, directory), though the user process needs to have permission to access both the symbolic link and the referenced item.

      I agree that it would be preferable for both the Mac and Windows versions of SketchUp to have the same (reasonably current) version of Ruby. However, this should be done in a way that keeps existing plugins working smoothly for naive users. So, perhaps we need a way for experienced
      users to "opt in" to a newer version of Ruby, etc.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Getting SketchUp to play nicely with RubyGems?

      (1) How many Ruby versions... Just the 'A' version ??

      That's all I see on my system.

      (2) How does the Mac SketchUp edition decide what Ruby version to load ...
      Is it hard-coded, OR is there a plist file ??

      There are several plist files that might be relevant, including:

      
      /Applications/Google/SketchUp 7/SketchUP.app/Contents/
        Frameworks/Ruby.framework/
          Resources/Info.plist
          Versions/A/Resources/Info.plist
      
      

      However, a quick inspection didn't reveal any pointers in the plists I examined. I suspect that the determination is made by following this symlink:

      
      .../Ruby.framework/Versions/Current -> A
      
      

      (3) Could you 'juryrig' SketchUp to load another version ...
      (4) If it works... can it work for the latest v 1.9.x ??

      Maybe, but I'm hoping that someone with access to and/or knowledge about the internals of SketchUp will jump in and tell us what's going on. I dislike snipe hunts...

      FWIW, I think we're more likely to be able to use a full copy of MRI 1.8.5 than any later version (less differences to get in the way).

      (5) The RVM issue. I can't use RVM, ...

      I suspect that RVM could be made to work under CygWin, if that isn't too weird for you. If you're interested in pursuing that goal, I suggest that you chat with the folks on the #rvm IRC channel...

      I don't know whether RVM has an override to set a custom path, but I can't imagine it would be very hard to add on, if not.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Getting SketchUp to play nicely with RubyGems?

      I'm pretty sure that SU supplies its own copy of the interpreter. For one thing, there's the fact that it sets RUBY_VERSION to '1.8.5' on a machine whose native Ruby is '1.8.7'. Hmmmmm.

      
        $ cd '/Applications/Google/SketchUp 7/SketchUP.app/Contents'
        $ cd 'Frameworks/Ruby.framework/Versions/A'
        $ ls -l Ruby
        -rwxrwxr-x  1  root  admin  1768636 Dec 29 2009 Ruby
      
      
      posted in Developers' Forum
      RichMorinR
      RichMorin
    • RE: Getting SketchUp to play nicely with RubyGems?

      The required bundle exists and is both readable and executable (?). I have updated the gist (http://gist.github.com/473142) to show this and to list all of the dylibs in the "Google SketchUp 7" directory tree. I can't tell from the file names whether any of these is the Ruby interpreter.

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Getting SketchUp to play nicely with RubyGems?

      Google SketchUp includes a trimmed-down version of MRI 1.8.5, including only part of the Ruby Standard Library.  As detailed on

      http://cfcl.com/twiki/bin/view/Projects/SketchUp/LibraryUse

      I'm trying to use RVM to give my SketchUp plugins access to the full Ruby library, including the wide world of RubyGems.

      I seem to have 1.8.5 installed and working, as well as a copy of RubyGems (1.3.4).  However, when I try "require 'yaml'" in the SketchUp Ruby Console, I get a nastygram:

      > require 'yaml'
      Error; #<LoadError;
      /Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib
        /ruby/1.8/i686-darwin10.4.0/stringio.bundle;
      Failed to load
      /Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib
        /ruby/1.8/i686-darwin10.4.0/stringio.bundle>
      (eval);1
      /Users/rdm/.rvm/rubies/ruby-1.8.5-p231/lib
        /ruby/1.8/yaml.rb;9
      (eval);1;in `require'
      (eval);1
      

      The requested file seems to be present, so I'm not sure what the problem is.

      Looking on the web for help, I found the following thread:

      http://forums.sketchucation.com/viewtopic.php?f=180&t=25233

      This discussion seems to be specific to MS Windows, but it makes me wonder if I need to reply one or more dylibs in SU. That said, I have no idea which one(s) I'd need to replace and I'm not interested in going on a snipe hunt.

      Help?

      posted in Developers' Forum
      RichMorinR
      RichMorin
    • Re-applying materials after scaling?

      Let's say I have a component with a vertical wood grain material. If I make the component larger in the vertical dimension, the material stretches. This makes the wood grain distort (eg, look "blurry").

      Using the UI, I can repair this damage, by sampling the material on a face in an unstretched component, then doing a "Paste all" into a vertical grain face in the stretched component. However, I can't figure out what part of the API would allow me to do this.

      Using the UI, I set up "before" and "after" files. I then compared a number of values, including the material's color, display_name, and name. None of these appear to change.

      The object ID for the material's texture changes, but I see no change in the texture's height, width, image_height, image_width, average_color, or filename.

      What am I missing?

      -r

      posted in Plugins
      RichMorinR
      RichMorin
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 4 / 6