Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Setting Up a Custom Attribute for Rotation

Setting Up a Custom Attribute for Rotation

ttazinazzo
Participant Participant
659 Views
7 Replies
Message 1 of 8

Setting Up a Custom Attribute for Rotation

ttazinazzo
Participant
Participant

Hey all - hopefully the last newbie question for a little while.

 

For coherence between business projects, I will need to create a Custom Attribute that is tied to the X-Rotation wire of an object in my scene. The custom attribute is named T-Beam rotation and was created as a Float parameter.

 

I am linking it to the X Rotation of my object through Parameter Wiring, however I am noticing that the custom attribute value is not equaling the rotation value shown in the rotation transform. If my object is rotated at 20 degrees I want the custom attribute to show 20 degrees as well. Instead, a small example value of 0.1 on the custom attribute rotates the object significantly (45 degrees or so) and I'm not sure why.

 

I'm thinking it might be because of an inconsistency between radians and degrees?

I'd like it to all show in degrees, so I have updated the wiring parameter expression with the below but it doesn't seem to change anything:

 

Wiring.PNG

Any idea on how I can just set the Custom Attribute directly equal to the rotational degree reading of the object?

0 Likes
660 Views
7 Replies
Replies (7)
Message 2 of 8

denisT.MaxDoctor
Advisor
Advisor

First, the wiring of a single component of Euler XYZ is not the best and trustworthy constraint. It's better to use an Orientation constraint.

Anyway... the rotation controller values are in  radians, but you need degrees. So use radtodeg / degtorad for conversion.

Second, as I see from your task description above, you don't need two-way-connection. Use a simple one-way.  

0 Likes
Message 3 of 8

ttazinazzo
Participant
Participant

Oh, I wasn't aware that there was a command for the conversion.

If I understand correct, would this be the right format? :

 

NewWiring.PNG

Even when I update it with that it still gives me wonky rotations.

Maybe it would just be easier to do it through an orientation constraint?

0 Likes
Message 4 of 8

denisT.MaxDoctor
Advisor
Advisor

first, make your Euler XYZ a List Rotation Controller, when the first item of the list is an initial value and the second is offset. You need the offset as I understand... 

0 Likes
Message 5 of 8

denisT.MaxDoctor
Advisor
Advisor

here is how I would do:

 

 

try(delete ca) catch()

angx_ca = attributes angx_ca attribid:#(12346,64321)
(
	parameters params rollout:params
	(
		target type:#node 
		angle type:#float ui:ui_angle
	)
	
	rollout params "CA: Angle Constraint" width:191
	(
		spinner ui_angle "Angle: " type:#float range:[-1e6,1e6,0] fieldwidth:64 align:#right offset:[4,4]

		button make_bt "Make Example" width:172 align:#center offset:[0,4]
		
		fn makeAngleConstraint = 
		(
			delete objects
			p = dummy name:#base boxsize:[8,8,8]
			
			-- Make rotation local by using parenting
			t = point name:#target parent:p size:10 box:on cross:on axistripod:on wirecolor:orange isselected:on
			
			-- lock Y and Z, leave only X free
			lockedtracksman.setlocks on t.rotation.controller[2] undefined -1 off 
			lockedtracksman.setlocks on t.rotation.controller[3] undefined -1 off
			
			t 
		)
		
		
		on make_bt pressed do undo "Make Dist&Ang" on
		(
			target = makeAngleConstraint()
			c = angle.controller = float_script()
			c.addtarget #angle target.rotation.controller[1]
			c.script = @"angle"
		)
		
		on params open do
		(
		)
	)
)
ca = createinstance angx_ca
createdialog ca.params

 

 

 

of course the CA need not be necessarily "standalone".

0 Likes
Message 6 of 8

ttazinazzo
Participant
Participant

So I'm reviewing the code you wrote and reviewing the project needs and I'm thinking I actually don't need a custom attribute, but instead need to create a script controller on a trackview node that is equal to the rotation.

 

Essentially we created a trackview node now named Beam, with subnodes "Position" "Velocity" and "Acceleration".

The "Position" subnode would need to have a script controller equaling the y-rotation controller of the object in the scene so that we can animate that object using that "Beam" node, "Position" subnode in trackview.

 

I'm trying to do a simple code like this:

nController = float_script()

nController.script = "object001.rotation.controller.y_rotation.controller"

OR

nController = float_script()

object001.rotation.controller.y_rotation.controller = nController

 

But I keep getting the same error:

-- Unknown property: "rotation" in undefined
-- MAXScript callstack:
-- thread data: threadID:24908
-- ------------------------------------------------------
-- [stack level: 0]
-- In top-level

 

Is there a way to use your code to achieve this?

0 Likes
Message 7 of 8

denisT.MaxDoctor
Advisor
Advisor

It's up to you if you want "simple"... I show how to do it right.

0 Likes
Message 8 of 8

ttazinazzo
Participant
Participant

Hey Denis,

 

I think I'm starting to understand your example.

However, I will still need to use a custom attribute so that the rotation is animatable, though I was able to create one now.

 

One question - I created a custom attribute named spin on my dummy object; I selected a box that I have in the scene and assigned a script controller to the y_rotation so that it equaled $Dummy001.spin. However, when I animate that $Dummy001.Spin attribute in trackview, the default is still in radians, and the box rotates severely because it is radians.

 

Do you know of a way to change it so that it rotates the object by degrees and not radians?

This would make the rest of the project significantly easier - one of the final pieces of the puzzle.

 

Thank you!

0 Likes