I can use Sketchup.send_action("selectAxisTool:") for interactively
setting the axes
but I cannot do it via script.
The main reason is I want to reset the axes back to default after
send_action ie [0,0,0] no rotation
Any help would be appreciated.
Regards
Bill Wood
PS
I am confused where to post Ruby technical problems
Google Sketchup Help>Ruby ideas
or
Sketchup Pro Groups>Ruby API
Nothing has changed in V6 for axes.
You can reset the axes back to their default origin via right click on
an axis line>Reset.
I've never played around with the Vector3d.axes or Transformation.axes
methods personally. I need to do that.
Todd
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|
#ci.transform!(realBounds.center);
#newXform=(ci.transformation.inverse*Geom::Transformation.new(realBounds.center))*ci.transformation
#ci.transform!(newXform)
newCenter=realBounds.center.transform(ci.transformation)
ci.transform!(newCenter-ci.transformation.origin)
}
end
end
If you want to pass it a group use this:
class Sketchup::Group
def definition # make it so you can use group.definition
return(entities[0].parent)
end
end
Note it changes the definition of group to add a .definition method.
This makes group more similar to componentInstance.
Todd
um...what does "logging it" mean?
Chris
The code for reseting to the centre will be useful - Thanks
PS Todd Not at all - you have been very helpfull
----(Are you getting tired of me posting replies all your
questions? :) )
> > Todd- Hide quoted text -
>
> - Show quoted text -
Bill - not at all! Conversation has been good! Google monitors
these forums. Go ahead and enter a post in the Feature Suggestions
forum for any Ruby API (or SU) features you want.
Todd
The main reason is I want to reset the model axes back to default ( ie
model origin [0,0,0] with no rotation ) after the componenet is
placed.
I know I could write a tool with dynamic placement using calls such as
def set_current_point(x, y, view)
def onMouseMove(flags, x, y, view)
def update_state
def onLButtonDown(flags, x, y, view)
etc
but I figure it is easier to use the Sketchup axes to determine
rotation of a component in relation to a face.
I have accepted that the user can reset the axes via the right click
popup menu activated while hovering over the axes.
Thank anyway.
> > > - Show quoted text -- Hide quoted text -
If so you could use use undo. Change axis,read axes,undo,create
component.
Cheers.
Chris
I hadn't thought of using undo. However there is a problem which I
came across. I thought I could get a handle to the component being
placed but---------
Sketchup.active_model.selection.clear
Sketchup.send_action("selectAxisTool:")
status = model.place_component modcomp, false
puts Sketchup.active_model.selection[0] # returns nil
It seems the script doesnt hang around to pickup the placement of the
component. The place_component honours the current setting of the axes
which is what I want so the undo axes would have to come after the
component placement. I would therefor have to undo component placement
and set axes. As I cant get a handle to the placed component this
wouldnt work I think.
I wouldnt worry to much about this problem. As mentioned, I accept the
user can manually change the axes. Sketchup should really provide
calls to manipulate the axes - perhaps in the future.
Thanks
Bill