sketchucation logo sketchucation
    • Login
    🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Group the selected entities and give them a name[Solved]

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 4 Posters 186 Views 4 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.
    • N Offline
      niccah
      last edited by

      I want to automate following event with a script:

      I group the selected entities, right click: "Elementinformation" and enter a name like "result"...

      So, that's what I already have:

      
      model = Sketchup.active_model
      selection = model.selection # all the selected entities
      
      

      Now I want to add a group, give them a name and add "selection" to the group:

      
      group = model.add_group
      group.name = "result"
      group.entities. ... (?)
      
      

      How can I add the "selection" to that group? It tried a lot, but without success 😞

      Do you have a tip what can I do?

      Thanks a lot for your help!

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        In the index for [Code Snippets] by Subject there is this entry:

        Copy selection to new group?

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • N Offline
          niccah
          last edited by

          @dan rathbun said:

          In the index for [Code Snippets] by Subject there is this entry:

          Copy selection to new group?

          absolutely perfect! That's it!

          Thanks a lot!

          Just for other interested people:

          
          model = Sketchup.active_model
          selection = model.selection.to_a
          	
          group = model.active_entities.add_group(selection)
          group.name = "result"
          
          
          1 Reply Last reply Reply Quote 0
          • mitcorbM Offline
            mitcorb
            last edited by

            Just out of curiosity, is there any significance in the white space between "...to_a" and "group=model.active......"?

            I take the slow, deliberate approach in my aimless wandering.

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

              Nothing!
              Just to make reading it easier ?

              Note that gp=some_entities.add_group(some_stuff)
              is ONLY successful if all of the some_stuff entities are in the some_entities context AND it's the active_entities: otherwise you'll Bugsplat!
              So it's fine when you are adding a selection to a group in the same entities - as to select them they must all be in the same [active] entities context and you make the new group in that context too.
              Just be wary of grouping groups and adding things that are in one context into another context - to do that IS possible but involves either complex 'cloning' of geometry OR getting the definition of groups/instances and repeating their instances [temporarily] in the new context before erasing the original one[s]...

              TIG

              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