Changing the position component axis

Hi.,
It is advised in the forum, to create an empty component before adding entities to avoid interacting with other existing entities.

  1. is it possible to change the axis orientation after creation.
  2. is it better to create the entities and adding to the component, during this time, whether we can able to change the axis orientation (Set component axis in the component window.)
  3. Does the transformation of axis is possible for the above scenario in ruby or it is not possible at all?
    Thanks.

With Ruby code, you create a component definition and add entities to it’s entities collection.
Then you add as many instances of this component to the entities collection of either the model itself, or the user’s active entities (which could be within the entities collection of another group or component definition.) You can also directly add these instances to another definition in the model’s definition list collection. (Ie, you might be creating a component with a nested hierarchy of groups or components.)

When you add the instances, one of the method arguments is a transformation for the instance. This transform can be a combination of translation, rotation and scaling (so as to position, rotate and size the instance.)

When you manually create a component in the model, you have no choice but to draw in the coordinates of the active context. That can lead to an awkward orientation relative to the component’s axes, which inherit from the axes of the active context.

But when you create a component via Ruby code, you work directly in the component definition’s innate coordinates. You can position, orient, and scale the new entities to align however is best - for example to minimize the bounding box.

Then when you place an instance in the model you apply a transformation to set that instance’s position, orientation and scale.

@DanRathbun & @slbaumgartner Thanks
from your replies, i understand that the component instance can be transformed. like orientation, scaling etc.,

But what i am trying to achieve is the following, that is orienting the component axis from the default position while creation of component. I need the larger length should be X axis and the shorter length will be Y axis and the thickness will be z axis. for each and ever component( top Rail, RH side panel) i create for a cabinet. And the axis position will differ for ever component.
i.e the RH Side panel will be @ 800mm in X axis for a 800mm width cabinet.


Attached here a small gif.
Thanks

I’m not sure I understand. You posted in the Ruby API category, but you are showing drawing a component manually with no Ruby involved.

If you want the long direction along the component’s X, the smaller direction along its Y, and the thickness along Z, create them that way in Ruby when you put entities into the component definition. Then if you want an instance stood up on edge at a particular location, create and apply the appropriate transformation when you place the instance using Ruby - a rotation and a translation combined.

@slbaumgartner.,
Hi.,
Just to highlight the orientation of the axis can be achieved through ruby, which i would want to achieve.
i can able to create a component through ruby, but no idea, how to achieve this transformation in ruby.
following is the snippet of the code only for the creation of the component.

# for the component definition
list = Sketchup.active_model.definitions
comp_def = list.add "LHPanel"

# Add Entities to the component 
ents= comp_def.entities
pt = [0,1,2,3]
# referencing early point for drawing. relative coordinate system
pt[0] = Geom::Point3d.new(0,0,0)
pt[1] = pt[0] + [18.mm,0,0] 
pt[2] = pt[1] + [0,550.mm,0] 
pt[3] = pt[2] + [-18.mm,0,0]
face = ents.add_face(pt)
face.reverse!
face.pushpull(720.mm, true)

save_path = Sketchup.find_support_file "Components", ""
comp_def.save_as(save_path + "/LHPanel.skp")
puts " The definition was save to: " + comp_def.path

You could draw the geometry in the component.entities already oriented as desired.
Then apply a rotation transformation to the instance ?

Alternatively, create the component, make a rotation transformation and apply that transformation to the component entities [using .to_a], then apply the inverse of that transformation to the instance - now the instance looks unchanged. but its ‘contents’ use the new axes within the component’s entities context…

Once you have a component definition (comp_def), use Entities#add_instance(comp_def, transformation) to add an instance to the desired Entities collection (e.g. Sketchup.active_model.active_entities). You can build the appropriate Transformation as a combination of rotation about Y_AXIS to stand the instance up, and translations about x, y, and maybe z to place it at the desired location.

@TIG/@slbaumgartner thanks.
Will try it out… if possible some one could detail little bit more :+1: