How to set component's origin to left-back-bottom corner

now i find that the components’ origin points are in diffrent corner. is there a method to set the component’s origin to the component’s left-back-bottom corner.

In the GUI you would use mouse right-click and Flip Along.

Via the API, you might apply a scaling transform of -1 in the desired direction.

In the GUI, why not Change Axes? Which won’t have the same effect as a FlipAlong unless the component has a particular kind of symmetry, will it?

Or is there a previous thread that I’ve missed, which says what shape CharellkingQu is drawing in Ruby?

can you give me an example? you know the transformation has sixteen arguments, i don’t know which one can works.

can you give me an example? which argument can works to scale transformation

I’m not quite sure what you are asking, especially what “left-back-bottom corner” means. When you first group a selection of drawing elements, the transformation origin is at the bounding box’s bottom-south-west corner (which is to the left when the viewing direction is northerly). Perhaps you want to de-rotate a grouped object with Ruby code. Applying a grouped object’s transformation inverse would set it to identity. Setting it to identity would de-rotate and descale it, as well as set to extrinsic position 0,0,0. If descaling isn’t desirable, one can use the transformation’s axes, which are normalized (i.e. scale factor of 1).

Given a Ruby reference to a grouped object “ent”, you should be able to de-rotate with the inverse of a transformation constructed from its axis methods like so:

t = ent.transformation
external_center = ent.bounds.center
external_translate = Geom::Transformation.translation( external_center )
ext_axis_tform = Geom::Transformation.axes( external_center, t.xaxis, t.yaxis, t.zaxis )
ent.transform! external_translate * ext_axis_tform.inverse

The code snippet above should do the rotation around the transformation’s outside bounding box (at least that is what I’m trying for). My simple test was successful.

Now, the internal drawing elements have also been de-rotated. Do you want them rotated inside of the grouped object so that the original orientation is maintained by rotating the nested drawing objects? After some trial and error with rotation center I have come up with:

internal_center = ent.definition.bounds.center
internal_translate = Geom::Transformation.translation( internal_center )
int_axis_tform = Geom::Transformation.axes( ORIGIN, t.xaxis, t.yaxis, t.zaxis )
internal_tform = internal_translate * int_axis_tform * internal_translate.inverse
ents = ent.definition.entities.to_a
ent.definition.entities.transform_entities( internal_tform, ents )

Once again the transformation’s original axes are used, this time to re-orient the internal components.

You asked about a “method” to do this. There is no simple method call. An algorithm that applies a sequence of transformations is needed.

1 Like

thank you very much, @BruceYoung. i’ll have a try. now i have another question how to check the origin point is not at the bounding box’s bottom-south-west corner

For a grouped object in the most outer entities collection, its outer bounding box corner number “0” appears to always be at the bottom south west corner. The following should work for a grouped object that hasn’t had its nested drawing elements altered:

if ent.bounds.corner(0) == ent.transformation.origin

If the grouped object is nested inside of others, then the coordinates above would need to be transformed to world coordinates.

The above Ruby statement is not working for my de-rotated test example for this forum topic because “transform_entities” messed around with the internal geometry, and some of the geometry is now lower than the transformation origin.

You seem to want to de-rotate the object to align with the outer bounding box. Why do you think it is necessary to do so? What is it you are trying to achieve? Can you attach a simplified model?

1 Like

thank you very much

sometimes, i find that the component’s origin is not a boundarybox’s corner. so is there a method that i directly set the origin point to the bottom-south-west corner?

Why do you think it is necessary to have a grouped object’s transformation origin at the bounding box?

That requires the object to be un-rotated, and internal drawing elements in their initial orientation when they were grouped. If you have rotated the object, used API calls to change the orientation of internal drawing elements, or used the axes tool to reposition the origin, then the origin will not even be at the bottom. Modifications can result in the origin being at the bounding box center, or the origin being outside of any bounding box. You can use tools to reposition the axes/origin.

an example model would help you clarify your requirement…

it all can vary…

in an .icf cleanup plugin of mine I have to do 3 different transformations to ‘fix’ the insertion points, before I can identify which can be components…

i.e. 60 doors become one if they have the same sizes, materials , edge counts and internal transformations…

I need to treat Doors, Windows, Walls differently from Floors as they each I use the largest face to find a direction…

I translate everything to origin and back first to have a known starting point for example…

if your needs are simpler, then even my starting point may not help…

john

can you tell me where i can get your code? i study your code. thank you

it’s not available publicly, but I wrote a version that shows you what happens and made this gif.

you can see items being moved to ‘fix’ their transformation…

it’s based on using small snippets that ‘show’ you what happens and you can use it to work out your code…

  model = Sketchup.active_model
  ents  = model.active_entities
  view  = model.active_view
  sel   = model.selection
  
  # select a single item with an odd origin
  i = sel[0]
  
  # collect it's contents
  dents = i.definition.entities

  # this makes sure we start at the same origin for everthing
  # we first move the contents
  tr = i.transformation
  dents.transform_entities(tr, dents.to_a)
  
  # this is just to watch what happens
  view.refresh
  sleep 0.5
  
  # then we transform contents container opposite to the contents
  i.transform!(tr.inverse)
  
  # if you run a loop on more than one item
  view.refresh
  sleep 0.5

it does slow things down, but this is for learning and entertainment…

better than watching a beachball…

john

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.