11 messages in com.googlegroups.sketchuprubyRe: Setting axes via script
FromSent OnAttachments
BillW13 Jul 2007 03:14 
Todd Burch - Katy, Texas13 Jul 2007 12:20 
cphillips13 Jul 2007 12:30 
Todd Burch - Katy, Texas13 Jul 2007 14:02 
cphillips13 Jul 2007 21:15 
BillW14 Jul 2007 02:35 
Todd Burch - Katy, Texas14 Jul 2007 04:34 
cphillips14 Jul 2007 10:28 
BillW16 Jul 2007 15:19 
cphillips16 Jul 2007 21:15 
BillW17 Jul 2007 01:42 
Subject:Re: Setting axes via script
From:cphillips (Dart@gmail.com)
Date:07/13/2007 12:30:06 PM
List:com.googlegroups.sketchupruby

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.

On Jul 13, 3:15 am, BillW wrote:

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