Vb rvb rotate object around its own longtitudinal axis

HI
I wonder if anyone can show me how to rotate an oblong shaped box around its own long axis no matter how the object is oriented. in rvb or python.

Thanks
dazza000

Well,
I have tried rotate but I can’t get it to work right, but Rotate3d seems to work interactively. However, Python doesnt seem to have this . So My question is now: How do I automate this without any user input.

import rhinoscriptsyntax as rs
rs.Command("_Rotate3d _Pause _Pause _Pause 12")

How do I supply the data as variables to the line above. It needs to select the object to rotate, have a starting point of rotation, a end point of rotation and an angle.

I tried to pass a simple variable to the command but it didn’t work:

import rhinoscriptsyntax as rs
deg = 45
rs.Command("_Rotate3d _Pause _Pause _Pause deg")

Any one help?
dazza000

Well, the main problem is not how to get the command Rotate to work, it’s how to determine the object’s “longitudinal axis” - “no matter how the object is oriented”, and then derive the rotation axis from it. That’s not a simple matter for any arbitrary object and orientation.

Also, as there are an infinite number of planes that can run through the longitudinal axis, in order to define one specific plane, you not only need the long (X) axis, you also need the short (Y) axis plus a rotation center point - the rotation axis will then be the plane’s Z axis.

_Rotate3D simply allows you to interactively determine the rotation axis using 2 points. _Rotate simply assumes you want to rotate around an axis parallel to the active CPlane Z axis.

Once you have the plane/axis, scripting the rotation itself is a piece of cake…

if you have a line or edge in the right direction in the object to be rotated then you can use it as a rotation axis (you perhaps have to move that line to the right location), or, if you have least two non-parallel and non-anti-parallel lines or edges you can take the Cross Product of such line/edges and use that as the rotation axis. As @Helvetosaur indicated, it is the direction which is the tricky part.

// Rolf

Hi Helvetosaur and RIL,
Thanks for responding to my problem, I have been trying to follow ideas about setting the cPlane then doing the required rotation but I am stuck on how to work with the cPlane. I can’t find any commands to get, move, rotate, and put back the cPlane. Is python the the right scripting to use?
Appreciate some help
Dazza000

Start of Code

import rhinoscriptsyntax as rs

print("---------------start--------------------------")
print("")

CLEAN THE SCENE

print(“Clean all”)
arrAll = rs.AllObjects()
if arrAll:
rs.DeleteObjects(arrAll)
print(“all objects deleted”)

#pt1 = [-25, -5, -5]
#pt2 = [ 25, -5, -5]
#pt3 = [ 25, 5, -5]
#pt4 = [-25, 5, -5]

#pt5 = [-25, -5, 5]
#pt6 = [ 25, -5, 5]
#pt7 = [ 25, 5, 5]
#pt8 = [-25, 5, 5]

Create the coordinates for the box

pt0 = rs.coerce3dpoint([-25, -5, -5])
pt1 = rs.coerce3dpoint([ 25, -5, -5])
pt2 = rs.coerce3dpoint([ 25, 5, -5])
pt3 = rs.coerce3dpoint([-25, 5, -5])

pt4 = rs.coerce3dpoint([-25, -5, 5])
pt5 = rs.coerce3dpoint([ 25, -5, 5])
pt6 = rs.coerce3dpoint([ 25, 5, 5])
pt7 = rs.coerce3dpoint([-25, 5, 5])

Add the box

box_id = rs.AddBox([pt0, pt1, pt2, pt3, pt4, pt5, pt6, pt7])
print("Box created with id: " , box_id)

Might want to have three points to create a plane

on the end of the box

say points 0 3 and 4

these could be used in aligning the cplane (3 points)

pt0_ID = rs.AddPoint( pt0 )
pt3_ID = rs.AddPoint( pt3 )
pt4_ID = rs.AddPoint( pt4 )

print(" Calculate and Create central axis points for box")
startPoint = [-25,0,0]
endPoint = [ 25,0,0]
startPoint_ID = rs.AddPoint( startPoint )
endPoint_ID = rs.AddPoint( endPoint )

print(“Now need to set the cplane to the bottom (points 0, 3, 4)of the box”)
cPlane_ID = rs.ViewCPlane
print("view cplane result ", cPlane_ID )

Problem - I’m Stuck here . How do I manipulate the cPlane!

just a test rotation for after setting the cPlane

rotation_angle = 34
rs.RotateObject(box_id, startPoint, rotation_angle,[0,0,1],True)

End of code.