Notifications
Clear all

[Closed] Scripted Plugin – Runtime Error by accessing parameters

Hi everyone,

i am a bit confused and would appreciate any help.
I’m into scripting a scripted plugin like the standard “ExposeTM” Node.
Currently for testing purposes i want to get the position of any object i picked through a pickbutton updated to a label.
For that i use a parameter to save the picked node and a second parameter to save the current position of this node.
Every parameter belongs to a custom attribute which are referenced to a rollout.

Here is my code so far:
plugin helper JS_ValueExpose
name:“ValueExpose”
category:“JS-DesignTools”
extends:Point
replaceUI:true
classID:#(0x7d7f057e, 0x6770bf04)
(
–Start Plugin
on create do
(
print “Start Creating Attributes”

		local attr = attributes ExposedValues
		(
			parameters exposeParams rollout:params
			(
				exposeObject_param type:#node ui:pickObjButton
				beforePosition_param type:#Point3 ui:beforePosition default:[0,0,0]
				
				on beforePosition_param set val do
				(
					beforePosition_param = val
				)
			)		
			rollout params "Test Attribute Rollout"
			( 
				pickbutton pickObjButton "Pick Node"
				label beforePosition "Position"
				button dummybutton "LOL"

				fn tcb2 = 
				(
					if exposeObject_param != undefined do beforePosition_param = exposeObject_param.pos
					return (beforePosition.text = beforePosition_param as string)
				)
				
				on pickObjButton picked obj do
				(
					exposeObject_param = obj
					pickObjButton.text = obj.name
					
					beforePosition_param = exposeObject_param.pos
					beforePosition.text = beforePosition_param as string
					
					if exposeObject_param != undefined do
					(
						deleteAllChangeHandlers id:#my_callback
						when parameters exposeObject_param changes id:#my_callback do tcb2()
					)
					registerTimeCallback tcb2
				)
				
				on dummybutton pressed do
				(
					print this.beforePosition_param
				)

				on params open do
				(
					print "Open params Rollout"
					if exposeObject_param != undefined do pickObjButton.text = exposeObject_param.name as string
					beforePosition.text = beforePosition_param as string
				)
				
				on params close do
				(
			--		unregisterTimeCallback tcb2
				)
			)
		)
		print "Finished Rollout"
		
		custAttributes.add this attr
	)
--End Plugin
)

My issue with that is:
I use fn tcb2() for updating the position label. tcb2() is used in a when structure which works fine.
The same tcb2() function is also registered to a registerTimeCallback, but when i scroll through the timeline i receive following runtime error:
scripterror

Why can i access my parameters through the when structure but not through registerTimeCallback?

Anyone got an idea?
Thanks!!

2 Replies
 MZ1

Why you used custom attribute inside plugin? It can be done like this:

plugin helper Exposer
extends:Point
replaceUI:true
classID:#(0x7d7f057e, 0x6770bf05)
(
	fn UpdateUI =
	(
		this.MainRoll.U_Position.text = if isvalidnode (PickedNode = this.P_PickedNode) then PickedNode.pos as string else ""
	)
	
	fn AddCallbacks Obj =
	(
		deleteAllChangeHandlers id:#Exposer_Callbacks
		unregisterTimeCallback UpdateUI
		if isvalidnode Obj do 
		(	
			when parameters Obj changes id:#Exposer_Callbacks do UpdateUI()
			registerTimeCallback UpdateUI
		)
	)
	
	parameters MainParam rollout:MainRoll
	(
		P_PickedNode type:#node ui:U_PickedNode
		on P_PickedNode set obj do
		(
			AddCallbacks obj
			UpdateUI()
		)
		on MainParam open do
		(
			UpdateUI()
		)
	)
	
	rollout MainRoll "Main"
	(
		pickbutton U_PickedNode "Pick Node"
		label U_Position ""
	)
)

delete objects
Target = sphere radius:10 pos:[20,0,0]
TestExposer = Exposer isselected:true

Thanks man! Good solution!
That helped me out.