Setting axes of a Group

I’m not seeing a way to do this but I can’t say I’ve ever tried to do this before so I may be missing something.

Basically what I’m trying to do is create a group extruded in the X direction so that the material is applied properly. Then I would like to somehow rotate it so it is vertical and then grab the handle for the group’s definition and generate copies with the add_instance method.

One way to do this is to simply leave the original group unrotated and then rotate each instance vertical as they are created but I would like to try and eliminate this additional transformation if possible.

I don’t see a way to do this unless I somehow can change the definitions axes.

Here is snippet of code that is creating the initial group and then assigning the group definition.

    origin = [0,0,0]
	xaxis = Geom::Vector3d.new(1,0,0)
	barradius = @Vert_bardia/2.0
	centercircle = Geom::Point3d.new(3,0,0)
	vbar_extrusion = @Stemheight + @Ftgdepth*0.5 - 3.0

	groupvb1 = Sketchup.active_model.active_entities.add_group
	entitiesvb1 = groupvb1.entities

	rebar_circle = entitiesvb1.add_circle centercircle, xaxis, barradius, @Numsegs_db
	rebar_face = entitiesvb1.add_face(rebar_circle)
	rebar_face.pushpull vbar_extrusion

	rot0 = Geom::Transformation.rotation(origin, Y_AXIS, 90.degrees)
	groupvb1.transform! rot0

	vbar_comp = groupvb1.definition

Note, that the 90 degree rotation only rotates the initial group or instance it does not rotate the definition. When I create new instances with the vbar_comp definition they are not rotated by the 90 degrees. Somehow I need to rotate the definition itself.

A definition does not have a transformation, only instances do. You have to transform the contents of the definition’s entities collection to change its axes.

1 Like

Fair enough, how does one go about that?

I think (not where I can test this right now)

myentities = mygroup.definition.entities
myentities.transform_entities(transform, myentities.to_a)
1 Like

I’ll give this a whirl and report back.

It works but then the material when applied to the new instances of the group are aligned 90 degrees out, back to the same problem. Hmm…

Perhaps a easier (but not so tidy) method is to provide a different material (for vertical rebar) and forego the whole rotation thing entirely.

Changing the axis of a group/component is effectively applying a transformation. Two in fact, as you need to transform the definition content, then each instance with the inverse transform.

1 Like