Make unique separate groups

Hello everyone, a tip, I have these five groups of entities very distinct from each other, created so that you can assign the wood material with the direction of the grain of the wood as I think best…
I would like to get a single group, of the five individual groups, so that I can then copy the single created group and move it…you can help me to better understand how to do it…

Thanks

Joseph

Img_g5

If you do not have them groups dynamic just use CTRL than Move tool.
Groups are always unique after copy. Components are not and you have to make them unique after copy

ents = gr_1.parent.entities
ary = [gr_1, gr_2, gr_3, gr_4, gr_5]
new_group = ents.add_group(ary)

Oops…I forgot to specify, that I wanted to know how to do using the ruby code… As always, the very kind Mr Dan, always answers to us beginners, thank you.

Dear Mr Dan, I tried to insert the lines of code as your advice, but it does not work, I do not understand where I am wrong, my purpose is to, up to the width of the hole, less than or equal to 63 cm, I create a single door, over 64 cm, the doors inserted should be two, to get this, I thought of grouping together in a single group, the individual groups corresponding to the upper, lower, right, left and central wing of the door, and then copy and move it, attach an image file and ruby file, for better clarification, thank you.

Joseph.

#..........previous code
ents = group_doorvertLathSx.parent.entities
        ary = [group_doorvertLathSx, group_doorvertLathDx, group_doorhorizLathTop, group_doorhorizLathBot, group_doorashWo]
        new_groupDoorSx = ents.add_group(ary)

        group_doorDx = new_groupDoorSx.copy
        group_doorDx.name = 'doorDx'
        point = Geom::Point3d.new((lg_hole -4.cm) / 2,0,0)
        transformation = Geom::Transformation.new point
        group_doorDx.move!(transformation)
#........next code

