[Closed] Help with pickbutton code
I’m having trouble understanding the pickbutton code that selects a target from a target camera.
The function first filters the list of objects that can be selected
and the code that selects a circle spline works but I’m running into trouble
with the code that sets the Camera Target. The following code is one of several attempts at it so I’ve given up and ask your advice because I’m now way too close to the problem to see clearly
fn Spline_filt obj = classof obj == Circle
fn Targ_filt obj = classof obj == Targetobject
..................................................
...................................................
ttCam = ally
ttCam.name = uniquename "ettCamera"
ttCam.target.name = uniquename "ettCamTarget"
ttCam.target.pos = [0.0,0.0,0.0]
ttCam.parent = ttDum
ttCam.pos = ttDum.pos
....................................................
...................................................
on pbt_Spline picked camPa do
(
ttpath = camPa
spn_rad.value = camPa.radius
)
on pbt_Targ picked camTa do
(
ttCam = camTa
spn_tHeight.value = camTa.target.pos.z
) --Bloody thing is pissing me off!!!
on spn_rad changed val do (ttPath.radius = val)
on spn_pheight changed val do (ttPath.pos.z = val)
on spn_tHeight changed val do (ttCam.target.pos.z = val)
on spn_oOffset changed val do (ttPath.rotation.z_rotation = val)
on spn_fRate changed val do (frameRate = val)
your pbt_Targ button picks a target of a camera (or of a light, for that matter).
It does not pick the camera itself.
Therefore, there is no sense in calling camTa.target.pos.z.
camTa already is the target.
call camTa.pos.z instead.
Pretty sure I tried that one and it seems to be ok except it now errors in another location :banghead:
I’d be happy to not have this feature but someone on my blog asked to be able to have any number of Cameras in the scene “with the same name” so he could filter them by name.
So I needed to be able to pick any camera from the scene to adjust it’s parameters
if ((tuTable != undefined) and (tuTable.isDisplayed)) do (destroyDialog tuTable)
rollout tuTable "EasyTurntable 1.65"
(
global saveTans
local ttPath, ttDum, ttCon, ttCam, camPa, camTa
fn Spline_filt obj = classof obj == Circle
fn Targ_filt obj = classof obj == Targetobject
spinner spn_sRan "Anim Start: " range:[-100000,100000,0] type:#integer setKeyBrackets:false enabled:false
spinner spn_eRan "Anim End: " range:[1,100000,100] type:#integer setKeyBrackets:false enabled:false
radiobuttons rdo_Cams "" labels:#("Standard", "VrayPhys") default:1 enabled:false
button but_Go "Go" width:80 height:20 across:2
button but_rSet "Reset all" width:80 height:20
button btn_RSpin "Reverse Spin" width:163 height:20 enabled:false
group "Adjust Settiings"
(
pickbutton pbt_Spline "Pick Camera Spline" filter:Spline_filt autodisplay:true width:160 height:18 enabled:false
pickbutton pbt_Targ "Pick Camera Target" filter:Targ_filt autodisplay:true width:160 height:18 enabled:false
spinner spn_rad "Camera Radius:" range:[1.0, 10000.0, 160.0] setKeyBrackets:false enabled:false
spinner spn_pheight "Camera Height:" range:[-10000.0, 10000.0, 100.0] setKeyBrackets:false enabled:false
spinner spn_tHeight "Target Height:" range:[-10000.0, 10000.0, 0.0] setKeyBrackets:false enabled:false
spinner spn_oOffset "Spline Rotation:" range:[-10000.0, 10000.0, -60.0] setKeyBrackets:false enabled:false
spinner spn_fRate "Frame Rate:" range:[0,100,25] setKeyBrackets:false enabled:false
)
function wasc ally = -- "Be vewy vewy quiet! I'm hunting Wabits"
(
ttCam = ally
ttCam.name = uniquename "ettCamera"
ttCam.target.name = uniquename "ettCamTarget"
ttCam.target.pos = [0.0,0.0,0.0]
ttCam.parent = ttDum
ttCam.pos = ttDum.pos
-- by this point I've forgotten what I'm doing, and why I'm doing it.
viewport.ResetAllViews()
max vpt persp user
max vpt camera
displaySafeFrames = true
max modify mode
clearSelection()
max zoomext sel all
select ttCam
)
on tuTable open do
(
redrawViews() -- Just freshen up a bit
-- This code saves the current tangent types prior to changing them to linear
saveTans = #()
maxops.getDefaultTangentType &inTangent &outTangent
tanIn = inTangent
tanOut = outTangent
append saveTans tanIn
append saveTans tanOut
-- If vray is installed then enable the radiobuttons
if vray != undefined and classof Vray == RendererClass do
(
rdo_Cams.enabled = true
)
)
on but_Go pressed do
(
-- Here we enable the ui stuff
spn_sRan.enabled = true
spn_eRan.enabled = true
spn_rad.enabled = true
pbt_Spline.enabled = true
pbt_Targ.enabled = true
spn_pheight.enabled = true
spn_tHeight.enabled = true
spn_oOffset.enabled = true
spn_fRate.enabled = true
btn_RSpin.enabled = true
----------------------------------------------------------------------------------------
-- Here we setup the bits and pieces to make our TurnTable
ttPath = Circle radius:160.0 pos:[0.0, 0.0, 100.0] steps:20 enabled:true
ttPath.name = uniquename "ettPath"
ttPath.rotation.z_rotation = -60.0
ttDum = Dummy pos:[0.0, -160.0, 100.0]
ttDum.name = uniquename "ettDummy"
ttCon = Path_Constraint follow:true
ttDum.pos.controller = ttCon
ttDum.pos.controller.path = ttPath
------------------------------------------------------------------------------------------
-- Next we set the radiobuttons to use either a standard Target Camera or Vray Physical Camera and call the function
case rdo_Cams.state of
(
1: (
wasc (Targetcamera pos:[50.0, 0.0, 0.0] target:(targetObject pos:[0.0, 0.0, 0.0]))
)
2: (
wasc (VRayPhysicalCamera pos:[50.0, 0.0, 0.0] target:(targetObject pos:[0.0, 0.0, 0.0]))
)
)
-- Now set the tangents to linear so we have a smooth camera movement
maxops.setDefaultTangentType #linear #linear
-- Hide the dummy so it doesn't get in our way visually
hide ttDum
)
on btn_RSpin pressed do
(
-- This code allows us to reverse the spin of our camera--but it grabs all the keys so I need to isolate the animation from the turntable
for y in objects do
(
getSel = GetCurrentSelection()
selectKeys getSel
animRange = interval animationRange.start animationRange.end
for y in objects do
(
try (
--numKeys y.pos.controller animRange
reverseTime y.pos.controller animRange #incLeft #incRight
reverseTime y.rotation.controller animRange #incLeft #incRight
reverseTime y.scale.controller animRange #incLeft #incRight
) catch()
)
)
)
on spn_sRan changed val do
(
animationRange = interval spn_sRan.value spn_eRan.value -- Set the animation range to the spinners value
ttCon.percent.controller.keys -- This sets up the first key (The start key)
ttCon.percent.controller.keys[1].time = val
ttCon.percent.controller.keys[1].value = 0
)
on spn_eRan changed val do
(
animationRange = interval spn_sRan.value spn_eRan.value -- Set the animation range to the spinners value
ttCon.percent.controller.keys -- This sets up the first key (The end key)
ttCon.percent.controller.keys[2].time = val
ttCon.percent.controller.keys[2].value = 100
)
on but_rSet pressed do
(
-- Resets all the settings back to their defaults
pbt_Spline.text = "Pick Camera Spline."
pbt_Targ.text = "Pick Camera Target."
spn_sRan.value = 0
spn_eRan.value = 100
spn_sRan.enabled = false
spn_eRan.enabled = false
btn_RSpin.enabled = false
animationRange = interval spn_sRan.value spn_eRan.value
rdo_Cams.state = 1
spn_rad.value = 160.0
spn_rad.enabled = false
pbt_Spline.enabled = false
pbt_Targ.enabled = false
spn_pHeight.value = 100.0
spn_pheight.enabled = false
spn_tHeight.value = 0
spn_tHeight.enabled = false
spn_oOffset.value = -60.0
spn_oOffset.enabled = false
frameRate = spn_fRate.value
spn_fRate.enabled = false
sliderTime = 0f
max vpt persp user
viewport.ResetAllViews()
displaySafeFrames = false
if isValidNode ttPath do (select ttPath; delete ttPath)
if isValidNode ttDum do (unhide ttDum; select ttDum; delete ttDum)
if isValidNode ttCam do (select ttCam; delete ttCam)
)
on pbt_Spline picked camPa do
(
ttpath = camPa
spn_rad.value = camPa.radius
)
on pbt_Targ picked camTa do
(
ttCam = camTa
spn_tHeight.value = camTa.pos.z
) --Bloody thing is pissing me off!!!
on spn_rad changed val do (ttPath.radius = val)
on spn_pheight changed val do (ttPath.pos.z = val)
on spn_tHeight changed val do (ttCam.target.pos.z = val)
on spn_oOffset changed val do (ttPath.rotation.z_rotation = val)
on spn_fRate changed val do (frameRate = val)
on tuTable close do
(
-- This is the bit that resets the tangents back to whatever they were before
inTangent = saveTans[1]
outTangent = saveTans[2]
maxops.setDefaultTangentType saveTans[1] saveTans[2]
)
)
createdialog tuTable width:190 height:294 style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox)
You’re gonna have to explain exactly what you’re trying to do and where the error part is. I don’t get any error picking a target.
On a side note, It’s good practice when asking for help on forums to reduce your tool to the smallest possible form that shows the problem.
It is deterring for most people (me included) to open a thread asking for assistance and find a very long piece of code they now have to read and understand, and it minimizes the chances of getting the help you need quickly.
ok it errors on this line now
on spn_tHeight changed val do (ttCam.target.pos.z = val)
– Error occurred in anonymous codeblock; filename: C:\Users\Luke\Maxscript\LukesScripts\Turntable\TurnTable_1_65.ms; position: 7090; line: 197
>> MAXScript Rollout Handler Exception:
– Unknown property: “pos” in undefined <<
I cant work out why it’s saying it’s undefined
But only when you try to adjust the spinner. It picks both items correctly.
Posting the whole code I hoped someone would run it.
I make one turntable and then change it’s settings then create another, then go back and select the original this is when the error pops up.
No… well yes but it still doesn’t do what is expected
which is why I put up the whole code as I think it needs to be run to understand
what is going on.
- Make one turntable press go
- change some/all of the settings
- Make another turntable
- use pickbuttons to select the previous turntables components
- adjust the target height spinner
- “Crash”!, “error”
Luke,
could you give a scenario how it expects to work?
i don’t need a way of implementation. give me please the basic idea of what you want to do.
Thanks denis
I guess I said it in my last post
- Make one turntable press go
- change some/all of the settings
- Make another turntable
- use pickbuttons to select the previous turntables components
- adjust the target height spinner
So I need to make the objects that create “one” turntable animation
and then adjust the settings.
Then I would like to create another set of objects that make another animation “two”
and then I would like to be able to swap between the two different set of objects
and adjust each of their settings.
Eventually I’ll use batch render the different cameras at different stages so it could mean there are more than 2 sets of turntables in the scene.
This was a request from someone on my blog.
I hope this makes more sense
Your steps don’t produce a crash for me, if I remove the word .target. from the spn_tHeight changed handler.
Thanks guys but when I take target out of
on spn_tHeight changed val do (ttCam.target.pos.z = val)
it breaks as this is the default spinner for the first camera target.
When I make a second camera with a unique name and then pick it with the fixed pickbutton and I take target out of the equation it just moves the camera not the target and this is not required as another spinner handles this as the camera is linked to the spline who’s height I’m adjusting and which the camera is linked.
I’ll just take this feature out for the time being until I work out what is going on but I really appreciate everyone’s help.
this explanation might be clear enough for you but I have no idea what turnable is, and have to read all thread before get it.
well. i did it…
I can fix your code to make it work, but I think that the way you do is not right. If I just only fix the code it will not be useful for other people. So can I show how I would do the similar task? And we will discuss any other possibilities with the community.
Thanks Denis I’ve been away from my computer for a while and was thinking about what I was doing. Rather than adapting the code to include the request from a user I realised I needed to re write the code.
So I’ll place the construction of the whole turntable in a function then add a spinner to allow you to set how many you need then use the pick buttons to choose the particular set you want to adjust. (I still don’t really know why he wanted the feature to build more than one but it was a good exercise for me so…)
In case there is animation on the subject you are filming, I also need to isolate the turntable animation (The reverse code) from the subjects animation as at the moment if you click reverse it stuffs up all the animation in the scene…