[Plugin] Key Rotate

[Plugin] Key Rotate

Postby kyyu » Wed May 05, 2010 12:28 am

This is the first plugin I wrote. I just wanted a simple plugin to rotate groups 90 degrees in all 3 axis. Got tired of doing it by dragging stuff with the mouse. I use it alot. I was totally clueless, at the time, so credit goes to TBD and his Rotix plugin. The structure will look similar. I deleted alot of stuff and added a few things. Though after writing the PushPull&Group plugin, I imported some extra picker logic back as improvement.

To use, just hover over a group to auto select and hit the following keys to rotate 90 deg. Arrow keys for x,y and Home/End for Z. I normally just reach over with my left hand. It might be disorienting at first, but you should quickly get the hang of it. Z should be no problem. A tip for x,y is; line yourself up on the standard position, facing the xy plane. And imagine the arrows on the surface of the part. And imagine pushing on an arrow, will push that edge down.

You can see me using it at ~6 minute mark in the F15 video: viewtopic.php?f=323&t=28072#p243453

Copyright(C) 2010, kyyu
All Rights Reserved

Name: Key Rotate
Version: 1.02
SU Version: 7.0
Date: 05-04-2010

Purpose: This plugin helps with the assembly of 3D models & puzzles for 1/4" sheet stock.
Description: Mouse over a group and use keyboard keys to rotate group 90 deg (about their center)
Usage:
# Right & Left arrow keys => rotate about the green (Y) axis direction
# Up & Down arrow keys => rotate about the red (X) axis direction
# Home & End arrow keys => rotate about the blue (Z) axis direction
# ** Hold Shift Key to add to selection

Credits: I learned alot buy studying TBD's Rotix plugin. Thanks you, for making it!
History:
1.0 (05-04-2010) - first version
1.01-2 added to description text


ky_Key Rotate.rb



-Kwok
0

kyyu 
 

Possible Key Rotate Mod...

Postby wozabee » Tue May 31, 2011 2:04 am

Hi,
after checking your Key rotate out, it's ALMOST the perfect thing I need for a problem I'm working on.
I've been able to get it to rotate all the way down to 1 degree increments per axis - which is part 1 of what I need - but does Anyone know what would need to be modified to make each component rotate on it's COMPONENT axis?

Fingers crossed,

cheers,

Woz.
0

wozabee 
 

Re: [Plugin] Key Rotate

Postby kyyu » Tue May 31, 2011 2:36 am

The variable "v" specifies the vector, representing the rotation axis. For example, for the Z axis: "v = Geom::Vector3d.new(0,0,1)"

Oh, I guess you need the rotation point, also.

It's these two lines of code that does the rotation:
tr = Geom::Transformation.rotation(pt,v,angle.degrees)
Sketchup.active_model.active_entities.transform_entities(tr,e)

Study the Sketchup Ruby API. For example, for the 1st line: http://code.google.com/apis/sketchup/do ... l#rotation

-Kwok
0

kyyu 
 

Re: [Plugin] Key Rotate

Postby wozabee » Tue May 31, 2011 2:58 am

kyyu wrote:The variable "v" specifies the vector, representing the rotation axis. For example, for the Z axis: "v = Geom::Vector3d.new(0,0,1)"



DANG!
....I'm going to have to REALLY swat up now and see if I can get to a stage where I can fully understand your answer (only JUST getting into the bare rudiments of scripting over these last few weeks).

So... you're meaning I have to find a way of relating to the relevant axis that has already been Assigned to each selected component?

...LOTS of leaning ahead 4 me m'thinks...

Thanks kyyu.

Woz
0

wozabee 
 

Re: [Plugin] Key Rotate

Postby wozabee » Tue May 31, 2011 4:24 am

Well, I'm STILL wading through the link you pointed me to.

...but I think I'm still a VERY long way in my learning enough to see clearly what's going on in all of your script.

So... as is, does your script transform the active entities (group, component) around their arbitrary geometric central axis?
I'm trying to see which part of the script works that particular bit out.

I would imagine my next step is to find out how to point your script to something that would describe the active entity's "COMPONENT AXIS" in each case.

