sketchucation logo sketchucation
    • Login
    1. Home
    2. RunnerPack
    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 1
    • Posts 32
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: Use Ruby To Apply Materials to Spacific Layers

      @eric_erb said:

      ...Thank you so much RunnerPack. You have been a life saver... Now I just gotta read the little book of ruby a few more times (I just finished the second read) last night), and maybe this will finally click. You know I didn't have near the same difficulty learning AS3 or HTML.

      You're quite welcome. (I didn't even do much, really...)

      If you can make sense of ActionScript, I'm confident you'll learn Ruby in short order. Not to brag, but I haven't read any books on Ruby; I just keep the reference docs handy. And those are from Ruby 1.4.6. πŸ˜›

      I guess I just learn better by doing, and Ruby makes that process very fast.

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: Use Ruby To Apply Materials to Spacific Layers

      @bagatelo:

      Ignoring the fact that you hijacked the thread... πŸ˜‰ I suggest you look at the code posted so far, at the code of some related plugins, and at the SketchUp Ruby API docs, and see if you can come up with something that does what you want. Your idea sounds like a simple extrapolation of the code above. If you start your own thread, I and other Rubyists can answer specific questions as you go.

      You may find that you really enjoy programming in Ruby. I certainly do! πŸ˜„

      @honoluludesktop:

      Yes, that would be quite simple. Just change the test for Sketchup::Drawingelement to Sketchup::ComponentInstance and e.layer.name to either e.name or e.definition.name. You might want to put in another test for Groups, too.

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: Use Ruby To Apply Materials to Spacific Layers

      @eric_erb said:

      On Sketchup Load it's returning... undefined method `file_loaded' for main:Object. is there something here I'm supposed to change before I save it to plugins?

      Oops! Put the following line at the top:

      require 'sketchup'
      

      @unknownuser said:

      By the way unless it will crash the script otherwise, there's no need for the script to make sure there's a material that matches the layer name before it runs. Like I said... The Layers are always named the same so when I create materials named after the layer names there will always be a material for each of the layers.

      Well, it's always good coding practice to put in as much error handling as one can. Ideally (though not necessary in this simple script) one should use begin...rescue...end blocks to trap and handle errors in a clean manner. Besides, this script could be handy for others who may not want to make sure every layer has a material, and vice versa, just to keep it from wiping out their already-assigned materials. πŸ˜„

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: Use Ruby To Apply Materials to Spacific Layers

      @eric_erb said:

      The line: su_materials = Sketchup.active_model.materials, I thought that might mean "referance the materials already active in the model", so I created a couple shapes on different layers and applied the materials I wanted to use to those and when I ran the plug-in it actually removed the materials from my new layers, so I guess I interpreted that line wrong.

      No, you interpreted correctly. That is exactly what it means. The only explanation I have for the code removing materials (which I assume means setting them to the default material) is that there is a mismatch between the names of your materials or layers and the contents of your hash.

      My idea would be to skip the hash and just make sure the names of layers and their respective materials are the same. i.e. anything on the "Roof" layer is painted with the material called "Roof", and so on.

      Here's the code for that (which also checks if the material exists before changing it):

      
      module Eric_Erb
      
          def self.paint_by_layer
              mod = Sketchup.active_model
              su_materials = mod.materials
              
              begin
                  mod.start_operation("Paint By Layer", true)
              rescue ArgumentError
                  mod.start_operation("Paint By Layer")
              end
      
              # Loop through entities & apply material based on layer name
              Sketchup.active_model.entities.each do |e|
                  mat = su_materials[e.layer.name]
                  unless mat.nil?
      	            if e.is_a? Sketchup;;Drawingelement then
      	                e.material = mat
      					e.back_material = mat if e.respond_to?('back_material=')
                  	end
                  end
              end
      
              mod.commit_operation
          end
      
      end
      
      unless file_loaded? File;;basename(__FILE__)
          UI.menu('Plugins').add_item('Paint by Layer') { Eric_Erb.paint_by_layer }
          file_loaded File;;basename(__FILE__)
      end
      
      

      (As you can see, I also attached it for downloading.)

      If you do stick with the hash, it may make it easier to edit if you declare it like:

      
      my_materials = {
          "Wall_Surfaces" => su_materials["Roofing_Metal_Standing_Seam_Red"],
          "Roof_Surface" => su_materials["Roofing_Slate_Tan"]
          # .. and so on.
      }
      
      

      Also, when testing, don't paint the objects beforehand. Just make some layers, make a material for each layer with the same name, make a face on each layer, and run the script.

      I hope that helps.


      Paints each entity with a material named after its layer.

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: SU Ruby Cheat-sheet

      Overall, it looks very nice. Thanks for sharing!

      I do see quite a few duplicates, though. Maybe if they were removed it could be printed on fewer sheets.

      BTW, what program(s)/techniques were used to make this?

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: Request - digital watercolor engine

      If you want to manipulate bitmap images from Ruby you should look at ImageMagick and a Ruby interface to it. A quick search on RubyForge found two interfaces to the command-line IM tools (which is the way I would go, for SU) and two wrappers for the IM library itself.

      I'm familiar with IM, but I have no experience with using it from Ruby either in- or outside of the SU Ruby environment. I'd be glad to help you test/experiment with stuff, though (but only in Windows πŸ˜‰).

      Hope that helps

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: [Plugin] Exploded Arc Centerpoint Finder UPDATE May 23, 2013

      Hey, EarthMover,

      It was my request on this Google Group post that (partially?) inspired Chris F. to make his plugin. Using his idea from that discussion, I made code to find the center-point of two Edges... which I promply discarded when he made his implementation that didn't look like a train-wreck πŸ˜†

      So, I took his code (without permission; sorry, Chris! 😳) and made my own tool with a different interface (context menu) that I think adds (some of) the functionality you want. Since you probably wouldn't find it otherwise, here is the thread where I attached mine.

      The readme header in the file also explains how other coders can use the new methods for finding the center of a Curve or of any two Edges. I also wanted to add a radius method and the "convert Curve to ArcCurve" function discussed above, but they're still on the todo list. BTW, my plugin also works on Circles and Polygons.

      posted in Plugins
      RunnerPackR
      RunnerPack
    • RE: [Plugin] Create 3d mesh from construction points... ver 1.3.

      @kirill2008 said:

      BTW can anyone post a sample ruby code shows how to make subclass of SU Point3d class?

      class NewPoint < Geom;;Point3d
      
      def method_name (param)
      #...etc.
      end
      
      #...etc.
      
      end
      

      If you just want to add a new method to the existing class, it's as easy as:

      class Geom;;Point3d
      
      def new_method_name (param)
      #...etc.
      end
      
      end
      

      Isn't Ruby great? πŸ‘

      HTH,
      Amos

      posted in Plugins
      RunnerPackR
      RunnerPack
    • RE: Wrong menu text when it contains forward slashes

      With all due respect to those who have replied, I can and have used slashes in menu items - both in SU plugins and in general Windows development environments. You can check for yourself: open Notepad. At the very bottom of the Edit menu you'll find an item called "Time/Date". AFAIK, the only special character used by Windows menus is the ampersand (&) used to underline the accelerator letter.

      As I stated in my original post, slashes work fine in the Right-click context menu. The problem is the "mirror" context menu that appears as the last item in the Edit menu on the main menu bar.

      I'll concede that it could be something I'm doing wrong, but if so it's an undocumented rule I'm breaking. It seems more likely to simply be a bug in SketchUp (perhaps in the Windows version only; I can't test on a Mac). Either way, I'm not really complaining, I just wanted to point it out. It's an odd bug, but not a deal-breaker.

      BTW, TIG, thanks for the replacement suggestions. I think the "pipe" might work just as well as the commas I switched to.

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: Wrong menu text when it contains forward slashes

      @remus said:

      try putting double slashes instead of singles.

      Didn't help... Here's some other things I've tried:

      # menu.add_item("Draw Curve\/ArcCurve\/Circle Center-point") {
      # slash_workaround = '/'
      # menu.add_item("Draw Curve#{slash_workaround}ArcCurve#{slash_workaround}Circle Center-point") {
      
      

      @remus said:

      Ive got a feeling theyre needed as slashes are ruby operators (or something along those lines) so you need to distinguish them.

      I thought so too at first, but I checked all the Ruby docs I could find and they only mention strings delineated by slashes (regular expressions) but nothing about slashes inside a string. Then I realized that it has to be a bug in SU because it shows up fine in the popup context menu. Plus, I got this from the SU console:

      puts 'Draw Curve/ArcCurve/Circle Center-point'
      Draw Curve/ArcCurve/Circle Center-point
      nil
      

      I've settled on 'Draw Center-point of Curve, ArcCurve, or Circle' until the problem is sorted out. I suppose I should try harder to figure out which of those things is actually selected, but I'm too lazy πŸ‘Š

      BTW, I've attached the plugin. It still might have bugs/quirks... The internal "ReadMe" stuff:

      curve_tools.rb; (C) 2009 Amos Bieler
      ("find_center" method based on code by Chris Fullmer, 
      because my version was ugly ;)
      
      -=_+	Description;
      
      This Ruby code can be useful to both modelers and plugin writers.
      
      -=_+	Modelers;
      
      As a tool for modelers, it is used to draw a construction 
      point at either the center point of a Curve, ArcCurve or 
      Circle entity, or at the point where the perpendiculars of 
      two Edges intersect. The latter effect is handy when an 
      ArcCurve or Circle has been exploded for any reason, such as 
      being Push/Pull'ed.
      
      Usage; Select and context-click on a curve or at least two 
      Edges and select The option ending in the phrase 
      "Center-point" (it changes depending on what is selected).
      
      -=_+	Authors;
      
      As a tool for plugin authors, it adds the "center" and 
      "radius" methods to Curve objects. In SketchUp's standard 
      API, these methods are only available to the ArcCurve class 
      and its derivatives. It also adds a "find_center" method to 
      the Edge class to facilitate the above-mentioned effects.
      
      Usage;
      
      	require 'curve_tools'
      
      	puts curve_object.center.to_s
      	(0.0", 0.0", 0.0")
      	nil
      
      	-or-
      
      	puts edge_object.find_center(other_edge).to_s
      	(0.0", 0.0", 0.0")
      	nil
      
      -=_+	History
      
      2009-08-10 - Initial release
      
      

      Simple, but quite handy...

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • RE: New API doc - typos and questions

      @unknownuser said:

      Point3d.offset (http://code.google.com/apis/sketchup/docs/ourdoc/point3d.html#offset) Description of the length parameter:

      (optional) the distance to offset. If not provided, the offset is my a distance equal to the vector length.

      Suggestion:

      The (optional) offset distance. If not provided, the point is offset a distance equal to the vector's length.

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • Wrong menu text when it contains forward slashes

      I wrote a Ruby script that adds a Context menu item called: "Draw Curve/ArcCurve/Circle Center-point". It appears correctly when the menu is shown by right-clicking or pressing the menu key (between Alt and Ctrl on the right side of a 104-key keyboard) but under "Edit|<Type-and/or-number-of-selected-item(s)> e.g. Edit|Arc" it only shows up as "Circle Center-point".

      I tried putting the string in single quotes and in double-quotes with the forward slashes escaped with back-slashes (restarting SU after each change). There was no change in either menu after either change.

      I'm running the latest free version of SU (7.0.10247) under 32-bit Win XP Pro SP3.

      posted in Developers' Forum
      RunnerPackR
      RunnerPack
    • 1
    • 2
    • 2 / 2