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

    Selection to component

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 5 Posters 3.2k Views 5 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.
    • PixeroP Offline
      Pixero
      last edited by

      I'm trying to group selected entitys and then convert it into a component to avoid SketchUp's component creation window.
      I have somehow made a wrong turn in my head and since this code doesn't give me an error in the console I'm not sure what I've messed up... 😳
      It's probably something embarassingly simple.

      ` mod = Sketchup.active_model
      ent = mod.entities

      	grp=[]
      	Sketchup.active_model.selection.each {|e|
      	  grp.push(e)
      	}		
      	grp=ent.add_group 
      	cmp=grp.to_component`
      
      1 Reply Last reply Reply Quote 0
      • S Offline
        slbaumgartner
        last edited by

        There are a couple of flaws in your code. First, you push Entities into the Array referenced by the variable grp and then immediately reassign grp to refer to your new Group. Second, you never added any content to the Group. The garbage collector in SketchUp Ruby is very aggressive about reaping empty Groups!

        1 Reply Last reply Reply Quote 0
        • R Offline
          rv1974
          last edited by

          TT already has (tt_groups2comps.rb) it for 100 years and it's perfect. I NEVER use the laggy standard one. Best works with shortcuts G for group, Shift-G for groups2comps
          http://sketchucation.com/forums/viewtopic.php?p=257578#p257578

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            Try this:

            mod = Sketchup.active_model
            sel = mod.selection
            ent = mod.active_entities
            grp = ent.add_group(sel.to_a)
            dfn = grp.to_component
            dfn.name = "Compo#1"
            
            

            If you don't force a definition name, then the component is confusingly named "Group#NN"
            You must use .active_entities, because if the current selection is not in a matching entities context you'll BugSplat !

            TIG

            1 Reply Last reply Reply Quote 0
            • PixeroP Offline
              Pixero
              last edited by

              Thanks TIG.
              That worked very well.

              A short question though.
              In the Entitys info window the Instance is now called Compo and the Definition is called Group#1.
              I thought the definition would be called Compo?

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                My mistake !
                Try this...

                mod = Sketchup.active_model
                sel = mod.selection
                ent = mod.active_entities
                grp = ent.add_group(sel.to_a)
                ins = grp.to_component
                ins.definition.name = "Compo#1"
                

                The instance should remain 'un-named'...

                TIG

                1 Reply Last reply Reply Quote 0
                • PixeroP Offline
                  Pixero
                  last edited by

                  Thanks again. This time it worked as it should.

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    db11
                    last edited by

                    Thanks to both of you for a very useful code snippet. Especially helpful when you're making a component from loose geometry and forgot to check "Replace selection with component", and have to go through the process twice. Always good to save clicks and annoyances.

                    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