sketchucation logo sketchucation
    • Login
    1. Home
    2. rvs1977
    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!
    ⚠️ Important | Libfredo 15.6b introduces important bugfixes for Fredo's Extensions Update
    R
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 16
    • Posts 53
    • Groups 1

    Posts

    Recent Best Controversial
    • RE: EntitiesObserver and Attributes - work around

      When a wall is resized I want the walls area-attribute to update. Thats basically what Im trying to do.

      Great to know that SU8 might work.

      About using put, I dont know how to use it? Is it possible to use it with Alex Screyers Ruby Editor? I have tried without any output. Im interested to know more about Win32Api. Is it something I need to download?

      posted in Developers' Forum
      R
      rvs1977
    • EntitiesObserver and Attributes - work around

      Hi!
      Im trying to figure out how to use the add_observer method on the entities in a group, and saw TTs list (url below)
      http://www.thomthom.net/software/sketchup/observers/#ViewObserver

      Here my worst nightmare came through... The Sketchup::EntitiesObserver - onElementModified(entities, entity) dont work. Just as I had experienced myself.

      What I try to accomplish (see the code below), is to keep track of the area of a specific face, named yv_face_area (green color). Initially I have set an attribute to the rsgroup (which contains the yv_face_area) set_attribute("rsdict, "area", area). It seems to work fine.

      But, as mentioned, the onElementModified method dont seems to work.

      Anyone haves an idea how to work around this problem?

      snippet:

      
      mod = Sketchup.active_model # Open model
      ent = mod.entities # All entities in model
      sel = mod.selection # Current selection
      
      class MyEntityObserver < Sketchup;;EntityObserver        
          def onEraseEntity(entity) #this work        
              UI.messagebox("onEraseEntity; " + entity.to_s)        
          end  
      end #class
      
      class MyEntitiesObserver < Sketchup;;EntitiesObserver        
          def onElementModified(entities, entity) #dont seems to work    
              UI.messagebox("onElementModified; " + entity.to_s)  
          end
          def onEraseEntities(entities) #this seems to work    
               UI.messagebox("onEraseEntities; " + entities.to_s)  
          end
          def onElementRemoved(entities, entity_id) #dont seems to work    
              UI.messagebox("onElementRemoved; " + entity_id)  
          end
          def onElementAdded(entities, entity) #this seems to work   
              UI.messagebox("onElementAdded; " + entity.to_s)  
          end
      end #class
      
      pts = []
      
      pts[0] = [ 0, 0, 0]
      pts[1] = [ 1000.mm, 0, 0]
      pts[2] = [ 1000.mm, 1000.mm, 0]
      pts[3] = [ 0, 1000.mm, 0]
      
      pts[4] = [ 0, 0, 1000.mm]
      pts[5] = [ 1000.mm, 0, 1000.mm]
      pts[6] = [ 1000.mm, 1000.mm, 1000.mm]
      pts[7] = [ 0, 1000.mm, 1000.mm]
      
      5.times do |i|
          rsgroup = ent.add_group
          
          rsgroup.entities.add_face pts[0..3]
          yv_face_height = rsgroup.entities.add_face pts[4..7]
          rsgroup.entities.add_face pts[0], pts[3], pts[7], pts[4]
          rsgroup.entities.add_face pts[3], pts[2], pts[6], pts[7]
          rsgroup.entities.add_face pts[1], pts[2], pts[6], pts[5]
          yv_face_area = rsgroup.entities.add_face pts[0], pts[1], pts[5], pts[4]
          
          yv_face_height.pushpull rand(1000.mm)
          yv_area = yv_face_area.area.to_m.to_m
          yv_face_area.material = (0xAADEAA)    
          rsgroup.set_attribute "rsdict","area", yv_area
          yv_face_area.set_attribute "rsdict", "area2", yv_area
              
          point = Geom;;Point3d.new (1100.mm * i, 0, 0)
          t = Geom;;Transformation.new point
          rsgroup.transform! t
          
          rsgroup.add_observer(MyEntityObserver.new)
          rsgroup.entities.add_observer(MyEntitiesObserver.new)
          
          
      end #times_do
      
      ent.each do |o|
          point = Geom;;Point3d.new (0, 1100.mm, 0)
          t = Geom;;Transformation.new point
          o.transform! t
      end #each_do 
      
      i = 0
      ent.each do |o|
          attr = o.get_attribute "rsdict","area" 
      
          if attr        
              UI.messagebox "Attr - Area; " + attr.to_s + " mΒ² - n; " + i.to_s       
              i = i + 1
          end
      end
      
      
      posted in Developers' Forum
      R
      rvs1977
    • RE: Creating new variables in for-loop?

      Ok thank you Dan. I will try that. πŸ˜„

      posted in Developers' Forum
      R
      rvs1977
    • RE: Creating new variables in for-loop?

      yes, I thought about but Im unsure how to do it.

      
      face_array = Array.new(loop_length,Hash.new)
      
      for i in 0..(loop_length-1)
          face_array[i][@yv_group_i] = Sketchup.active_model.entities.add_group
          face_array[i][@yv_face_i]  = @yv_group_i.entities.add_face (@pts[1+(i*4)], @pts[2+(i*4)], @pts[3+(i*4)], @pts[4+(i*4)]) 
      end
      
      

      Something like that...??

      posted in Developers' Forum
      R
      rvs1977
    • Creating new variables in for-loop?

      Hi!

      Is it possible to create new variables in a for-loop?

      Now I have something like this, which works:

      
      loop_length = 3
      
      for i in 0..(loop_length-1)
        if (i == 0)
          @yv_group0 = Sketchup.active_model.entities.add_group
          @yv_face0 = @yv_group0.entities.add_face (@pts[1], @pts[2], @pts[3], @pts[4]) 
        end
      
        if (i == 1)
          @yv_group1 = Sketchup.active_model.entities.add_group
          @yv_face1 = @yv_group1.entities.add_face (@pts[5], @pts[6], @pts[7], @pts[8]) 
        end
       
        if (i == 2)
          @yv_group2 = Sketchup.active_model.entities.add_group
          @yv_face2 = @yv_group2.entities.add_face (@pts[9], @pts[10], @pts[11], @pts[12]) 
        end
      end
      
      

      I think it would be smarter if it was possible to create new variabels in the for-loop, like:

      
      for i in 0..(loop_length-1)
        
          @yv_group_i = Sketchup.active_model.entities.add_group
          @yv_face_i  = @yv_group_i.entities.add_face (@pts[1+(i*4)], @pts[2+(i*4)], @pts[3+(i*4)], @pts[4+(i*4)]) 
      end
      
      

      As you can see, I would like to try to put the i on the variables.
      Is that possible in some way?? πŸŽ‰

      -Rasmus

      posted in Developers' Forum
      R
      rvs1977
    • RE: Webdialog - trouble passing array from JS to Ruby

      ah ok πŸ˜„

      Anyway, it finally works with this "simple" solution:

      
      my_dialog.add_action_callback("get_array") do |web_dialog,yv_array|
      @YV_array = yv_array.scan(/\d+/).collect {|d| d.to_i}
      end
      
      

      I wonder why the eval-rescue solution has to be avoided? Is it slow?

      Thanks to all of you. - Aerilius, Dan, Thomthom


      Gratias Ad Omnes

      posted in Developers' Forum
      R
      rvs1977
    • RE: Webdialog - trouble passing array from JS to Ruby

      Aerilius, Im a little impressed.

      When you quote my code, you use different variable-names than the ones from my example.
      The funny thing is, the variable-names you use is the one I actually use on my own computer, before I started to look at arrays... Are you psychic or something?? πŸ˜„

      posted in Developers' Forum
      R
      rvs1977
    • RE: Webdialog - trouble passing array from JS to Ruby

      Thank you all!! Now I have something to try out. πŸ˜„

      posted in Developers' Forum
      R
      rvs1977
    • Webdialog - trouble passing array from JS to Ruby

      hi!

      I have a problem passing array from Webdialg (Javascript) to Ruby.

      Htmlfile.html

      
      <script>
      var layer_array = [108,190,95];
      query = 'skp;get_array@' + layer_array;
      window.location.href = query;
      </script>
      
      

      Rubyfile.rb

      
      my_dialog.add_action_callback("get_array") do |web_dialog,yv_array|
      UI.messagebox "YV_array from callback action; " + yv_array
      end
      
      

      In the html/js file its possible to do like this:
      alert("first item: " + layer_array[0]);
      => Output: "first item: 108"

      Or if I do like this:
      alert("all items: " + layer_array);
      => Output: "all items: 108,190,95"

      Every things work fine!

      But, when its send back to ruby the trouble starts:
      If I write:
      UI.messagebox ("first item: " + layer_array[0])
      => Output: "first item: 57"

      But if I write:
      UI.messagebox ("all items: " + layer_array)
      => Output: "all items: 108,190,95"
      Here it seems to work???

      My guess is when its send from JS to Ruby it goes from being an array to be a string?

      Anyone know how to overcome this problem?

      -Rasmus

      posted in Developers' Forum
      R
      rvs1977
    • RE: [??] How to pass a variable from main.rb to a boxtool

      Finally it works!!... πŸ˜„

      BUT I had to move the rs_main.rb from the "\Plugins\as_plugins\as_rubyeditor\snippets"-folder to the "\Plugins"-folder, and then restart SU. At start up it showed the Alertbox "Helle World".

      BUT It won't work if I use the playbutton in AS-code editor. It seems like, when using modules, it has to be loaded into SU at startup.

      I wonder if there is a way to come around this?

      EDITED 1: It can be run directly from the snippet folder with ruby console (then SU requires no restart):
      load 'c:\path to the program\Google SketchUp 7\Plugins\as_plugins\as_rubyeditor\snippets\rs_main.rb'

      EDITED 2: in rs_main.rb require is changed to load. Then it updates the variables when its changed.

      So far so good! Thank you...

      posted in Developers' Forum
      R
      rvs1977
    • RE: [??] How to pass a variable from main.rb to a boxtool

      @dan rathbun said:

      BTW.. did you install the full Ruby version ??
      Ruby (v1.8.6-p287) Windows One-Click Installer

      When you do.. you will have the full CHM file for
      "Programming Ruby - The Pragmatic Programmer's Guide, 1st Ed."
      in your "C:/Ruby186/doc" directory.

      No I havn't. But I will πŸ˜„

      posted in Developers' Forum
      R
      rvs1977
    • RE: [??] How to pass a variable from main.rb to a boxtool

      I get the point using namespaces, so I decided to find out how module works by making the simpelts possible example... and it dont work πŸ˜•

      Again with 2 files:

      • rs_main.rb, and
      • rs_moduletest.rb

      From rs_main.rb I call a method defined inside rs_moduletest.rb. The method then should write in a messagebox "Hello World".

      rs_main.rb:

      module RVS; end
      module RVS;;MyPlugin 
      
          # declare module vars and constants first
          @@myHelloVar = 'Hello World'
          
          
          # require other parts of this plugin;
          require('as_plugins/as_rubyeditor/snippets/rs_moduletest.rb')
          
          # main plugin script, menu items, etc.
          MyPlugin.test() # Calling the test-method from rs_moduletest.rb
      
      end #module RVS;;MyPlugin 
      

      rs_moduletest.rb

      module RVS;;MyPlugin 
      	public
      	def self.test ()
      		UI.messagebox @@myHelloVar 
      	end
      	
      end #module RVS;;MyPlugin 
      

      how should this be written to work?

      posted in Developers' Forum
      R
      rvs1977
    • RE: [??] How to pass a variable from main.rb to a boxtool

      First of all, thank you for all the answers. Its really helpful.

      Even though its a little abstract to me right now, I know which direction to go. I belive the answer is using an author module. I will try to find out the difference between module and class

      posted in Developers' Forum
      R
      rvs1977
    • [??] How to pass a variable from main.rb to a boxtool

      Hi β˜€ !

      I have 2 files:

      • main.rb, and
      • rs_boxtool.rb

      I would like to pass a variable from main.rb to rs_boxtool.rb, setting the size of the box. The idea is to use @boxheight as a variable. Is that possible?

      main.rb:

      require ('as_plugins/as_rubyeditor/snippets/rs_boxtool.rb')
      @boxheight = 100 # It's a variable inside the tool, but it dont work!
      boxtool = BOX_tool.new
      Sketchup.active_model.select_tool boxtool
      

      rs_boxtool.rb:

      class BOX_tool
        def initialize
          @mod = Sketchup.active_model 
          @ent = @mod.entities 
          @view = Sketchup.active_model.active_view
         
          @state = 0
          inches = 1
          @mm = inches.to_mm
          
          #@boxheight = 1800/@mm # --> This sould be accessed from the rs_boxcall.rb file
      
           #---box def.start---
           @pts = []        
           @pts[0] = [0,0,0]
           @pts[1] = [0,0,@boxheight]
           @pts[2] = [0,@boxheight,@boxheight]
           @pts[3] = [0,@boxheight,0] 
                     
           #---box def.slut---  
        end
      
        def activate 
           
        end 
      
        def onMouseMove(flags, x, y, view) 
           
           if (@state == 0) # Create box_group
             ip = Sketchup;;InputPoint.new
             ip.pick view, x,y
             ip = ip.position 
       
            @yv_group =Sketchup.active_model.entities.add_group
            @yv_face1 = @yv_group.entities.add_face (@pts[0], @pts[1], @pts[2], @pts[3]) # basis side
                
            point = Geom;;Point3d.new ip 
            new_transform = Geom;;Transformation.new point  
            @yv_group.transformation = new_transform
            @state = 1
          end
      
          if (@state == 1) # box follow mousemove
            ip = Sketchup;;InputPoint.new
            ip.pick view, x,y
            ip = ip.position       
            
            Sketchup.status_text = "@state = 1 ; Inputpoint; ", ip 
            point = Geom;;Point3d.new ip 
            new_transform = Geom;;Transformation.new (point)
            @yv_group.transformation =  new_transform
          end
      
          if (@state == 2) # onLMouseButton place boxgroup in choosen position
            ip = Sketchup;;InputPoint.new
            ip.pick view, x,y
            ip = ip.position 
            ip = ip.x-0.1/@mm, ip.y , ip.z
      
            Sketchup.status_text = "@state = 2 ; Inputpoint; ", ip 
            point = Geom;;Point3d.new ip 
            new_transform = Geom;;Transformation.new (point)
            @yv_group.transformation = new_transform
            @ip1 = ip
            @state = 3
                       
          end   
        def onLButtonDown(flags, x, y, view)
          if (@state == 3)
             self.reset
          end
      
          if (@state == 1)
            @state = 2
          end
        end # onLButtonDown
      
      end
      
        def reset
          @state = 0
        end
      end # class BOX_tool
       
           #boxtool = BOX_tool.new 
           #Sketchup.active_model.select_tool boxtool
      

      Thanks in advance.

      -Rasmus

      posted in Developers' Forum
      R
      rvs1977
    • RE: New API doc - typos and questions

      Hmm... found a solution.

      When I press Methods Index in the menu it opens "https://developers.google.com/sketchup/docs/methods?hl=da"

      I tried to delete ?hl=da so it only said: "https://developers.google.com/sketchup/docs/methods"

      Then it works.

      posted in Developers' Forum
      R
      rvs1977
    • RE: [Question]how to load a tool from an external .rb file

      Thank you Dan. It worked β˜€

      I have started to go through the Ruby Resource as you suggested. And I also found the answer for my own question in there. πŸ‘

      posted in Developers' Forum
      R
      rvs1977
    • [Question]how to load a tool from an external .rb file

      Hi All πŸ˜„

      Once I made a simple linedrawing tool, capable of drawing straigt lines.
      Its saved in a file called mylinetool.rb in \Plugins\as_plugins\as_rubyeditor\snippets

      The question is, how do I make a small rubyscript that loads and runs the tool from Alex Schreyers Ruby Code Editor?

      Is it something like "load_file", "include" or "load(filename)"??

      Can it be loaded from a URL? eg. http://www.google.com/mylinetool.rb

      thanks in advance

      -Rasmus

      posted in Developers' Forum
      R
      rvs1977
    • RE: New API doc - typos and questions

      Hi!

      Under Quick References --> Method Index it will only load from "Symbol, A, B, C, D to E"... not any further.

      I have the same problem in I.E. and Chrome... for more than a week now.

      posted in Developers' Forum
      R
      rvs1977
    • RE: [Q] on mouse over component - boundingbox lightup

      Hi Chris

      Thank you so much!

      This is exactly what I was looking for. Once again this forum has helped me out! β˜€
      I'm trying to make a wall tool, and have an idea that this will be very usefull.

      -Rasmus

      posted in Plugins
      R
      rvs1977
    • [Q] on mouse over component - boundingbox lightup

      Greetings out there... β˜€

      I'm trying to make a snippet where a component's bounding box lights up, when the mouse is pointing at the object. I have looked around for a while at different classes, for instance the oberserver class and the UI class - pickhelper, but nothing seems to do the job.

      Can anyone tell me in which direction to look, or even better show me a rubyexample I can look in?

      thx in advance ❗

      -Rasmus

      posted in Plugins
      R
      rvs1977
    • 1 / 1