#........**full ruby file**
def frame_with_door()
    mod = Sketchup.active_model 
    definit_frame_door = mod.definitions
    comp_frame_door = definit_frame_door.add("FrameDoor")
    ent = comp_frame_door.entities 

    # Create "InputBox"....
    prompts = ["Height Hole: ",  "Width Hole: ",  "Structure Thickness: "] 
    options = ["", "", ""] 
    defaults = [65.cm, 50.cm, 2.cm] 
    title = "Create Frame_Door" 
    answers = UI.inputbox(prompts, defaults, options, title)

    hg_hole = answers[0] 
    lg_hole = answers[1] 
    str_tck = answers[2] 

    # Create "Frame"....
    # clear horizontal lath width
    wth_horiz_lath = (lg_hole -6.cm)

    
    layer_frame = mod.layers.add("Frame")
    mod.active_layer = layer_frame

    # left vertical lath
    group_vertLathSx = ent.add_group
    group_vertLathSx.name = 'vertLathSx'
                                                          
    pt_orig = ORIGIN

    pt1 = [0,0,0]
    pt2 = [0,str_tck,0]
    pt3 = [3.cm,str_tck,0]
    pt4 = [3.cm,0,0]

      face_vertLathSx = group_vertLathSx.entities.add_face(pt1,pt2,pt3,pt4)
      face_vertLathSx.pushpull (-hg_hole)
    
    # right vertical lath
    group_vertLathDx = ent.add_group
    group_vertLathDx.name = 'vertLathDx'
    
    pt5 = pt1.transform([(lg_hole -3.cm),0,0])
    pt6 = pt5.transform([0,str_tck,0])
    pt7 = pt6.transform([3.cm,0,0])
    pt8 = pt7.transform([0,-str_tck,0])

      face_vertLathDx = group_vertLathDx.entities.add_face(pt5,pt6,pt7,pt8)
      face_vertLathDx.pushpull (-hg_hole)

    # top horizontal lath
    group_horizLathTop = ent.add_group
    group_horizLathTop.name = 'LathTop'
    
    pt9 = pt4.transform([0,0,(hg_hole -3.cm)])
    pt10 = pt9.transform([0,str_tck,0])
    pt11 = pt10.transform([0,0,3.cm])
    pt12 = pt11.transform([0,-str_tck,0])

      face_horizLathTop = group_horizLathTop.entities.add_face(pt9,pt10,pt11,pt12)
      face_horizLathTop.pushpull (wth_horiz_lath)

    # bottom horizontal lath
    group_horizLathBot = ent.add_group
    group_horizLathBot.name = 'LathBot'
    
    pt13 = pt4.transform([0,0,3.cm])
    pt14 = pt3.transform([0,0,3.cm])
    
      face_horizLathBot = group_horizLathBot.entities.add_face(pt4,pt13,pt14,pt3)
      face_horizLathBot.pushpull (-wth_horiz_lath)

    if answers[1] <= 63.cm 

        # Create "Door..one..Sx"....
        layer_door = mod.layers.add("Door")
        mod.active_layer = layer_door

        # left vertical lath of the door
        group_doorvertLathSx = ent.add_group
        group_doorvertLathSx.name = 'doorvertLathSx'
                                                              
        pt_dr1 = pt13.transform([-1.cm,0,-1.cm])
        pt_dr2 = pt_dr1.transform([0,-3.cm,0])
        pt_dr3 = pt_dr2.transform([5.cm,0,0])
        pt_dr4 = pt_dr3.transform([0,3.cm,0])

          face_doorvertLathSx = group_doorvertLathSx.entities.add_face(pt_dr1,pt_dr2,pt_dr3,pt_dr4)
          face_doorvertLathSx.pushpull (hg_hole -4.cm)

        # right vertical lath of the door
        group_doorvertLathDx = ent.add_group
        group_doorvertLathDx.name = 'doorvertLathDx'
                                                              
        pt_dr5 = pt_dr4.transform([(lg_hole -14.cm),0,0])
        pt_dr6 = pt_dr5.transform([0,-3.cm,0])
        pt_dr7 = pt_dr6.transform([5.cm,0,0])
        pt_dr8 = pt_dr7.transform([0,3.cm,0])

          face_doorvertLathDx = group_doorvertLathDx.entities.add_face(pt_dr5,pt_dr6,pt_dr7,pt_dr8)
          face_doorvertLathDx.pushpull (hg_hole -4.cm)

        # top horizontal lath of the door 
        group_doorhorizLathTop = ent.add_group
        group_doorhorizLathTop.name = 'doorhorizLathTop'
                                                              
        pt_dr9 = pt_dr3.transform([0,0,(hg_hole -4.cm)])
        pt_dr10 = pt_dr9.transform([0,0,-5.cm])
        pt_dr11 = pt_dr10.transform([0,3.cm,0])
        pt_dr12 = pt_dr11.transform([0,0,5.cm])

          face_doorhorizLathTop = group_doorhorizLathTop.entities.add_face(pt_dr9,pt_dr10,pt_dr11,pt_dr12)
          face_doorhorizLathTop.pushpull (lg_hole -14.cm)

        # bottom horizontal lath of the door 
        group_doorhorizLathBot = ent.add_group
        group_doorhorizLathBot.name = 'doorhorizLathBot'
                                                              
        pt_dr13 = pt_dr3.transform([0,0,5.cm])
        pt_dr14 = pt_dr4.transform([0,0,5.cm])
        
          face_doorhorizLathBot = group_doorhorizLathBot.entities.add_face(pt_dr3,pt_dr13,pt_dr14,pt_dr4)
          face_doorhorizLathBot.pushpull -(lg_hole -14.cm)

        # ashlar wood
        group_doorashWo = ent.add_group
        group_doorashWo.name = 'doorashWo'
                                                              
        pt_ashWo1 = pt_dr3.transform([0,1.cm,5.cm])
        pt_ashWo2 = pt_ashWo1.transform([0,1.5.cm,0])
        pt_ashWo3 = pt_ashWo2.transform([0,0,(hg_hole -14.cm)])
        pt_ashWo4 = pt_ashWo3.transform([0,-1.5.cm,0])

          face_doorashWo = group_doorashWo.entities.add_face(pt_ashWo1,pt_ashWo2,pt_ashWo3,pt_ashWo4)
          face_doorashWo.pushpull (lg_hole -14.cm)

    elsif answers[1] >= 64.cm

        # Create "Door..one + one = two..Sx + Dx"....
        layer_door = mod.layers.add("Door")
        mod.active_layer = layer_door

        # left vertical lath of the door
        group_doorvertLathSx = ent.add_group
        group_doorvertLathSx.name = 'doorvertLathSx'
                                                              
        pt_dr1 = pt13.transform([-1.cm,0,-1.cm])
        pt_dr2 = pt_dr1.transform([0,-3.cm,0])
        pt_dr3 = pt_dr2.transform([5.cm,0,0])
        pt_dr4 = pt_dr3.transform([0,3.cm,0])

          face_doorvertLathSx = group_doorvertLathSx.entities.add_face(pt_dr1,pt_dr2,pt_dr3,pt_dr4)
          face_doorvertLathSx.pushpull (hg_hole -4.cm)

        # right vertical lath of the door
        group_doorvertLathDx = ent.add_group
        group_doorvertLathDx.name = 'doorvertLathDx'
                                                              
        pt_dr5 = pt_dr4.transform([(lg_hole -14.cm),0,0])
        pt_dr6 = pt_dr5.transform([0,-3.cm,0])
        pt_dr7 = pt_dr6.transform([5.cm,0,0])
        pt_dr8 = pt_dr7.transform([0,3.cm,0])

          face_doorvertLathDx = group_doorvertLathDx.entities.add_face(pt_dr5,pt_dr6,pt_dr7,pt_dr8)
          face_doorvertLathDx.pushpull (hg_hole -4.cm)

        # top horizontal lath of the door 
        group_doorhorizLathTop = ent.add_group
        group_doorhorizLathTop.name = 'doorhorizLathTop'
                                                              
        pt_dr9 = pt_dr3.transform([0,0,(hg_hole -4.cm)])
        pt_dr10 = pt_dr9.transform([0,0,-5.cm])
        pt_dr11 = pt_dr10.transform([0,3.cm,0])
        pt_dr12 = pt_dr11.transform([0,0,5.cm])

          face_doorhorizLathTop = group_doorhorizLathTop.entities.add_face(pt_dr9,pt_dr10,pt_dr11,pt_dr12)
          face_doorhorizLathTop.pushpull (lg_hole -14.cm)

        # bottom horizontal lath of the door 
        group_doorhorizLathBot = ent.add_group
        group_doorhorizLathBot.name = 'doorhorizLathBot'
                                                              
        pt_dr13 = pt_dr3.transform([0,0,5.cm])
        pt_dr14 = pt_dr4.transform([0,0,5.cm])
        
          face_doorhorizLathBot = group_doorhorizLathBot.entities.add_face(pt_dr3,pt_dr13,pt_dr14,pt_dr4)
          face_doorhorizLathBot.pushpull -(lg_hole -14.cm)

        # ashlar wood
        group_doorashWo = ent.add_group
        group_doorashWo.name = 'doorashWo'
                                                              
        pt_ashWo1 = pt_dr3.transform([0,1.cm,5.cm])
        pt_ashWo2 = pt_ashWo1.transform([0,1.5.cm,0])
        pt_ashWo3 = pt_ashWo2.transform([0,0,(hg_hole -14.cm)])
        pt_ashWo4 = pt_ashWo3.transform([0,-1.5.cm,0])

          face_doorashWo = group_doorashWo.entities.add_face(pt_ashWo1,pt_ashWo2,pt_ashWo3,pt_ashWo4)
          face_doorashWo.pushpull (lg_hole -14.cm)

        ents = group_doorvertLathSx.parent.entities
        ary = [group_doorvertLathSx, group_doorvertLathDx, group_doorhorizLathTop, group_doorhorizLathBot, group_doorashWo]
        new_groupDoorSx = ents.add_group(ary)

        group_doorDx = new_groupDoorSx.copy
        group_doorDx.name = 'doorDx'
        point = Geom::Point3d.new((lg_hole -4.cm) / 2,0,0)
        transformation = Geom::Transformation.new point
        group_doorDx.move!(transformation)

    end

   layer_comp = mod.layers.add("Component Frame_Door")
   mod.active_layer = layer_comp
       
   comp_frame_door.insertion_point = pt_orig # punto di iserimento del componenete stesso scelto da noi....
   mod.place_component(comp_frame_door, false)

