Notifications
Clear all

[Closed] preventing errors inside a script controller

preventing errors inside a script controller

I need to get a parameter value assigned to a scene object, (radius of a wheel).
radius is a parameter of a custom attribut. So, if I collapse the stack of a cylinder primitive, still get a radius value.
But max will popup an error message if obj.radius doesn’t exist.
How could I prevent this error? try() catch() is the only solution?
if (obj.radius == undefined) doesn’t work here

Fernando

4 Replies
 rdg

Hi Fernando,

try()catch() is a very expensive way to solve this.
You could use a customAttribute to store the radius.

Georg

Like he said:


theSphere = sphere()

def = attributes radiusContainer
(
	parameters main
	(
		RC type:#float animateable:true
	)
)

custAttributes.add theSphere def

theSphere.RC.controller = bezier_float()
theSphere.RC = theSphere.radius

paramWire.connect2way theSphere.baseObject[#Radius] theSphere.baseObject.radiusContainer[#rc] "rc" "Radius"

So create a custom attribute, apply it to the object and have it’s parameter be param wired to the original object’s radius. That way, when the original object’s radius changes, so will the parameter. When the object is collapsed, the wireparam is voided with no errors, and you still have the radius parameter in the custattribute to access in your script controller.

-Dave

My rotations tools does this.

It uses the “hasProperty” method to check if the object has a property called “Radius”, and if it does then you can just call “x = obj.radius” and if it doesn’t you can go with some other value.

Download it and look at the source code. Follow the link in my signature.

thanks rdg and Dave Black,
The file will be edited by many people. So, I am looking for a way to bypass errors if someone delete the CA or something.
Thanks mustan9, that is what I need: hasProperty function inside a conditional.

Fernando