sketchucation logo sketchucation
    • Login
    1. Home
    2. MartinRinehart
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    🚨 Skimp | 25% Off until March 30 Buy Now
    M
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 131
    • Posts 766
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Face pointing towards the camera?

      @thomthom said:

      The result of the dot product can be used to determine if its the front or back side pointing towards the camera.

      t = ph.transformation_at(index) n = picked.normal.transform(t).normalize # global vector orientation c = Sketchup.active_model.active_view.camera.direction m = (c % n > 0) ? e.back_material : e.material

      If the dot product is positive then the backface is facing the camera, otherwise it's the front side.

      Who is ph? Who is picked?

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Mac Help Needed

      @tfdesign said:

      all i get after typing

      Dir::pwd

      is;

      /

      That's it!

      And if you then Dir::chmod( '..' ) and then Dir::pwd do you still look at the single forward slash (root)?

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: WebDialog set_file

      @thomthom said:

      Seems that __FILE__ didn't return an absolute path when you skipped the πŸ˜„ in your path

      Bingo!

      rc2.jpg

      A few more experiments, a Mac answer and then maybe a sensible set_file(). Maybe I won't have to fire myself!

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Face pointing towards the camera?

      @adamb said:

      But thats much more work than a dot product. Your turning an orientation problem into something its not.

      I'm not seeing how a dot product solves the problem. Could you articulate or maybe Sketch something Up?

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: WebDialog set_file

      @chris fullmer said:

      ... I can't stand things installing themselves into my c:\ root. I've come to appreciate the simplicity of knowing that all programs should be installed in the Program Files directory, ...

      I am sure of fewer and fewer things as I get older. Some because I forget, others because I question old certainties. But one thing I hold true:

      Where you put stuff on your computer should always be your choice, not mine.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: WebDialog set_file

      @thomthom said:

      I'm not seeing that.

      Test File: tt_file.rb

      
      > puts __FILE__.inspect
      > puts File.dirname(__FILE__).inspect
      > puts File.split(__FILE__).inspect
      > 
      

      load 'tt_file.rb' "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/tt_file.rb" "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins" ["C:/Program Files (x86)/Google/Google SketchUp 7/Plugins", "tt_file.rb"] true

      Now we're getting someplace! This is what I see:

      rc.jpg

      (When you have to use screen shots to rule out the use of hallucinogenic drugs, you know you've got a problem.) "Tell me what's goin' on - I ain't got a clue!" J. Buffett

      posted in Developers' Forum
      M
      MartinRinehart
    • Mac Help Needed

      I'm trying to write a bit of code that let's the developer access WebDialog's HTML files in locations of your own choice. I need to know what happens as you back up toward and at your root directory.

      If someone could try this:

      In the Ruby Console ask Dir::pwd (*nix for Print Working Directory). That should report something like /foo/bar/moo/baz. Then back up a directory with Dir::chdir( '..' ) and ask Dir::pwd again. (You can use the up arrow in the RC to save retyping.)

      It should report /foo/bar/moo. Done again you should get /foo/bar then /foo, then / and then? Do you get an error or do you just get / again? Or do you get an error before you get this far?

      Thanks ever so much!

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: WebDialog set_file

      @chrisglasier said:

      Excuse me for being a simpleton ...

      I like simple. Simple is good.

      I don't think c:/Program Files/Google/Google SketchUp 7/Plugins/airshow is simple. On my machine the airshow is /models/airshow. I wanted your machine to have /yourchoice/airshow.

      With a little Mac help, we may yet get there.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: WebDialog set_file

      @dan rathbun said:

      I think the problem is the API is not right (or explaining things the way they work.)

      Amen, brother.

      From the console I conclude that the key is "C:".

      File.dirname( ... ) does not return "C:". Absent the "C:" set_file() can't find the file. Adding "C:" myself means there is 0% chance of working on a Mac. Therefore, find_support_file() is a necessity to open an .HTML file in the same directory as the code.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Tool Needed

      @chris fullmer said:

      ...

      Thanks ever so much, Chris! Wrestling the docs to extract "how to get started" is never fun.

      posted in Developers' Forum
      M
      MartinRinehart
    • WebDialog set_file

      Edit 3/1/10:

      A better way to handle the problem (setting an HTML file to the same directory as the Ruby file), that works on Macs and PCs, and works however the Ruby was loaded is this:

      
      pathname = File.expand_path( File.dirname(__FILE__) )
      pathname = File.join( pathname, 'whatever.html' )
      wd.set_file( pathname )
      
      

      The File.expand_path() method returns the full path, back to the root on a Mac or back to the drive on a PC.

      end edit

      Edit:

      To shorten a long story, WebDialog.set_file() requires a drive specification or it won't work on Windows. This little bit of code does the trick:

      
      def fixup( pathname )
      =begin
      On a PC, WebDialog.set_file() requires a drive specification.
      
      47 == '/' ( if working dir starts with '/' you're on a mac )
      58 == ';' ( don't add the directory, if you've already got one )
      dir[0..1] on Windows will be 'C;' or 'D;' or ...
      =end
          dir = Dir;;pwd() # working directory
          pathname = dir[0..1] + pathname unless 
              ( dir[0] == 47 ) || ( pathname[1] == 58 )
          return pathname
      end
      
      
      

      End edit.

      I'm trying to distribute my little movie.

      It uses a WebDialog for a "title" before the movie and another for "credits" after the movie. On my machine these are hard-coded. I want to soft code them.

      The distribution .zip will include .skp files, .html for the dialogs, .rb code, etc. To keep life simple, I want them all to live in a single subdir that viewers can put anywhere convenient on their own machines. A "load /my/dir/airshow.rb" in the Ruby Console gets things started.

      Problem is, I can't open the !@#$ html files with the set_file() method. Here are some things that don't work:

      wd.set_file( 'title.html' ) wd.set_file( File.dirname(__FILE__) + 'title.html' ) wd.set_file( File.dirname(__FILE__) + '/title.html' ) wd.set_file( 'title.html', File.dirname(__FILE__) ) wd.set_file( 'title.html', File.dirname(__FILE__) + '/' ) wd.set_file( File.dirname(__FILE__) + '/title.html', nil )

      I even tried using set_html() but that lost the graphics that are a big part of the title.

      Edit: this works
      pathname = Sketchup.find_support_file( 'title.html', '../../' + File.dirname(__FILE__) + '/' ) wd.set_file( pathname )

      Somebody PLEASE tell me that there's a better way. I've fired people for writing code like that.

      posted in Developers' Forum
      M
      MartinRinehart
    • Tool Needed

      I've yet to write my first SU tool. The time has come, perhaps.

      I want to be able to point to something in my model and have its location returned [r,g,b]. (A tooltip would be nice, in the clipboard would be nicer, both would be great!)

      Is this a good first-time tool? And where does one start?

      Thanks!

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Face pointing towards the camera?

      Sounds complicated. How about:

      ` center = face.bounds.center
      edge1 = camera.eye to center
      edge2 = camera.eye to (center + face.normal)

      edge1 longerThan edge2 ? outside : inside`

      This fails in the special case when camera's line-of-sight is nearly parallel to face's plane.

      posted in Developers' Forum
      M
      MartinRinehart
    • Alternate API, Pioneers Wanted

      Edit: eliminated possible name conflict, movable_ci.rb 2/18

      I've created an alternate API for moving, rotating and scaling. Design goal: eliminate the transformation matrix; let the developer move, rotate and scale directly.

      ` # inst is a ComponentInstance

      movable = MovableCI.new( inst )

      or movable = TransformableCI.new( inst )

      movable.move( Point3d ) # move to point
      movable.move( Vector3d ) # move from current point
      movable.move( [r,g,b] ) # same as by Vector3d
      movable.move( r, g, b ) # same as by Vector3d

      movable.rotate( P3d, plane_or_vector, angle_in_degrees )

      plane_or_vector is one of 'rg', 'gb', 'rb' or [r,g,b]

      movable.scale( [P3d,] global_scale_factor )
      movable.scale( [P3d,] red_scale_factor, green_sf, blue_sf )

      default P3d is the origin`

      The MovableCI is optimized for animation. In a console, use TransformableCI.

      The attached code states that this is documented in Chapter 16 of the tutorial. Until that chapter is finished, this post is the doc. Edit: Chapter 16 is now available.

      I've used the MovableCI heavily to create a little movie. Used a Transformation in just one of over 4k frames.

      I'm creating SketchUp learning materials. If you want to compete with me, please write your own code. Otherwise you can use this as if it were public domain.


      For use in the Ruby Console.


      For use in animations.

      posted in Developers' Forum
      M
      MartinRinehart
    • Instance.move!() and instance.transform!()

      There are two important differences between move!() and transform!().

      The first, which is documented, is that move!() does not record changes on the undo stack.

      The second, which is not documented, is that move!() does not invalidate the view (so does not force immediate redraw).

      This is well-designed and correctly implemented, making move!() ideally suited for use in animations.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Matrix Multiplication in C[++]

      My third screenshot could have been clearer. This is an elaboration:

      12.jpg

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Matrix Multiplication in C[++]

      Blind me? Maybe it was, "Lucky me."

      Transformation * Transformation multiplies the 3x3 rotation/scale matrix. It does not handle location. My code multiplies the 4x4 matrices. Here are the results:

      09.jpg

      xform:
      1.0, 0.0, 0.0, 0.0 0.0, 1.0, 0.0, 0.0 0.0, 0.0, 1.0, 0.0 20.0, 0.0, 0.0, 1.0

      Asked for Transformation.rotation( [0,0,0], [0,1,0], 30 ). Got:

      0.866025403784439, 0.0, -0.5, 0.0 0.0, 1.0, 0.0, 0.0 0.5, 0.0, 0.866025403784439, 0.0 0.0, 0.0, 0.0, 1.0

      Used Transformation * Transformation, then move!().

      10.jpg

      xform:
      0.866025403784439, 0.0, -0.5, 0.0 0.0, 1.0, 0.0, 0.0 0.5, 0.0, 0.866025403784439, 0.0 20.0, 0.0, 0.0, 1.0

      Not my idea of rotating around the origin. So I tried again, using my own matrix multiplication:

      11.jpg

      xform:
      0.866025403784439, 0.0, -0.5, 0.0 0.0, 1.0, 0.0, 0.0 0.5, 0.0, 0.866025403784439, 0.0 17.3205080756888, 0.0, -10, 1.0

      My own version appears to rotate around the origin.

      Anybody wanting to fiddle with this, here's a little Matrix class. You create a Matrix with Matrix.new( nrows, ncols, [array of values] ). From a Transformation, that's Matrix.new( 4, 4, xform.to_a() ). Individual values may be retrieved by subscripting: m1[3,3] is the global scale factor, Wt. You multiply by multiplying: m1 * m2. ( instance_xform * new_xform. It's not commutative.)

      class Matrix
      =begin
      You can multiply one matrix by another with this class.
      
      In m1 * m2, the number of rows in m1 must equal the number of columns in m2. This code does absolutely no checking. Program must check sizes before calling this code! (Application herein; square matrices of equal size, where this is not an issue.) 
      =end
          
          attr_reader ;nrows, ;ncols, ;values
          
          def initialize( nrows, ncols, values )
              @nrows = nrows
              @ncols = ncols
              @values = values
          end # of initialize()
          
          def * ( m2 )
              vals = []
              for r in 0..(@nrows-1)
                  for c in 0..(m2.ncols-1)
                      vals.push( row_col(row( r ), m2.col( c )) )
                  end
              end
              return Matrix.new( @nrows, m2.ncols, vals )
          end # of *()
      
          def [] ( row, col )
              return @values[ row * @ncols + col ]
          end # of []()
          
          def col( c )
              ret = []
              for r in 0..(@nrows-1)
                  ret.push( @values[r*@ncols + c] )
              end
              return ret
          end # of col()
      
          def row( r )
              start = r * @ncols
              return @values[ start .. (start + @ncols - 1) ]
          end # of row()
          
          def row_col( row, col )
              ret = 0
              for i in 0..(row.length()-1)
                  ret += row[ i ] * col[ i ]
              end
              return ret
          end
          
          def inspect()
              ret = ''
              for r in 0..(@nrows-1)
                  for c in 0..(@ncols-1)
                      ret += self[r, c].to_s
                      ret += ', ' if c < (@ncols-1)
                  end
                  ret += "\n"
              end
              return ret
          end # of inspect()
          
      end # of class Matrix
      
      

      Anybody not believing what I say (that included me!) is invited to try for themselves.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Matrix Multiplication in C[++]

      @thomthom said:

      transformation * transformation works.

      The docs says

      @unknownuser said:

      point1
      A Point3d, Vector3d, or Transformation object.

      Blind me! Many thanks.

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Quickly rename layers on several components

      @gaieus said:

      Certainly a plugin would be best

      Gaieus, you do know that my "how to Ruby" section of the tutorial is well underway, don't you? No programming experience required:

      http://www.MartinRinehart.com/models/tutorial/tutorial_11.html

      posted in Developers' Forum
      M
      MartinRinehart
    • RE: Quickly rename layers on several components

      Did you ever program anything in any language?

      You'll need a list of old names and new names. In Ruby array notation (enclose the array with [ and ], enclose the names in quotes and separate array members with commas, like this:

      list = [ ["first_old_name", "replacement_for_it"], ["next_old_name", "next_replacement_name"], ... ]

      Create such a list and you are about 90% done with the project. I, or one of the smart people who inhabit this forum, will help you with the other 10%.

      posted in Developers' Forum
      M
      MartinRinehart
    • 1 / 1