List rotation of an object

script
rhinoscript
rhino

#1

Is there a way to extract the rotation angle of an object in relation to its original position when it was created ?
Ideally I’d like to be able to display an annotation tag that shows that angle, always in relation to its original angle (zero).
I need only its rotation on the xy plane.
How can this be scripted ?
Thanks


#2

It would only be possible if the objects were block instances. Then you could get that value from their xform matrix via scripting. Otherwise regular Rhino objects are not ‘self aware’ afaik.

–jarek


#3

Thanks Jarek. Actually that would be fine, I can make my object a block for what I want to accomplish.
But I don’t know much scripting, how can you extract the rotation value and display it dinamically as I rotate ? I could look at the rotation in the status line but after it’s rotated the first time it wouldn’t give me the angle in relation to the original block matrix.
Can you help?
Thanks


#4

I don’t know how to do it dynamically as you rotate.What can be done is show i.e. a text dot or print the rotation value along Z axis into command line after each rotation. Would that help?
-j


#5

Sure, that would be fine. A text dot at the insertion point would be fine but it would require to delete it every time a new rotation is applied … nevermind, maybe its easier just to show it in the command line.
All this exercise is because I work with vray and when I use a dome light with an hdri for the background, it’s a p.i.t.a. to get oriented trying to place the sun or any light source of the hdri in the right location to get the shadows where I want them because vray for Rhino doesn’t show the environment hdri in the viewport. What I use now is a sphere with the same hdri that I’m using for the background & dome light and I can visualize where the light is. To get even more confusing, vray spherical UVWGeneEnvironmet mapping tipe puts the Rotation zero in a very counterintuitive place (9 o’clock) and rotation angles increasing clockwise …
If I make the sphere a block and I can see the angle as I rotate, I could quickly see what angle I need to enter in the vray mappings. Even better if the rotation direction and zero degrees origin match the ones used in vray.


#6

Hi Juan,

I see - interesting technique…
Try this script: z_ExtractBlockZRotationAsDot.rvb (1.2 KB)

What it does - you can select a block, or multiple blocks, along with text dots. When you run the script, it will delete any dots and place new dots with the rotation along Z value at the block insertion point, and keep the objects selected. That way you can keep rotating and press the script button (if you make it), and the dot should update. It also prints the value into command line.

If you look at the script, maybe you can figure out how to compensate for Vray differences. There is f factor currently = 0 but you can change it to 90 (or -90?) to give you the Vray start angle, You also may need to multiply the result by -1 to compensate for clockwise vs. counter clockwise. I dont have Vray here to test it out, but in one case you would get your final result from the number, otherwise you’d need to do some math.

Hope that helps.

–jarek


#7

Hi Jarek,
That would do the trick. Thanks. The only thing is that I need the angles to display as 0 to 360. Right now it displays up to 180 (+ or -). I’m sure it’s easy to do but I coulnd’t figure it out …


#8

Hi Juan,

to make it 0 - 360, change the line:
v = Round((180 / (4 * Atn(1))) * r(2), 2) + f 'convert into degrees and add 'Vray' factor
to:
v = Round((180 / (4 * Atn(1))) * r(2), 2) + f + 180 'convert into degrees and add 'Vray' factor
it simply adds 180 to your result.

hth,

jarek


#9

Not really, adding 180 doesn’t do it. From 0 to 180 the result is correct but for example for a 200 degrees angle it displays -160. If I add 180 I’ll get 20 degrees not 200.
I added an if statement to check if the angle is negative and then add 360.
It works now. Thanks for all your efforts !
Cheers


#10

ok, makes sense - glad you made it work. Looks like you can do scripting after all :wink:


#11

Ha, ha, sure, that much …
Take care


#12

Hi @Jarek
Further to your script to show the z rotation of a block, I’ve made a modified version to reset the block to 0 rotation (attached).
I’d like to further expand it to have an option to match another entity’s rotation, in this case the sun azimuth.
I think I can manage to do it in Python but I’m having trouble converting this one from rvb to Python as starting point. Is there a way that you could convert it to Python for me?
I’ve tried a couple of online tools but they are for generic VB and they don’t understand certain Rhino functions.
EDIT: I’ve attached also the attempt to convert it to Python but I get an error
I would appreciate it if you could give me a hand.
Thanks !

ResetBlockZRotation.rvb (1013 Bytes)
ResetBlockZRotation.py (1.1 KB)


#13

Hi Juan,

Sorry, I have very little Python skills so far. Can’t help with that. Hope one of the Python gurus over here can chime in.

–jarek


#14

Thanks anyways :slight_smile:

@clement can you help ?


#15

@juancarreras, below seems to do the same as the rvb above using the converted function:

# original Script written by Jarek Bieda
import Rhino
import rhinoscriptsyntax as rs
from math import atan2, pi, asin
    
def ResetBlockZRotation():
    f = 0    
    block = rs.GetObject('Block Instance ?', 4096, True)
    r = DecomposeXformRotation(rs.BlockInstanceXform(block))
    v = round( r[2] * -180/pi, 0) + f
    if v < 0: v += 360
    rs.RotateObject(block, rs.BlockInstanceInsertPoint(block), v, False)
    print("Block rotation reset to zero")
    
def DecomposeXformRotation(arrXform):
    arrRotate = Rhino.Geometry.Point3d.Unset
    arrRotate.X = atan2(- arrXform.M21, arrXform.M22)
    arrRotate.Y = asin(arrXform.M20)
    arrRotate.Z = atan2(arrXform.M10, arrXform.M00)
    return arrRotate
    
ResetBlockZRotation()

note that i added some imports and removed the ones not required.

c.


Normals issue with exported mesh of mirrored linked blocks
#16

Grand !
Thanks @clement

I might bug you again if I get stuck with my new script … :slight_smile: