Change axes from ruby
-
Hy ! I want to change a component's axes using a ruby script instead of using the right-click menu "Change Axes" command.
In particular, what I want is to put the axe's origin in center of the component's boundingbox and rotate the coordonates around Z axis.Is there a posibility to use ruby for this?
Thanks for any help! -
-
@didier bur said:
Hi,
@unknownuser said:
Is there a posibility to use ruby for this?
No
Your answer just cnocked me down
So the so-easy-to-do right-click command doesn't have any alternative to be executed without user intervention?
You can see here an example of what I want to do here: http://bayimg.com/aaLjcAabj -
The way I got around the problem in one of my tools was to call the axes tool as shown below
Sketchup.send_action("selectAxisTool:") if @rotate
status = model.place_component modcomp, falseRegards
Bill Wood
-
Here is a function to reset the components axis to the bounding box center.
def resetAxis(ent) cd=ent.definition realBounds= Geom;;BoundingBox.new cd.entities.each{|de| realBounds.add(de.bounds)} #Calculate the real bounding box of the entities in the component. center=Geom;;Point3d.new(0,0,0) #desired center. if(realBounds.center!=center) #if not already centered #transform all the entities to be around the new center cd.entities.transform_entities(Geom;;Transformation.new( center-realBounds.center), cd.entities.to_a) #move each instance of this component to account for the entities moving inside the component. cd.instances.each{|ci| newCenter=realBounds.center.transform(ci.transformation) ci.transform!(newCenter-ci.transformation.origin) } end end
-
@billw said:
The way I got around the problem in one of my tools was to call the axes tool as shown below
Sketchup.send_action("selectAxisTool:") if @rotate
status = model.place_component modcomp, falseRegards
Bill Wood
Would you, please explain me a little bit more? I'm on my first steps in programming.
Thank you! -
@cphillips said:
Here is a function to reset the components axis to the bounding box center.
Thanks CPhillips ! the code works great!
So, if I understand correctly, you can't move axi's origin in SU, instead the boundingbox can be manipulated around its origin, right? -
As far as I know the only way to "move an axis" in Sketchup is to move all the entities in the component so they are centered around the desired axis. That is what the function does.
-
@cphillips said:
As far as I know the only way to "move an axis" in Sketchup is to move all the entities in the component so they are centered around the desired axis. That is what the function does.
I've seen that. So, rotating the axis to obtain a different boundingbox see here: http://bayimg.com/BaLOIaABJ can be done in the same way? Using a transformation that rotates all entities in the component around the origin, then rotates the component back in its initial position?
P.S. what BillW wanted to say with
Sketchup.send_action("selectAxisTool;") if @rotate status = model.place_component modcomp, false
?
Easy things for you people as pure chinese for me, a newbie -
Hi NewOne
It looks like I misunderstood what you were after.
I thought you wanted to change the Sketchup Axes before placing a component ie the orientation of a placed component is determined by the current axes orientation. There is no method for changing the axes as far as I am aware.
This statement invokes the Axes tool which allows the user to set the axes orientation prior to next call
Sketchup.send_action("selectAxisTool:")
The place_component method places a component "modcomp" in the Model using the component placement tool.
status = Sketchup.active_model.place_component modcomp, false
Apologies for the confusion.
Advertisement