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

    Posts

    Recent Best Controversial
    • Ruby Console utility

      Whilst searching around for information about Ruby in SU I remember seeing details of a plug-in or ruby script which added some functions to the Ruby Console to make script testing easier - but now I can't seem to find it.

      Has anyone seen this anywhere?

      posted in Developers' Forum
      E
      ezt
    • RE: I'm getting there - but need some help.

      It's so easy when you know how. πŸ˜‰

      Thanks again Todd.

      posted in Developers' Forum
      E
      ezt
    • RE: I'm getting there - but need some help.

      Thanks again Todd.

      You have saved me a lot of time trying to get this far.

      @unknownuser said:

      A few other helpful pointers...

      I quickly tried to modify the script to take these comments in to account, and I somehow ended up breaking the script. I'll have another look at this later when I have some time, but I have about 15 other scripts I have done, similar to the one I posted here, for other types of cabinets, and I need to press on an incorporate the changes for grouping in those first.

      One question though.

      In the global grouping you said to use

      @unknownuser said:

      overall_group = Sketchup.active_model.entities.add_group( left_side_group, right_side_group, bottom_group )

      This works well enough, but can you just clarify what name is given to this group?
      From what I can figure, it has no name. If that's the case, can I somehow give the overall group the same name as was input for the Cabinet Code?

      posted in Developers' Forum
      E
      ezt
    • RE: I'm getting there - but need some help.

      @unknownuser said:

      To create a group with stuff in it, code:
      stuff = an_array_of_entities_andor_groups_andor_components_you_have_already_created ;
      new_populated_group = Sketchup.active_model.entities.add_group(stuff) ;

      I have searched around and can't find anything that really helps with this.

      I assume that 'stuff' is the name that will be applied to the new group, but don't understand what to add after the = sign to include the other groups I have created.

      Also, 'stuff' (the new group) needs to be called the same as the 'default_name' (eg Cabinet1) entered in the Gui.

      Any further guidance would be appreciated.

      posted in Developers' Forum
      E
      ezt
    • RE: I'm getting there - but need some help.

      Thanks very much Todd.

      The first part works a treat - excellent.

      I am not sure I fully understand what to put in the last bit about creating the Global group, but I'll experiment with that this evening.

      Thanks again.

      posted in Developers' Forum
      E
      ezt
    • I'm getting there - but need some help.

      I am not versed in Ruby, but I needed a script to create a cabinet based on dimensions entered in a GUI - so I have tried to figure out how to accommodate my needs by studying other scripts to see if I could figure out how they work.

      The cabinet needs to be placed as a 'group' named by a Cabinet Code entered in the GUI, and each part of the cabinet needs to be a 'sub-group' named with the Cabinet code prefixing the part name.

      For example the cabinet group may be called 'Cabinet1' and the panel parts are groups called 'Cabinet1 - SideL', 'Cabinet1 - Bottom','Cabinet1 - Top' etc.

      I have managed to creat the first script which is for drawing the cabinet.
      Each cabinet part is created as its own 'group'. (No rocket science for most of you, but I was well pleased that I got it to work).

      However I am stuck on the next 2 steps.

      As I need the group for each part to be called something different for every cabinet created I have added a prompt for the cabinet code to be entered in the 'Cabinet Code' box.

      • My first question is how do I specify the default value for this to show text (eg 'Code Req'd') instead of a dimension (in this case I have it at 0.mm)?

      My second question is how do I use this code to prefix the group.name (for example if the Cabinet Code is 'Cabinet1' the group name for the left side should be 'Cabinet1 - SideL').

      My final question is, how do I create a global 'Group' for the whole cabinet before it is placed using the 'Cabinet Code' such that each of the part groups are secondary level.

      Here is the ruby code I have used

      @unknownuser said:

      require 'sketchup.rb'
      def wallcab1

      prompts = ["Width ", "Height ", "Depth", "Side Thickness", "Top-Bottom Thickness", "Back thickness ", "Cabinet Code"]
      values = [500.mm, 720.mm, 300.mm, 18.mm, 18.mm, 18.mm, 0.mm]

        results = inputbox prompts, values, "Cabinet Dimensions"
        return if not results
        xx, zz, yy, d1, z1, r1, n1 = results
      

      Make Left Side

      model = Sketchup.active_model
      model.start_operation "SideL"
      entities = model.active_entities
      group = entities.add_group
      entities = group.entities

          pts = []
      pts[0] = [0.mm, 0.mm, 0.mm]
      pts[1] = [d1, 0.mm, 0.mm]
      pts[2] = [d1, yy, 0.mm]
      pts[3] = [0.mm, yy, 0.mm]
      
      
      	face = entities.add_face pts
      

      status = face.pushpull -zz, true
      group.name = "SideL"

      Make Bottom Panel

      model = Sketchup.active_model
      model.start_operation "Bottom"
      entities = model.active_entities
      group = entities.add_group
      entities = group.entities

          pts = []
      pts[0] = [0.mm+d1, 0.mm, 0.mm]
      pts[1] = [xx-d1, 0.mm,  0.mm]
      pts[2] = [xx-d1, yy,  0.mm]
      pts[3] = [0.mm+d1, yy,  0.mm]
      
      
        face = entities.add_face pts
      

      status = face.pushpull -z1, true
      group.name = "Bottom"

      Make Top Panel

      model = Sketchup.active_model
      model.start_operation "Top"
      entities = model.active_entities
      group = entities.add_group
      entities = group.entities

          pts = []
      pts[0] = [0.mm+d1, 0.mm, 0.mm+zz]
      pts[1] = [0.mm+xx-d1, 0.mm, 0.mm+zz]
      pts[2] = [0.mm+xx-d1, yy, 0.mm+zz]
      pts[3] = [0.mm+d1, yy, 0.mm+zz]
      
      
      	face = entities.add_face pts
      

      status = face.pushpull -z1, true
      group.name = "Top"

      Make Right Side

      model = Sketchup.active_model
      model.start_operation "SideR"
      entities = model.active_entities
      group = entities.add_group
      entities = group.entities

          pts = []
      pts[0] = [xx-d1, 0.mm , 0.mm]
      pts[1] = [xx, 0.mm, 0.mm]
      pts[2] = [xx, yy, 0.mm]
      pts[3] = [xx-d1, yy, 0.mm]
      

      face = entities.add_face pts
      status = face.pushpull -zz, true
      group.name = "SideR"

      Make Back Panel

      model = Sketchup.active_model
      model.start_operation "Back"
      entities = model.active_entities
      group = entities.add_group
      entities = group.entities

          pts = []
      pts[0] = [0.mm, 0.mm+yy, 0.mm+zz]
      pts[1] = [0.mm+xx, 0.mm+yy, 0.mm+zz]
      pts[2] = [0.mm+xx, 0.mm+yy+r1, 0.mm+zz]
      pts[3] = [0.mm, 0.mm+yy+r1, 0.mm+zz]
      

      face = entities.add_face pts
      status = face.pushpull -zz, true
      group.name = "Back"

      end

      if( not file_loaded?("wallcab1.rb") )

      # This will add a separator to the menu, but only once
      #add_separator_to_menu("Plugins")
      # To add an item to a menu, you identify the menu, and then
      # provide a title to display and a block to execute.  In this case,
      # the block just calls the create_box function
      UI.menu("Plugins").add_item("Wall Cabinet1") { wallcab1 }
      

      end

      #-----------------------------------------------------------------------------
      file_loaded("wallcab1.rb")

      Any help would be greatly appreciated.

      posted in Developers' Forum
      E
      ezt
    • Select By Layer

      Here is a script for selecting items in a particular layer.

      @unknownuser said:

      #Make sure this ruby file is loaded

      ("require" will load a file only if it is not loaded yet)

      require "sketchup.rb" #Make sure this ruby file is loaded

      def select_by_layer
      # First get a list of all of the layers in the model
      model = Sketchup.active_model
      layers = model.layers
      names = layers.collect {|l| l.name}

        # Display a dialog to pick the layer to select
        prompts = ["Layer"]
        values = [names[0]]
        enums = [names.join("|")]
        results = inputbox prompts, values, enums, "Select By Layer"
        return if not results
        
        # Now select everything on the selected layer
        layername = results[0]
        do_select {|e| e.layer.name == layername}
      

      end

      define our file name so we will know when we load it twice

      filename="selectbylayer.rb"

      #run this code the first time this script is loaded
      #If it is loaded again, file_loaded!(filename) will return true
      if !file_loaded?(filename)
      # get the SketchUp plugins menu
      plugins_menu = UI.menu("Plugins")
      # add a seperator and our function to the "plugins" menu
      if plugins_menu
      plugins_menu.add_separator
      plugins_menu.add_item("Select By Layer") { select_by_layer}
      end
      # Let Ruby know we have loaded this file
      file_loaded(filename)
      end

      This shows the layers in the model as a drop down list and the items selected are those in the layer chosen from the drop down list.
      What I would like is the layers to be shown in a list with checkboxes. The selected items would then be defined as all those in the layers where the boxes are ticked.

      Is this do-able? Can anyone tell me how?

      Many thanks in advance.

      posted in Developers' Forum
      E
      ezt
    • RE: Combining Ruby Scripts

      Tig - you are a star.

      I could not figure out why one or two scripts ran in the console and others did not.
      it seems that by coincidence the 'def name' was the same as the script name for the couple that worked.

      Now I understand it from your explanation, it all makes sense.

      I have a couple of other questions, but I will put them in new topics rather than take up more of your time here (although if your posting history is anything to go by you will probably chip in there too πŸ˜‰ )

      posted in Developers' Forum
      E
      ezt
    • RE: Combining Ruby Scripts

      Tig,

      That's superb.

      Your very clear instructions allowed me to complete the script and it all works superbly.

      One point though, you mentioned using the Ruby Console. I have a problem with that. Every time I try to enter a script it returns errors. For example, if I run myscript.rb I get the error

      @unknownuser said:

      myscript.rb
      Error: #<NameError: (eval):149: undefined local variable or method `myscript' for main:Object>
      (eval):149

      I also get it with other scripts which also work when accessed from the plugins menu.

      Is there something I need to set somewhere for the console to work?

      posted in Developers' Forum
      E
      ezt
    • RE: Combining Ruby Scripts

      Thank you Tig.

      I have virtually no knowledge of Ruby, but I have had a go and I have a couple of questions if I may.

      First:
      I have created a small script called 'myscript' like this -

      @unknownuser said:

      #Make sure this ruby files are loaded
      require "sketchup.rb"
      require "script1.rb"
      require "script2.rb"

      def run_thescripts

      ???????????

      end

      define our file name so we will know when we load it twice

      filename="myscript.rb"

      #run this code the first time this script is loaded
      #If it is loaded again, file_loaded!(filename) will return true
      if !file_loaded?(filename)
      # get the SketchUp plugins menu
      plugins_menu = UI.menu("Plugins")
      # add a seperator and our function to the "plugins" menu
      if plugins_menu
      plugins_menu.add_separator
      plugins_menu.add_item("My Script") { run_thescripts}
      end
      # Let Ruby know we have loaded this file
      file_loaded(filename)
      end

      I am not sure if this is correct (although it seems to be the format from what I have seen in other scripts), and am not sure how to call and run the other two scripts with this. What should I put after the 'def run_scripts' part where the ????? are for two other scripts (script1.rb and script2.rb)?

      Second:

      In the two other scripts I assume that this is the part where I have to comment out the 'menu part' for them.

      @unknownuser said:

      define our file name so we will know when we load it twice

      filename="myscript.rb"

      #run this code the first time this script is loaded
      #If it is loaded again, file_loaded!(filename) will return true
      if !file_loaded?(filename)
      # get the SketchUp plugins menu
      plugins_menu = UI.menu("Plugins")
      # add a seperator and our function to the "plugins" menu
      if plugins_menu
      plugins_menu.add_separator
      plugins_menu.add_item("myscript") { run_scripts}
      end
      # Let Ruby know we have loaded this file
      file_loaded(filename)
      end

      Is it just this part I comment out

      @unknownuser said:

      get the SketchUp plugins menu

         plugins_menu = UI.menu("Plugins")
         # add a seperator and our function to the "plugins" menu
         if plugins_menu
             plugins_menu.add_separator
             plugins_menu.add_item("myscript") { run_scripts}
         end
      

      The whole Ruby thing seems quite useful, and I must get my head around it, but thanks for your help in the meantime.

      posted in Developers' Forum
      E
      ezt
    • Combining Ruby Scripts

      I am new to Sketchup and have downloaded a few Ruby scripts which are extemely useful.

      However, would it be possible to combine some of them into one script to save having to go through 2 or 3 one after the other?

      For example I use a 'select by layer' script to select components, then run the 'cutlist and materials' script which only works on selected components.

      It would be nice to be able to run just one script which executed the other 2 one after the other.

      If this is possible, how easy would it be?

      Thanks.

      posted in Developers' Forum
      E
      ezt
    • 1
    • 2
    • 2 / 2