sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Making groups of loose geometry

    Scheduled Pinned Locked Moved Developers' Forum
    6 Posts 2 Posters 364 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Chris FullmerC Offline
      Chris Fullmer
      last edited by

      (EDIT: The question is how do I put existing geometry into a group. The rest is background info)

      Hi, I am writing a script that takes all loose geometry and turns everything into groups. It should work by turning all connected into a group, then moving on to the next portion of connected loose geometry and then turning that into a group and so on and so on until all loose geometries have been turned into groups.

      I thought I would be able to select all geometry, then start selecting the first entity and select all connected and then pass those entities off to an array named ents. So once I have my ents array setup, how do I tell SU to make a new group and move the entities in ents into that group? Does it work like that? Do I have to redraw everything inside of that group instead of just sort of moving the existing geometry there? I was hoping that the line below would do what I wanted, but it doesnt πŸ˜•

      group = ents.add_group

      It just breaks the code. So instead I tried to make a group of all gemoetry which is why I used the line below

      group = entities.add_group

      And I've found that it just creats an empty group. It doesn't actually add "entities" to the group.

      So what is the way to put existing geometry into a group? Here's all of my code so far.

      model = Sketchup.active_model
      entities = model.active_entities
      entity = entities[0]
      ents = entity.all_connected
      
      if (ents)
        group = entities.add_group
        ents.clear
      
        if (group)
          UI.messagebox group
        else
          UI.messagebox "No Group"
        end
      
      else
        UI.messagebox "Failure"
      end
      

      Sorry its so long for something so basic,

      Chris

      Lately you've been tan, suspicious for the winter.
      All my Plugins I've written

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        new_group = entities.add_group(array_of_entities)
        

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • thomthomT Offline
          thomthom
          last edited by

          Btw, what's your main source for API references? The reference documentation (http://code.google.com/apis/sketchup/docs/developers_guide/index.html) or the wiki style documentation?

          The wiki styled ref usually have more info. http://groups.google.com/group/SketchUp-Plugins-Dev/web/google-sketchup-ruby-api

          As you see in the wiki's description of add_group, it contains more info of it's usage: http://groups.google.com/group/SketchUp-Plugins-Dev/web/Ruby-Entities.html#add_group

          Thomas Thomassen β€” SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • Chris FullmerC Offline
            Chris Fullmer
            last edited by

            See, its just that easy. You know I can't find that documented in the API. It only says that add_group is used to make an empty array.

            Thanks Thom!

            Chris

            Lately you've been tan, suspicious for the winter.
            All my Plugins I've written

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              Yea, I dunno why there's two separate sources for this. None of which is complete...

              I usually try the wiki, then the other source, then I ask here for help if I still can't work it out.

              Another way to find out info is to use the Ruby console and type .methods for the various objects. For instance, I wanted to get the scaling of a group/component. So I look up the Transformation class. In the wiki docs it lists .scaling and .rotation as available methods. (The other resource got nothing on that topic) However, .scaling and .rotation returns error to me.

              But if I select a component and type this into the console:

              Sketchup.active_model.selection[0].transformation.methods
              

              I get this:

              ["rotx", "instance_variable_get", "to_s", "send", "identity?", "clone", "nil?", "roty", "instance_variable_set", "set!", "inspect", "instance_eval", "xscale", "invert!", "dup", "equal?", "rotz", "inverse", "methods", "yscale", "taint", "eql?", "origin", "hash", "singleton_methods", "zscale", "instance_of?", "extend", "xaxis", "id", "protected_methods", "tainted?", "kind_of?", "untaint", "yaxis", "__id__", "*", "private_methods", "is_a?", "freeze", "display", "zaxis", "object_id", "public_methods", "==", "===", "respond_to?", "type", "instance_variables", "=~", "method", "frozen?", "__send__", "to_a", "class"]
              

              Note how different that is. And note the methods: rotx, roty, rotz, xscale, yscale and zscale... sigh

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • Chris FullmerC Offline
                Chris Fullmer
                last edited by

                Ahh, the wiki! I had forgotten that the wiki was there. i was not looking in that.

                And thanks for the heads up on methods. I had seen someone else mention it earlier, so I use it once in a while. But I'm normally not great at just being able to see the available methods and choosing the one I need and figuring it out on my own. I generally need a bit of an example with syntax.....oh syntax.

                I'm getting there though, little by little. When this script is done, I'll post it and I'm pretty sure it will be a #1 seller 🀣

                Thanks Thom,

                Chris

                Lately you've been tan, suspicious for the winter.
                All my Plugins I've written

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                • First post
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement