Script to rotate objects around one of his axis

I just started Rhinoscript development, and I’m still not used with the 3D management. So I would like some explaination for the RotateObject Rhino3D method.

I have an object, and I would like to do a rotation of it, around the Y axis, in particular, around the orange arete.

To do so, I followed this example :

Option Explicit

Call Main()
Sub Main()
    'Create second glass
    Dim sObj, aBox, aMin, aMax, aCen
    sObj = Rhino.GetObject("Select object to rotate 1 degree", 0, True)
    If Not IsNull(sObj) Then
        aBox = Rhino.BoundingBox(sObj)
        If IsArray(aBox) Then
            aMin = aBox(0)
            aMax = aBox(6)
            aCen = Array( _
                0.5 * (aMax(0) + aMin(0)), _
                0.5 * (aMax(1) + aMin(1)), _
                0.5 * (aMax(2) + aMin(2))_
                )
	yAxis = Array( _
		0.5 * (aMax(0) + aMin(0)), _
		0.5 * (aMax(1) + aMin(1)), _
		0.5 * (aMax(2) + aMin(2))_
		)
            Rhino.RotateObject sObj, aCen, 10.0, yAxis, True
        End If
    End If 
End Sub

But I don’t understand how it works.

  • What is aBox(6), does it represent the 6th corner of the box ?

  • Can you explain me aMin and aMax ?

  • Can you explain me the aCen variable ? What are the different points of this array, and also, why are they all multiply by 0.5 ?

  • The syntax of RotateObject is as following

  • Rhino.RotateObject(strObject, arrPoint, dblAngle, arrAxis, blnCopy)

  • I would like to define the arrAxis to rotate around my orange axis. How can I declare this arrAxis (yAxis in the script) ?
    Thank you in advance for your help.

Here is information on the BoundingBox method and what it returns.

aCen is the calculated midpoint between aMax and aMin.

For a world xy-axis aligned bounding box, try setting aMax to aBox(3), per the help file.

1 Like

Thank you a lot for your answer.
It works !

Here is the code :

Option Explicit

Call Main()
Sub Main()
	'Create second glass
	Dim sObj, aBox, aMin, aMax, aCen,yAxis
	sObj = Rhino.GetObject("Select object to rotate 10 degree", 0, True)
	If Not IsNull(sObj) Then
		aBox = Rhino.BoundingBox(sObj)
		If IsArray(aBox) Then
			aMin = aBox(0)
			aMax = aBox(3)
			aCen = Array( _
				0.5 * (aMax(0) + aMin(0)), _
				0.5 * (aMax(1) + aMin(1)), _
				0.5 * (aMax(2) + aMin(2))_
				)
			yAxis = Array( _
				0, _
				1, _
				0_
				)
			Rhino.RotateObject sObj, aCen, 10.0, yAxis, True
		End If
	End If 
End Sub