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

    Posts

    Recent Best Controversial
    • RE: Web dialog on a Mac

      Ok,
      I've got it!! I made a few design decisions which should be reasonably documented in the code, but I've enclosed a fully working example below for submitting forms that works on a Mac and a Windows system.

      The example below presents a single form with a radio buttons and checkboxes and after selecting them how you desire and hitting submit all of the settings are sent one by one. To get around the asynchronous/synchronous problem, I essentially have message passing between Ruby and JavaScript to force sending one option at a time (making both Operating Systems act asynchronously) from a options list. It should be quite easy to extend from here.
      

      Here is the HTML/JavaScript Code:

      
      <html>
          <body >
              Multi-Platform WebDialog form submission test<br><br>
      
              <form name="stuff">
                  Favorite Food;<br>
                  <input type="radio" name="food" value="Pizza">Pizza<br>
                  <input type="radio" name="food" value="Hotdogs">Hotdogs<br>
                  <br>Favorite Animals;<br>
                  <input type="checkbox" id="a_cat" value="a_cat">Cat<br>
                  <input type="checkbox" id="a_dog" value="a_dog">Dog<br>
                  <input type="checkbox" id="a_squirrel" value="a_squirrel">Squirrel<br>
                      
                  <input type="button" value="Submit" onclick="sendformdata()">
              </form>
              
              <script>
                  var options = {};   // object that stores all of our settings
                  
                  //Sends a mesage to SU / Ruby
                  function call_ruby( callback_name, message ) {
                      window.location = 'skp;' + callback_name + '@' + message;
                  }
              
                  //Add a checkbox value to the options object
                  function add_checkbox_data(var_str) {
                      if (document.getElementById(var_str).checked) {
                          options[var_str] = "1";
                      } else {
                          options[var_str] = "0";
                      }
                  }
              
                  //Add a radio button value to the options object
                  function add_radio_data(field) {
                      //Get the field data
                      var ps = document.getElementsByName(field);
                  
                      for (var i = 0, length = ps.length; i < length; i++) {
                          if (ps[i].checked) {
                              // store value in our object
                              options[field] = ps[i].value;
                              // only one radio can be logically checked, don't check the rest
                              break;
                          }
                      }
                  }
              
                  //Send a single setting to SU, callbacks will come and get the rest
                  function send_setting()
                  {
                      var size = 0, key;
                      var seting, value;
                      
                      for (key in options) {
                          if (options.hasOwnProperty(key)) size++;
                      }
                      
                      if (size > 0) {
                          for (setting in options) break; // Get the first setting
                          value = options[setting];
                          delete options[setting];
                          call_ruby(setting, value);
                      } else {
                          call_ruby("submit", 1);
                      }
                  }
              
                  function sendformdata()
                  {
                      add_radio_data("food");
                      
                      //The checkbox options all have unique names to simplify storage in 'options' receipt at the SU end (more callback handlers needed though)
                      //Could have concatenated all check options into a string, sent them as a single submit and parsed the string at the SU end too
                      add_checkbox_data("a_cat");
                      add_checkbox_data("a_dog");
                      add_checkbox_data("a_squirrel");
                      
                      //Send the first setting to SU, the callbacks will get the rest
                      send_setting();
                  }
      
              </script>
          </body>
      <html>
      
      

      Here is the Ruby Code:

      
      @d = nil
      @d = UI;;WebDialog.new("Test", true, "", 800, 800, 200, 200, true)
      
      htmlset = File.join( File.dirname(__FILE__), "test.html" )
      @d.set_file( htmlset )
      
      #set the callback for the radiobuttons
      @d.add_action_callback('food') { |dialog, params|
          puts '>> Food; ' + params
          @d.execute_script('send_setting();')    #check for more settings to send
      }
      
      @d.add_action_callback('a_cat') { |dialog, params|
          puts '>> Animal; Cat - ' + params
          @d.execute_script('send_setting();')    #check for more settings to send
      }
      
      @d.add_action_callback('a_dog') { |dialog, params|
          puts '>> Animal; Dog - ' + params
          @d.execute_script('send_setting();')    #check for more settings to send
      }
      
      @d.add_action_callback('a_squirrel') { |dialog, params|
          puts '>> Animal; Squirrel - ' + params
          @d.execute_script('send_setting();')    #check for more settings to send
      }
      
      #Make the window persistant on top of SU
      RUBY_PLATFORM =~ /(darwin)/ ? @d.show_modal() ; @d.show
      
      

      Thanks to all for the advice along the way.

      Sincerely, Paul

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Web dialog on a Mac

      Thanks for the replies Dan,
      I'm still having issues, but I'll keep tinkering =P.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Web dialog on a Mac

      All,
      I'm still having trouble despite reading the articles and trying to incorporate the advice recommended. Most of the 'examples' seem to stop at demonstrating that the behavior is different between operating systems. I just want to have a form send back it's data. I'm presuming that this is to do with the asynchronicity on the Mac. The submit button in the form doesn't run make it back to Ruby at all and the normal button works for one option, but not multiple options.

      Here is the Ruby example code:

      @d = nil
      @d = UI;;WebDialog.new("Test", true, "", 800, 800, 200, 200, true)
      
      htmlset = File.join( File.dirname(__FILE__), "test.html" )
      @d.set_file( htmlset )
      
      #set the callback for the radio buttons
      @d.add_action_callback('food') { |dialog, params|
          puts '>> Food; ' + params
          @d.execute_script('send_radio_data();')    #return control back to JS?
      }
      
      @d.add_action_callback('animal') { |dialog, params|
          puts '>> Animal; ' + params
          @d.execute_script('send_radio_data();')    #return control back to JS?
      }
      
      RUBY_PLATFORM =~ /(darwin)/ ? @d.show_modal() ; @d.show
      

      Here is the HTML example code:

      <html>
          <body >
              Multi-Platform WebDialog form submission test<br>
              
              <form name="stuff" onsubmit="submitbutton();" method="post">
                  Favorite Food;<br>
                  <input type="radio" name="food" value="Pizza">Pizza<br>
                  <input type="radio" name="food" value="Hotdogs">Hotdogs<br>
                  Favorite Animal;<br>
                  <input type="radio" name="animal" value="Cat">Cat<br>
                  <input type="radio" name="animal" value="Dog">Dog<br>
                              
                  <input type="button" value="Submit by Button" onclick="buttonpress()">
                  <input type="submit" value="Submit by Submit">
              </form>
              
              <script>
                  function call_ruby( callback_name, message ) {
                      location = 'skp;' + callback_name + '@' + message
                  }
              
                  function send_radio_data(field) {
                      //Get the field data
                      var ps = document.getElementsByName(field);
                  
                      for (var i = 0, length = ps.length; i < length; i++) {
                          if (ps[i].checked) {
                              // Send the value back to SketchUp
                              call_ruby(field, ps[i].value);
                              // only one radio can be logically checked, don't check the rest
                              break;
                          }
                      }
                  }
              
                  function sendformdata()
                  {
                      send_radio_data("food")
                      send_radio_data("animal")
                  }
              
                  function buttonpress()
                  {
                      alert("Doing Button Press Send");
                      sendformdata();
                  }
              
                  function submitbutton()
                  {
                      alert("Doing Submit send")
                      sendformdata()    // Never gets ran
                  }
              
              </script>
          </body>
      <html>
      

      If someone could put me out of my misery and help me correct this it would be much appreciated.

      Sincerely, Paul.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Web dialog on a Mac

      Thanks for the feedback,
      I'll try some of your ideas. I did know about the unload, but thought I'd taken care of that with a message back to ruby to let it know the DOM was loaded.

      Paul.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • Web dialog on a Mac

      Hi,
      I have a plug-in I wrote working on Windows system, but have received feedback that is doesn't work on a Mac. I've borrowed a Mac and confirmed that the Web Dialog doesn't send the message back to the Ruby script. I tried a basic example (showing the console from a web dialog) and this also failed.

      I am new to using a Mac so I don't know if there is some option you need to set to permit web dialogs to operate? There doesn't appear to be any differentiation in the coding documentation required between the Operating Systems or their respective browsers.
      
      I assume this is a pretty basic fix, but can't seem to find the answer yet.
      

      Help appreciated. Happy Holidays.

      Paul.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Intersect_line_line question

      Ah,
      Good point sl. I used a similar test for a line-plane intersection test.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Intersect_line_line question

      Not the most mathematically efficient I think, but this will do for now...

      Redirecting to Google Groups

      favicon

      (groups.google.com)

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Intersect_line_line question

      Thanks again Dan,
      I'll see what I can come up with =).

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Intersect_line_line question

      Thanks Dan,
      That makes sense. I see that the way the function operates however isn't what I was after. The function as it stands turns the lines into infinite rays defined by the line's two points and then checks if the infinite rays intersect. I just want to check if the line segments bounded by the pairs of points intersect.

      I'm muddling through implementing this now, unless you know of an existing coded examples. There are 5 cases to check for
      
      1. Parallel Lines
      2. Normal Intersection within line segments
      3. Intersection, but outside limits defined by line segment points
      4. No intersection at all
      5. Lines are coincident (intersection is a line, not a point)

      Sincerely, Paul.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • Intersect_line_line question

      Hi,
      I'm having trouble with Geom.intersect_line_line not giving the expected results so I was hoping someone could either tell me what I'm doing wrong or that the function is bugged so I know whether to rewrite it.

      According to the documentation in the API

      @unknownuser said:

      Geom.intersect_line_lineSketchUp 6.0+
      The intersect_line_line computes the intersection of two lines.

      Arguments:

      line1
      The first line to intersect.
      line2
      The second line to intersect.
      Returns:

      point
      The intersection point. Returns nil if they do not intersect.
      line1 = [Geom::Point3d.new(10,0,0), Geom::Vector3d.new(1,0,0)]
      line2 = [Geom::Point3d.new(0,10,0), Geom::Point3d.new(20,10,0)]
      pt = Geom.intersect_line_line(line1, line2)

      This will return the point (10,10,0).

      If you type in their example into the Ruby editor it doesn't actually work as advertised, it returns nil.

      Here is an example of two parallel lines returning a value...

      l1 = [[0,0,0], [10,0,0]]
      [[0, 0, 0], [10, 0, 0]]
      l2 = [[0,5,0], [10,5,0]]
      [[0, 5, 0], [10, 5, 0]]
      i = Geom.intersect_line_line(l1, l2)
      Point3d(-10, 0, 0)
      

      Thoughts?

      Sincerely, Paul.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • [Plugin] Geodesic Dome Creator 0.2.0

      Just finished an update and thought I'd share

      https://sites.google.com/site/sugeodesic/home

      New Features

      • Spherical Hubs

      • Cylindrical Struts Point option for Hub Centers (Platonic solid vertices)

      • Improved Menu System

      • Material Selector for faces, struts and hubs (requires SKMTools)

      Fixes

      • Tetrahedron fix (Issue 😎

      • Duplicate Hub/Struts (Issue 1)

      • Resulted in approximately 6.5% speed improvement of generation time

      • Fraction option now works (Issue 9)

      Improvements

      • Sphere hubs are now components (still need to do cylindrical hubs)

      I tested it on older versions of SketchUp, but I'm still curious to see how the new menu system works for people that use older setups.

      Full Sphere.png

      Glass Dome 2.png

      Wood 5F 5_8 Dome.png

      Regards, Sketchy...

      posted in Plugins
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Assigning Textures

      Thanks Jolran,
      You're right that was a short coming in logic, but it was making it into the 'if' anyway. The issue is you can only use .texture to load images, not skm's. TIG wrote a module to extract a .skm and return the texture within so I'm currently integrating that library.

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Assigning Textures

      Hmmm,
      I included your advice and it still does not work. I also tried hardcoding a path (without spaces in case that was it) and it wasn't. The .nil check below is failing

      			dialog.add_action_callback("face_material") { |dlg, msg|
      				filepath = msg
      				if File.exists?(filepath)
      					puts filepath
      					filepath = msg.gsub('\\','/')
      					puts filepath
      					@face_material.texture = "C;/a.skm"
      					if (@face_material.texture.nil?)
      						puts "No worky..."
      					end
      					puts @face_material.texture
      				end
      			}
      

      Any ideas as to why I can't assign a path...?

      Reference posts....
      http://sketchucation.com/forums/viewtopic.php?f=180&t=3100
      http://www.thomthom.net/thoughts/2012/03/the-secrets-of-sketchups-materials/

      Update:
      https://groups.google.com/forum/#!msg/sketchupruby/0St9qMVnro4/TtcTfhOsbHoJ
      Apparently you can't add .skm's directly...
      http://sketchucation.com/forums/viewtopic.php?f=180&t=32643

      Now to find SKMTools... http://sketchucation.com/forums/viewtopic.php?f=180&t=33079

      Ok, SKMTools installed....now windows permissions issues in the plug-in directory that SKM needs for temporary writing..... fun night πŸ˜ƒ

      Most frustrating... Sketchy

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Assigning Textures

      Thanks a lot for the feedback Dan πŸ˜ƒ

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • Assigning Textures

      Hi,
      I'm trying to assign textures (the standard ones), but I'm having a bit of trouble as it just shows up as black faces and was hoping for some direction...

      In the initialization stage of my class I create a new material as follows;

      			@face_material = Sketchup.active_model.materials.add "face_material"
      

      I receive my path from my web dialog with this bit of code

      			dialog.add_action_callback("face_material") do |dlg, msg|
      				filename = msg
      				if File.exists?(filename)
      					@face_material.texture = filename
      					puts @face_material.texture
      				end
      			end
      

      Here is the output of the 'puts' statement so I can tell I'm getting the path ok.

      @unknownuser said:

      C:\Program Files (x86)\SketchUp\SketchUp 2013\Materials\Translucent\Translucent_Glass_Tinted.skm

      If I check the face material texture I get nil back so I'm guessing this means that the assignment failed. Is there something about needing say no spaces in the name or needing to double backslash \ the path?

      I create the face and assign the front and back sides with the material

      							face = @geodesic.entities.add_face @primitive_points[p_num - order], @primitive_points[p_num - order - 1], @primitive_points[p_num]	
      							face.material = @face_material
      							face.back_material = @face_material
      

      This face turns out to be black instead of what I picked. I've read a few articles on the subject, but can't find my mistake.

      Sincerely, Sketchy...

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Creating Bump Map / Height Maps

      Thanks for the responses.
      The Bitmap to mesh is exactly what I was looking for =). The other is for exporting, but still looks pretty useful.

      Thank you.

      posted in Plugins
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • Creating Bump Map / Height Maps

      Question,
      Is there a way to create Height Maps with the Free version of Sketchup, a plug-in perhaps? I've done some searching and it seems everyone uses a combination of tools and other tricks. I hear SU Pro may have it native?

      If there isn't one I might just write my own for something I'm tinkering with, but it would be nice to save the time.
      

      Thoughts?

      Sketchy.

      posted in Plugins
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Geodesic Dome Plugin

      All,
      I need your help to check which of the two interfaces has the best compatibility before I release the next version. Enclosed you will find two versions (they can co-exist together). Both have implementations of an accordion interface.

      The "black" version, is a customized accordion and this is really all this interface is focused on. It has an animated opening of sections with a bounce as the section expands. This is the prettier of the two, but is a one trick pony.
      

      Clipping of Black Interface

      Interface based on Prototype and Scriptalicious

      The "white" version, is build on a whole platform of cool gadgets I could use for other interface niceties. Their accordion does an instantaneous open so it isn't as sexy as my black variant.
      

      Interface based on Bootstrap

      Clipping of White Interface
      There will be slight differences in font size / color etc., but ignore these. The same with the color difference, its just to tell them apart (but I like the black coloring =P) I'm purely interested in whether the accordion works (sections slide open as you click on them) and whether it will generate ok (default settings are fine). If they are both broken, I'll be stopping at the liquor store instead of StarBucks this afternoon.

      If you have any issues, please tell me your Operating System and SketchUp version. Hopefully I'll get the next version released shortly.
      

      Sincerely, Sketchy.

      posted in Plugins
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • RE: Transformation.rotation help

      You can see how it is wrong....

      blah.png

      Here is the code....

      
      						p = Geom;;Point3d.new([0, 0, 0])    #Point of rotation	
      						
      						#Create a copy, but don't move it (it needs rotating first
      						trans = Geom;;Transformation.translation([0,0,0])
      						new_hub = @geodesic.entities.add_instance hub_def, trans
      						
      						#Create a vector pointing up the Z axis
      						z_vec = Geom;;Vector3d.new [0, 0, 1]
      						
      						#Turn our target point into a vector
      						cv = Geom;;Vector3d.new c[0], c[1], c[2]
      						
      						#Get the angle between the Z-axis and the vector
      						angle = z_vec.angle_between cv
      						
      						#Create a rotation transform and rotate the object
      						r1 = Geom;;Transformation.rotation(p, cv, angle)
      						new_hub.transform!(r1)
      						
      						#Translate to final destination
      						t = Geom;;Transformation.translation(c)
      						new_hub.transform!(t)
      
      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • Transformation.rotation help

      Hi,
      I can't get this to work quite right so I was hoping for some insight. The Transformation.rotation is a bit light on documentation in the API.

      @unknownuser said:

      Transformation.rotationSketchUp 6.0+
      The rotation method is used to create a Transformation that does rotation about an axis.

      The axis is defined by a point and a vector. The angle is given in radians.

      Arguments:

      point
      A Point3d object.
      vector
      A Vector3d object.
      angle
      A numeric value, expressed in radians, that specifies the angle to rotate about the axis set by the second parameter.
      Returns:

      transformation
      a new Transformation object

      From what I understand the point will be in 3D, but the Vector has to only contain 1 Dimension (i.e. the axis you'll be rotating around such as [0,0,1] or [1,0,0]).

      What I want to do is rotate to a vector in 3D, which is essentially 2 successive rotations around axes such as y then x. The problem is that the two rotations that equal my 3d vector's direction don't lead to a correct rotation, but if I do only one of the rotations each seems correct for its respective axis.

      I have a feeling I may need to just enter my own transformation matrix, but I was hoping I could just do it with existing commands...thoughts?

      To make it a bit clearer here is an image. I want to rotate and translate an object from a point (origin in this case) to the end of a vector. This requires a rotation in two planes and a translation...
      rotation.png

      You can do the rotations with one operation in SU so I'm presuming I'm just missing something...

      Sketchy..

      posted in Developers' Forum
      s_k_e_t_c_h_yS
      s_k_e_t_c_h_y
    • 1 / 1