end

UI.menu("Plugin").add_item("Frame_Door"){frame_with_door}

Be specific about what exactly does and does not work.

Ie, do the door stiles, rails and panel get grouped ?
Do the frame styles and rails get grouped ?

?


Whenever you temporarily change the modl’s active layer (tag), be sure that you change it back to “Layer0”.

I realize this is a snippet to show an issue, but your method is much too long for single method code.

If I delete this part of the code the rest works…

#..........previous code
ents = group_doorvertLathSx.parent.entities
        ary = [group_doorvertLathSx, group_doorvertLathDx, group_doorhorizLathTop, group_doorhorizLathBot, group_doorashWo]
        new_groupDoorSx = ents.add_group(ary)

        group_doorDx = new_groupDoorSx.copy
        group_doorDx.name = 'doorDx'
        point = Geom::Point3d.new((lg_hole -4.cm) / 2,0,0)
        transformation = Geom::Transformation.new point
        group_doorDx.move!(transformation)
#........next code

The code snippet I suggested was meant to run after groups had been created.
I assumed that the groups (you spoke of in the opening post) or components had been inserted earlier.

BUTyour code is creating these groups.
So what I said does not really apply.

Just create your groups within the parents that you want them to be within.

I myself would have the door and the frame in separate subgroups.


By the way, you are creating geometric primitives that are not assigned to “Layer0”.
This is not a good idea. Assign your group instances to other tag layers.
Leave geometric primitives like curves, edges and faces assigned to “Layer0”.