In my ultimate desired use, all of the component axis's would also fall on the same real-world axis for each piece. If you could imagine each component looks a bit like a floating piece of a "cracked-apart spherical "shell" each rotating about a common "core" but each on slightly different layers so that they can "sheer" over each other.

As you might visualize, ultimately, it would be like pushing and rotating continents around on the surface of a little globe of the earth in any direction, each continent always properly oriented to the Core, and appearing to "float" with respect to the surface and each other.

With your script, I've managed now to at least get each component to rotate by 2 degree increments for each keystroke, but of course they just rotate where they are, intersecting each other.

Lots of working out ahead.

Thanks again Kwok,

Cheers,

Woz




kyyu wrote:The variable "v" specifies the vector, representing the rotation axis. For example, for the Z axis: "v = Geom::Vector3d.new(0,0,1)"

Oh, I guess you need the rotation point, also.

It's these two lines of code that does the rotation:
tr = Geom::Transformation.rotation(pt,v,angle.degrees)
Sketchup.active_model.active_entities.transform_entities(tr,e)

Study the Sketchup Ruby API. For example, for the 1st line: http://code.google.com/apis/sketchup/do ... l#rotation

-Kwok
0

wozabee 
 

Re: [Plugin] Key Rotate

Postby kyyu » Tue May 31, 2011 5:21 am

So... as is, does your script transform the active entities (group, component) around their arbitrary geometric central axis?
I'm trying to see which part of the script works that particular bit out.

Yes, it rotates about the center point of the group/component:
pt = e.bounds.center

This is real basic, which means you need to learn the basics 1st. I will give you a link to some videos and to a book, later below.

Like I said it's just two lines. You define a tranformation, in this case rotation:
tr = Geom::Transformation.rotation(pt,v,angle.degrees)
You only need to supply a point of rotation, a vector(ie an axis), and the angle.
Then you apply the transformation to something, in this case the group/component reference by the variable "e":
Sketchup.active_model.active_entities.transform_entities(tr,e)

I would imagine my next step is to find out how to point your script to something that would describe the active entity's "COMPONENT AXIS" in each case.

In my ultimate desired use, all of the component axis's would also fall on the same real-world axis for each piece. If you could imagine each component looks a bit like a floating piece of a "cracked-apart spherical "shell" each rotating about a common "core" but each on slightly different layers so that they can "sheer" over each other.

As you might visualize, ultimately, it would be like pushing and rotating continents around on the surface of a little globe of the earth in any direction, each continent always properly oriented to the Core, and appearing to "float" with respect to the surface and each other.

With your script, I've managed now to at least get each component to rotate by 2 degree increments for each keystroke, but of course they just rotate where they are, intersecting each other.

Lots of working out ahead.

Thanks again Kwok,

Cheers,

Woz


You say you want to use the "COMPONENT AXIS", but I don't see why. You can simply rotate about the center of your sphere.

You can test out snippets of code, without writing a full plugin. Look at Chris Fullmers video tutoirals, 1st 6: http://www.youtube.com/user/ChrisFullmer#g/u
And then try out this snippet of code. Select something and execute the snippet of code and that something will rotate/orbit around the origin, 30 deg each time. I am assuming this is what you had in mind.

Code: Select all
model = Sketchup.active_model
ent = model.entities
sel = model.selection
pt = [0,0,0]
v = Geom::Vector3d.new(0,0,1)
tr = Geom::Transformation.rotation(pt,v,30.degrees)
Sketchup.active_model.active_entities.transform_entities(tr,sel[0])

And read this book. The full pdf version is free: http://www.autosketchup.com/

Sketchup Ruby API: http://code.google.com/apis/sketchup/docs/index.html

Oh, and you should start a new thread for more help with your new plugin, so as not to tie up this one. Go ahead and post a link here to the new thread.

-Kwok
0

kyyu 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 



 

Return to Plugins

Who is online

Users browsing this forum: _domiomi, Aroundthebend, astro19930807, Google Bot, sokhet and 9 guests

Visit our sponsors: