Returning values from spinner and manipulate with them in real time

Hello everyone, I would like to develop an tool, which will place car wheels from middle of the scene to correct positions.
There is an example, what I want to do:
http://i.imgur.com/m9SXXZr.png
I want the script to place wheels on the correct location (yellow dots) with one click after the values to the spinner are inserted.

This is the rollout I have:

rollout WheelPlacerTool "WheelPlacer" width:878 height:247
(
	--- Rollout Style ---
	GroupBox WheelParametersGroup "Wheel Parameters" pos:[11,5] width:843 height:138
	spinner WheelDistance "" pos:[20,96] width:125 height:16 range:[0,4,0] type:#worldunits scale:0.001
	spinner FrontValue "" pos:[160,96] width:125 height:16 range:[0,3,0] type:#worldunits scale:0.001
	spinner RearValue "" pos:[300,96] width:125 height:16 range:[0,3,0] type:#worldunits scale:0.001
	spinner FrontSupressionLimit "" pos:[440,96] width:125 height:16 range:[0,1,0] type:#worldunits scale:0.001
	spinner RearSupressionLimit "" pos:[580,96] width:125 height:16 range:[0,1,0] type:#worldunits scale:0.001
	spinner WheelDepth "" pos:[720,96] width:125 height:16 range:[0,0.5,0] type:#worldunits scale:0.001
)
createdialog WheelPlacerTool

WheelDistance - distance between center of front and rear wheel axis.
FrontValue - distance between front wheels
RearValue - distance between rear wheels
FrontSupressionLimit - center of front wheel in Z-axis.
RearSupressionLimit - center of rear wheel in Z-axis.
WheelDepth - correction for wheel pivot (0,000) will mean center.

The main question is how do I get current value from spinner and use it as :

$myObject.pos = [ ValuefromSpinner1, ValuefromSpinner2,  ValuefromSpinner3]

Thanks for any help with my project :)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
miauu's picture

.

To get the spinner value use:

WheelDistance.value

For example:

$myObject.pos = [ WheelDistance.value, FrontValue.value,  RearValue.value]

pixamoon's picture

real time update

and this is small sample how to get position update in real time...
positioning function is only sample, you have to replace it with your own:

(
	local carBody
	local carWeel
	local carWeels = #()
 
	try(destroyDialog ::WheelPlacerTool)catch()
 
	rollout WheelPlacerTool "WheelPlacer" width:878 height:247
	(
		--- Rollout Style ---
		GroupBox WheelParametersGroup "Wheel Parameters" pos:[11,5] width:843 height:138
 
		spinner WheelDistance "" pos:[20,96] width:125 height:16 range:[0,100,10] type:#worldunits scale:0.1
		spinner FrontValue "" pos:[160,96] width:125 height:16 range:[0,100,10] type:#worldunits scale:0.1
		spinner RearValue "" pos:[300,96] width:125 height:16 range:[0,100,10] type:#worldunits scale:0.1
		spinner FrontSupressionLimit "" pos:[440,96] width:125 height:16 range:[0,1,0] type:#worldunits scale:0.001
		spinner RearSupressionLimit "" pos:[580,96] width:125 height:16 range:[0,1,0] type:#worldunits scale:0.001
		spinner WheelDepth "" pos:[720,96] width:125 height:16 range:[0,0.5,0] type:#worldunits scale:0.001
 
		pickbutton pcBody "Pick Body" pos:[10,160] width:100
		pickbutton pcWeel "Pick Weel" pos:[110,160] width:100
 
		fn applyChange = if carBody != undefined and carWeel != undefined do (
 
				----------------------- this is just some start - u need to finish this function ----------------------------------
 
				carWeels[1].pos = [ (carBody.pos[1] - FrontValue.value), (carBody.pos[2] - WheelDistance.value / 2), carBody.pos[3]]
				carWeels[2].pos = [ (carBody.pos[1] - FrontValue.value), (carBody.pos[2] + WheelDistance.value / 2),  carBody.pos[3]]
				carWeels[3].pos = [ (carBody.pos[1] + RearValue.value), (carBody.pos[2] - WheelDistance.value / 2), carBody.pos[3]]
				carWeels[4].pos = [ (carBody.pos[1] + RearValue.value), (carBody.pos[2] + WheelDistance.value / 2), carBody.pos[3]]
			)
 
		on WheelDistance changed arg do applyChange()
		on FrontValue changed arg do applyChange()
		on RearValue changed arg do applyChange()
		on WheelDepth changed arg do applyChange()
		on FrontSupressionLimit changed arg do applyChange()
		on RearSupressionLimit changed arg do applyChange()
		on WheelDepth changed arg do applyChange()
 
		on pcBody picked o do (carBody = o; applyChange())
		on pcWeel picked o do (
 
			carWeel = o
			carWeels[1] = Instance o
			carWeels[2] = Instance o
			carWeels[3] = Instance o
			carWeels[4] = Instance o
			applyChange()
		)
 
	)
	createdialog WheelPlacerTool
)
zwrtron's picture

Thank you! Its working but I

Thank you! Its working but I have an issue, exactly the same I had during I was developing it. Even if scene units are set to meters and spinner too it place wheels by maxunits. For example wheen the wheelbase is 2 it moves the wheels by two maxunits. How to make it working with meters. (Works well when values are multiplied by 39). 1m = 39maxunits

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.