sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Copy selection to new group?

    Scheduled Pinned Locked Moved Developers' Forum
    8 Posts 3 Posters 1.6k Views 3 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 want to make a new group and copy the selected geometry to it.
      What is the best way of doing it?

      Something like this (but this doesn't seem to work.):

      
      new_group = ents.copy
      
      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        If you have a selection you are in the active_entities so making a group direct shouldn't BugSplat - adding stuff to a group as you initially make it can be fatal if you cross-thread entities sets so is generally not recommended BUT here I think it'll be OK...
        If the selection was made manually it's always in the one [active_]entities context, if you are assembling the 'selection' in code then you must ensure that everything in the selection has the same parent and that the parent owns the model.active_entities - so if the model.active_entities==model.entities all of the coded 'selected objects' must have object.parent==model - I hope that bit's clear?
        This is how I would add the selection to a new group [untested - might be typo-riddled]...

        model=Sketchup.active_model
        ents=model.active_entities
        ss=model.selection
        ### check there's something to 'group' here
        ssa=ss.to_a
        ss.clear
        group=ents.add_group(ssa)
        ### everything that was selected has been moved into the new 'group' entities
        copy=group.copy; copy.explode
        ### this copies the group and explodes it so that the original selection is
        ### reinstated on top of the now grouped original selection.
        
        

        You should also add a model.start_operation('group selection')and a model.commit_operation to allow a one-step undo - unless of course the code is to go inside an already wider start/commit block of code...

        TIG

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

          Thanks, I'll try if this works.
          I'll rephrase what I want:

          I have a selection of faces and edges that might or might not be inside a group or component.
          The script should make a copy of these selected entities in a new group and open the group and select them to continue working on the duplicate instead of the original.

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

            There is no way to open a group/component in SketchUp via the Ruby API.

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

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

              @thomthom said:

              There is no way to open a group/component in SketchUp via the Ruby API.

              Ouch! Well then I guess I'll have to go the copy.explode way...

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

                There is no simple API method to open a group for editing, BUT it can be done in Windows if you have a shortcut key to Group-Edit using a keystroke emulation.

                require 'win32ole.so'
                ### you need this .so file in Plugins
                ### an example of access SUp tools not otherwise available...
                ### make a shorcut key-combo if NOT set already
                ### here we assume = ctrl+alt+shift+G
                ### check that you have just the group selected and if so do this...
                  WIN32OLE.new("WScript.Shell").SendKeys("+^%{g}")
                ###
                

                Here's the .so zipped Win32API.zip

                TIG

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

                  A small step forward but not quite there yet:

                  
                  model = Sketchup.active_model  
                  ent = model.active_entities  
                  ent_array = ent.to_a
                  group = ent.add_group(ent_array)	
                  bounds = group.bounds
                  #Be certain to move the copy enough so it wont touch the original
                  v = [(bounds.width+10), (bounds.height+10), 0]
                  tt = Geom;;Transformation.new(v)
                  copy = group.copy 
                  copy.transform!(tt)
                  sel = Sketchup.active_model.selection
                  ss = sel.add copy
                  group.explode
                  copy.explode
                  
                  

                  I want the copy to be exploded and the entities that were inside the "copy" group selected.
                  It would also be great to have the copy not inside the original group (if the original was grouped).

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

                    Once you have the group you can get a reference to its definition
                    defn=group.entities.parent
                    It acts just like a normal component definition.
                    So then use
                    group2=model.entities.add_instance(defn, group.parent.transformation)
                    [you must check it's not already in the model - if it is use group.transformation]
                    then
                    group.erase!
                    So the collection is now called ' group2' and it is in model.entities...

                    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