[Closed] Scripted geometry only updating via spinner
I’ve got the following scripted geo plugin I’m trying to write (it essentially build a rectangle shape in the viewport):
plugin shape JoystickRect
name:“Joystick”
classID:#(0x5b055255, 0xd0f9aeb)
extends:rectangle version:1
category:“Rigging”
autoPromoteDelegateProps:true
replaceUI:true
(
parameters pBlock rollout:params
(
dimension type:#integer ui:spnDimension
)
fn SetWidth =
(
format ("dimension: "+(this.dimension as string)+"
“)
if (dimension == 1) then
(
format (“Setting 1d
“)
this.delegate.width = 0.4
)
else
(
format (“Setting 2d
“)
this.delegate.width = 2.0
)
)
rollout params "Parameters"
(
spinner spnDimension "Dimension" type:#integer range:[1, 2, this.dimension]
--//////////////////////////////////////////////////
--EVENTS
--//////////////////////////////////////////////////
on spnDimension changed val do
(
SetWidth()
)
)
on create do
(
this.delegate.length = 2.0
this.delegate.CornerRadius = 0.15
SetWidth()
)
tool create
(
local startPoint
on mousePoint click do
case click of
(
1: (
nodeTM.translation = gridPoint--;#stop
return $
)
2: #Stop
3: #stop
)
)
)
Now I’m having a issue with this which is driving me nuts! If i try and build like this:
JoystickRect name:“rectName” dimension:1
Then it builds an object for me, but I’m getting this printed out:
dimension: 0
Setting 2d
My object is always coming out as a square. Even though I passed in the dimension parameter with a value of 1.
If i do ‘$.dimension = 1’ then the attribute on the object in the modifier panel changes to 1, but the object does not set the width to 1. However if i actually click the spinner then it does.
What patently obvious thing am I not doing right?
Use the ‘on property set’ event handler instead, something like
plugin shape JoystickRect
name:"Joystick"
classID:#(0x5b055255, 0xd0f9aeb)
extends:rectangle version:1
category:"Rigging"
autoPromoteDelegateProps:true
replaceUI:true
(
fn setWidth val =
(
this.delegate.width = if val == 1 then 0.4 else 2.0
)
parameters pBlock rollout:params
(
dimension default:1 type:#integer ui:spnDimension
on dimension set val do setWidth val
)
rollout params "Parameters"
(
spinner spnDimension "Dimension" type:#integer range:[1, 2, 1]
)
on create do
(
this.delegate.length = 2.0
this.delegate.cornerRadius = 0.15
)
tool create
(
local startPoint
on mousePoint click do
case click of
(
1: (
nodeTM.translation = gridPoint--;#stop
return $
)
2: #Stop
3: #stop
)
)
)