sketchucation logo sketchucation
    • Login
    1. Home
    2. MartinRinehart
    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 131
    • Posts 766
    • Groups 1

    Posts

    Recent Best Controversial
    • WebDialog.set_html() Gotchas

      It is very convenient to keep small HTML segments in your Ruby, rather than making a separate file. However, you should know this:

      The WebDialog.set_html() writes your HTML into a temp file and hands the browser the URI of that file. During the file writing process, character substitution is performed. I'd call it a bug, not a feature. It means the string in this bit of script:

      crlf = '\x0d\x0a';

      is reduced to two characters, an unterminated string error at load time. This works:

      crlf = String.fromCharCode( 13 ) + String.fromCharCode( 10 );

      If you want a backslash in a regular expression, its probably best to put the HTML in its own file. This is from the console I'm working on:

              
      # escape the backslashes;
      pathname.gsub!( /\\/, "\\\\\\\\" ) # huh? dunno. experiment.
      
      
      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Layers and materials

      Move everything you want to Bucket brick onto a "brick" layer. Ctrl+A to select everything. Bucket brick.

      Exception: groups and component instances are not Bucketed. However, when you Bucket a group or instance, every face in the group/instance is Bucketed. Bucket is still loaded with "brick" until you change it, so this is quicker to do than to explain.

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: Snapping one surface to another

      Welcome!

      Is each a group or a component instance?

      Joining: along one base edge or face-to-face?

      A few? (by hand, SketchUp tools) or a lot? (Ruby program needed)

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: IE9 looking good

      The day I can stop writing s!@#$ like this I'll pop the cork on a superb bottle of bubbly.

          
      function getVPHeight() { // VP == ViewPort
          try { if ( innerHeight ) return innerHeight;  // standard
              if ( document.documentElement &&
                  document.documentElement.clientHeight ) // MSIE standards?
                  return document.documentElement.clientHeight; }
          catch( e ) { return document.body.offsetHeight; }// MSIE quirks
      }
      
      
      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Alternate API, Pioneers Wanted

      I edited the original post to state that Chapter 16 was available.

      I've also finished the design of the multi-instance animator. Simple and light. Will get to it as soon as I finish YARC (yet another Ruby console).

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Set camera, and move shape by end point

      @tig said:

      If you want to change target/eye/up you need to create a new camera to match your requirements.

      I timed this for my movie. Took less than 1% of the available "fuss with the scene" time at 24 fps.

      @tig said:

      tr=Geom::Transformation.translation(pt1.vector_to(another_point))
      then finally group.transform!(tr) to relocate the group to this new point anchored by corner 'pt1'

      Way harder than using the API I introduce in Chapter 16.

      movable = MovableCI.new( instance_you_want_to_move ) movable.move( point_or_vector )

      Also includes rotate and scale methods, no transformations required.

      The MovableCamera API also simplifies your life. If you're not doing animations, you can stop at mid-chapter. (You'll miss the final reprise of a character who was, in fact, modeled on TIG. You can scan for the fairytale colors to catch him near the end. He tells you why you might want to go back to the old, complicated way.)

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Sketchup.find_support_file

      @jim said:

      Variables created in a for loop which you might assume have loop scope are actually visible outside the loop when the loop terminates.

      Thanks!

      Ruby never ceases to amaze me.

      posted in Developers' Forum
      M
      MartinRinehart
    • Debugging WebDialogs' .tmp Files

      OK, so MSIE is giving you an error at line 123456789 and you are dead sure that the meaning of the message is "somewhere in your code there's something wrong." Very, very helpful. Been there?

      Lately I've been using WebDialog.set_html() to eliminate the need for a separate HTML file. That "useless" error message is not quite as useless as I used to think. It includes the URL of the file (it's on your disk, hidden). My last was something like "c:\Documents and Settings\username\Local Settings\Temp\skp1A.tmp". ("Local Settings" is hidden. Neither your Open File dialog nor Windows Explorer will show it. You can, however, type it into the Open File dialog.) Apparently, SketchUp writes this temp file and then hands its address to MSIE.

      You can open the file with Opera. Turn on the error console and you will find that mystery bug in a flash. (Assuming Opera thinks its a bug. Often but not always the case.) You'll need to comment out the line that sets location to "skp:...". Opera doesn't think "skp" is a valid protocol.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Sketchup.find_support_file

      @unknownuser said:

      Hi all,
      I have reports from users that Sketchup.find_support_file "plugins" returns nil although the folder exists

      On a PC (where it doesn't matter) the folder is "Plugins". Is the issue simply capitalization?

      I direct users to find their Plugins folder via Sketchup.find_support_file "Plugins" in the Ruby Console. Zero problems reported.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Sketchup.find_support_file

      @dan rathbun said:

      $LOAD_PATH.each {|e| target= ...

      May I cast one vote for the for ... in ... loop? I adopted it for my tutorial as I was writing for programmers and programming newbies. Then I read that it was indeed faster. And as a long-time, big-time fan of readable code, whatever.each {|x| ... wins no prizes.

      for path in $LOAD_PATH do ... end

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Model size

      @leedeetee said:

      I am wondering if there is a way to be able to see the size of the various components and items within the model?

      Sort of.

      Assuming you have a train, delete everything but the locomotive. File/Save As ... locomotive.skp. Load again. Delete everything but the caboose. File/Save As ... caboose.skp. And so on.

      File/New. File/Import locomotive.skp. File/Import ... through caboose.skp. After each import, click the origin. Each piece will be a separate component in the completed model. Clicking the origin will reassemble perfectly.

      And each piece will be much friendlier to work with than the 25MB full model.

      Trick: open locomotive.skp. Create a layer named locomotive. Select all. Use Entity Info to move everything into the locomotive layer. Save. When you import, your completed model has a layer named "locomotive" with a single component, also named "locomotive".

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: Aligning the Protractor & Other Tools

      @greentoaster said:

      having the center of the cylinder coaxial with the green or red axis seems impossible.

      For all these problems, drag out a rectangle near, but not touching, your work. Push/pull up to box size. Triple-click, group. Place the thing you want on the appropriate face. Hold the shift key down to lock orientation. Go do your thing. (Works for Circles, Polygons, Rotate tool, Protractor, ...

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: Dumb question - components

      File/Save. Delete everything not in the component you want. If the component is grouped or already a component, explode it.

      File/Save As ... compname.skp

      Reload model. Delete everything in the component. Save.

      File/Import ... compname.skp. It will be turned into a component, named "compname" in your model.

      More generally, build components as freestanding models. Think like a well-organized office manager as you put them into sensible folders with well-chosen names. Then model with lots of File/Imports.

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: New user learning

      SketchUp's worst flaws are discovered by people who want to do non-architectural things. It was designed for architects. (Want to model an elephant? Maybe not a good SketchUp task. Probably will become the next contest here.)

      Plugins come later. Ask "How do I ..." questions here. ("How do I model an elephant?" will get plenty of pachyderm-specific suggestions.)

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: API Docs Comments

      I just posted a comment re the correct args to WebDialog.new(). Do others get it?

      This could be invaluable. The "gotcha" that stabbed you in the back, I read about it instead of also getting stabbed.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Trouble triggering javascript event from sketchup

      Javascript - Advanced event registration models

      favicon

      (www.quirksmode.org)

      ppk's conclusion: don't use addEventListener if you need to support MSIE.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: C != C

      @agamemnus said:

      With the recent Google Chrome's and Firefox's very fast Canvas (graphics) rendering, JS has become even more useful.

      I second that emotion! <canvas> is great. It's just about the most fun you can have in 2D.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Stretching with an offset + stretching on all sides

      @agamemnus said:

      What would you do if you wanted to scale the hull to a certain width/height/length?

      Go with TIG's stuff.

      posted in Newbie Forum
      M
      MartinRinehart
    • RE: Trouble triggering javascript event from sketchup

      @cjthompson said:

      I've edited the top post to reflect the changes you suggested.

      Well, that sure is easier to read. To make it work, try my fourth suggestion. Have preliminary JS put up a big button that says "Start!" or whatever. That button's onclick() calls an action_callback in the Ruby. The action_callback can safely execute_script().

      Another thing I see is the onclick() timing. The click will happen sometime after addButton() has run to completion. message will no longer exist. Move var message = ... outside the function. (No, you really don't have to worry about polluting the global namespace in a WebDialog.)

      Pay attention to thomthom's remarks re attaching code to the event handler.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Trouble triggering javascript event from sketchup

      Some random notes. I bet one of these (no idea which!) fixes the issue.

      1. "document.body" works. No need to look it up.
      2. "setAttribute" has issues. Easier to say "button.id = 'btn1';"
      3. The WebDialog parameters are wrong in the doc. Never tried to use just one. Try (title, scrollable, registryKey, width, height, left, top, resizable). (Set scrollable true. It will always be true on a PC, regardless of this param's value.)
      4. There are timing issues calling execute_script. Put a button in a minimal WD. Click the button to call a Ruby action_callback. execute_script() in the action_callback. (I named this The Bug from Hell. It took me nearly a week to find this out. If you execute_script() before your page is correctly formed, it won't work and you'll get no error. Ugh.)
      5. Style points: This might all be more readable laid out as a Ruby multiline string:
        html = <<eos

      <html> <body>
      <script type='text/javascript'>
      function make_button() {
      button = document.createElement('input');
      button.attr = value;
      button.other_attr = other_value;
      ...
      document.body.appendChild( button )
      }
      </script> </body> </html>

      eos

      @@webDialog.set_html( html )

      Come to think of it, I'm betting on #4.

      posted in Developers' Forum
      M
      MartinRinehart
    • 1 / 1