Setting axes via script

801 views
Skip to first unread message

BillW

unread,
Jul 13, 2007, 6:15:03 AM7/13/07
to Google SketchUp Help - Ruby ideas
I have hunted high and low in the Ruby API for a way of setting the
axes via script.
I also did a search and the comments suggest you cannot. Has this
changed at SK6?

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

Todd Burch - Katy, Texas

unread,
Jul 13, 2007, 3:21:01 PM7/13/07
to Google SketchUp Help - Ruby ideas
(Are you getting tired of me posting replies all your
questions? :) )

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

cphillips

unread,
Jul 13, 2007, 3:30:29 PM7/13/07
to Google SketchUp Help - Ruby ideas
I wrote this function to reset the axes to the center. I had to
transform all the entities in the group. I don't think there is an
easier way.

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 Burch - Katy, Texas

unread,
Jul 13, 2007, 5:03:13 PM7/13/07
to Google SketchUp Help - Ruby ideas
Thanks Chris. I've logged it!

Todd

cphillips

unread,
Jul 14, 2007, 12:15:56 AM7/14/07
to Google SketchUp Help - Ruby ideas
Cool!

um...what does "logging it" mean?
Chris

BillW

unread,
Jul 14, 2007, 5:36:13 AM7/14/07
to Google SketchUp Help - Ruby ideas
Thanks guys. I would prefer to be able to actualy set the axes from
script - perhaps next release of Sketchup?

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 -

Todd Burch - Katy, Texas

unread,
Jul 14, 2007, 7:35:12 AM7/14/07
to Google SketchUp Help - Ruby ideas
Chris, that means you've made the dubious honor and me taking the time
to cut and paste your code into a script file for my later
reference. :)

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

cphillips

unread,
Jul 14, 2007, 1:29:20 PM7/14/07
to Google SketchUp Help - Ruby ideas
Where do you want to move the axis to? And relative to what?

BillW

unread,
Jul 16, 2007, 6:19:38 PM7/16/07
to Google SketchUp Help - Ruby ideas

I am using Sketchup.send_action("selectAxisTool:") from script to
interactively set the axes which is then directly used for a call to
status = model.place_component modcomp, false

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 -

cphillips

unread,
Jul 17, 2007, 12:15:44 AM7/17/07
to Google SketchUp Help - Ruby ideas
If I correctly understand your explanation. You are using Sketchup's
built in axes placement tool to place components. But the problem is
that after you place a component you have also changed the axes of
whatever the active model was?

If so you could use use undo. Change axis,read axes,undo,create
component.

Cheers.
Chris

BillW

unread,
Jul 17, 2007, 4:42:53 AM7/17/07
to Google SketchUp Help - Ruby ideas
Hi 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

Reply all
Reply to author
Forward
0 new messages