Also you should be using 2 space indents for Ruby, not 3 or 4.

Sketchup::ComponentDefinition#insertion_point and Sketchup::ComponentDefinition#insertion_point= methods have been removed in newer API versions. Do not use this feature.

I have not yet understood this concept…??

Hi, I solved it this way, could it be correct ?

The purpose was this: to insert the width of the hole equal to or greater than 64 cm,
two bar doors must be inserted on the frame of the same width,
in the file rb, after the condition " elsif answers[1] >= 64.cm ",

# We create the container group of all entities for the double door(grp_doorDob)..
grp_doorDob = ent.add_group
grp_doorDob.name = 'doorDob'
ents_doorDob = grp_doorDob.entities

For each group of double door, I apply the variable “ents_doorDob”,

# Create "Door..one + one = two..Sx + Dx"....
# left vertical listel of the door_double sx + dx
group_doorDobvertListSx = ents_doorDob.add_group
group_doorDobvertListSx.name = 'doorDobvertListSx'
#........... another code
#........... another code
# right vertical listel of the door_double sx + dx
group_doorDobvertListDx = ents_doorDob.add_group
group_doorDobvertListDx.name = 'doorDobvertListDx'
#........... another code
#........... another code
# top horizontal listel of the door_double sx + dx 
group_doorDobhorizLathTop = ents_doorDob.add_group
group_doorDobhorizLathTop.name = 'doorDobhorizLathTop'
#........... another code
#........... another code
# bottom horizontal listel of the door_double sx + dx 
group_doorDobhorizListBot = ents_doorDob.add_group
group_doorDobhorizListBot.name = 'doorDobhorizListBot'
#........... another code
#........... another code
# ashlar wood door sx + dx
group_doorDobashWo = ents_doorDob.add_group
group_doorDobashWo.name = 'doorDobashWo'
#........... another code
#........... another code

to follow, before closing “elsif answers[1] >= 64.cm”

# Transform the container group(grp_doorDob) of all design entities..
#..that make up the double door, in a "Component" (to_component), saving it in the..
#..variable "doorDob"...
doorDob = grp_doorDob.to_component
doorDob.definition.name = "doorDob"
doorDob_comp = doorDob.definition
# Create the "insertion point" (pt_orig_doorDob) for the right double door....
pt_orig_doorDob = pt_orig.offset(X_AXIS, lg_dobdoor)
tr = Geom::Transformation.axes(pt_orig_doorDob, X_AXIS, Y_AXIS, Z_AXIS)
twoDoor = ent.add_instance  doorDob_comp, tr

end # end elsif answers[1] >= 64.cm
#........... another code
#........... another code

could be a solution ? thank you.
frame_with_door.rb (9.6 KB)