[Closed] Copy Keys and Pick button check
Hello,
I’m hoping someone could help me, I’m new to working with maxscript. I have the following script. (The entire code is at the bottom)
on PitchButton picked obj do
(
PitchButton.text = obj.name
PitchAnimation = obj
)
if PitchButton != undefined then
(
SelectedObject = (pitchanimation as string + “.rotation.” + pEdit).controller – controller I want to read
VehicleMotion = $VehicleMotion.custom_attributes[#Pitch][#Pitch_Animation].controller – controller I’m writing to
CheckBox SelectedObject VehicleMotion --current function (works when both Selected Object and VehicleMotion are custom_attributes)
)
PitchButton: is selecting an object that I want to read the keys from.
pEdit: is text entered into an Edit Text box. (example x_rotation)
What I’m trying to achieve is SelectedObject into a controller so I can read the keys, and have them copied to the VehicleMotion controller. Currently when I run (pitchanimation as string + “.rotation.” + pEdit).controller I get prompted “–Unknown property: “controller” in “$Dummy:Pitch @ [60.274170,3094.132080,0.000000].rotation.x_rotation” ($Dummy:Pitch is the selected object.). When I run the VehicleMotion in the listener, I get “Controller:Bezier_Float”. I don’t know what I’m doing wrong, that SelectedObject isn’t letting me run the string as a controller.
I have the PitchButton in an “if then” because I want to have it checked to see if anything is selected and if not to ignore it. However, for some reason the script still tires to read this part of the script. I don’t know what I’m doing wrong.
Any help would be greatly appreciated and if needed I can paste the entire script if that will make things easier to understand. Thanks
global selKey = ()
global userAnimatedObj
global PitchAnimation
global pEdit
global pEditVal
global SelectedObj
--Initialize time
global firstFrameCopy = "0"
global lastFrameCopy = "1150"
global newFrame = "0"
global pEdit = "x_rotation"
global pscaleEdit = "1"
global rEdit = "y_rotation"
global rscaleEdit = "1"
global hEdit = "z_position"
global hscaleEdit = "1"
global yEdit = "z_rotation"
global yscaleEdit = "1"
global firstFrameCopyVal = firstFrameCopy as float
global lastFrameCopyVal = lastFrameCopy as float
global newFrameVal = newFrame as float
global PitchButton = undefined
importnode = $VehicleMotion001
if importnode != undefined then
(
SelectBtnText = importnode.name
userAnimatedObj = importnode
)
else SelectBtnText = "---"
--Function for copying keys
fn CheckBox r w =
(
controller_read = r
controller_write = w
keys = controller_read.keys
--Deletes Selected Keys
fn deleteKeysByRange controller_write deleteRange =
(
for x in controller_write.keys.count to 1 by -1 do
(
if (controller_write.keys[x].time >= firstFrameCopyVal) and (controller_write.keys[x].time <= lastFrameCopyVal) do deleteKey controller_write x
)
)
for obj in selection do
(
deleteKeysByRange controller_write (interval firstFrameCopyVal lastFrameCopyVal)
)
--Copy r Keys to w
for i = 1 to keys.count do
(
key_time = keys[i].time
if key_time >= (firstFrameCopyVal as float) and key_time <= (lastFrameCopyVal as float) do
(
new_key = addnewkey controller_write i
new_key.value = keys[i].value
new_key.time = keys[i].time + NewFrameVal
new_key.intangent = keys[i].intangent
new_key.outtangent = keys[i].outtangent
new_key.inTangentLength = keys[i].inTangentLength
new_key.outTangentLength = keys[i].outTangentLength
)
)
Movekeys controller_write 1
Movekeys controller_write -1
)
rollout MotionKeyCopy "Motion Key Copier" width:405 height:440
(
--groups
groupBox SelectObjGroup "Select Vehicle Motion" pos:[10,10] width:130 height:60
groupBox AxisGroup "Select Motion to Copy" pos:[10,75] width:130 height:110
groupBox CopyKeysGroup "Copy Keys" pos:[10,375] width:130 height:60
groupBox CopyFrameGroup "Copy Frame Range" pos:[10,185] width:130 height:115
groupBox StartFrameGroup "Starting Frame" pos:[10,300] width:130 height:72
groupBox NonVMGroup "Non-Vehicle Motion" pos:[148,10] width:252 height:424
groupBox grp18 "Pitch" pos:[153,55] width:235 height:70
groupBox grp19 "Roll" pos:[153,130] width:235 height:70
groupBox grp20 "Heave" pos:[153,205] width:235 height:70
groupBox grp21 "Yaw" pos:[153,280] width:235 height:70
groupBox grp22 "Propulsion" pos:[153,355] width:235 height:70
--buttons
button CopyKeysBtn "Send to Motion" pos:[25,395] width:100 height:30
--pickbuttons
pickButton SelectObjButton SelectBtnText pos:[22,35] width:105 height:25
pickButton PitchButton "---" pos:[158,70] width:80 height:20
pickButton RollButton "---" pos:[158,145] width:80 height:20
pickButton HeaveButton "---" pos:[158,220] width:80 height:20
pickButton YawButton "---" pos:[158,295] width:80 height:20
pickButton PropButton "---" pos:[158,370] width:80 height:20
--checkboxes
checkbox CopyPitchChk "Pitch" pos:[20,100] width:60 height:18 enabled:true checked:false
checkbox CopyRollChk "Roll" pos:[83,100] width:45 height:18 enabled:true checked:false
checkbox CopyHeaveChk "Heave" pos:[20,130] width:60 height:18 enabled:true checked:false
checkbox CopyYawChk "Yaw" pos:[83,130] width:45 height:18 enabled:true checked:false
checkbox CopyTransChk "Transport" pos:[20,160] width:70 height:18 enabled:true checked:false
checkbox SameCheck "Same Object" pos:[158,30] width:80 height:18 enabled:false checked:false
--edit boxes
editText CopyMaxEdit "" pos:[20,269] width:95 height:17 text: lastFrameCopy
editText CopyMinEdit "" pos:[20,225] width:95 height:17 text: firstFrameCopy
editText NewFramesEdit "" pos:[20,338] width:95 height:17 text: newFrame
editText PitchEdit "" pos:[153,95] width:85 height:17 enabled:false text: pEdit
editText PitchScaleEdit "" pos:[248,95] width:60 height:17 enabled:false text: pscaleEdit
editText RollEdit "" pos:[153,170] width:85 height:17 enabled:false text: rEdit
editText RollScaleEdit "" pos:[248,171] width:60 height:17 enabled:false text: rscaleEdit
editText HeaveEdit "" pos:[153,245] width:85 height:17 enabled:false text: hEdit
editText HeaveScaleEdit "" pos:[248,245] width:60 height:17 enabled:false text: hscaleEdit
editText YawEdit "" pos:[153,320] width:85 height:17 enabled:false text: yEdit
editText YawScaleEdit "" pos:[248,320] width:60 height:17 enabled:false text: yscaleEdit
editText PropEdit "" pos:[153,395] width:85 height:17 enabled:false
--Labels
label CopyMinLabel "Start Frame" pos:[25,205] width:70 height:18
label CopyMaxLabel "End Frame" pos:[25,249] width:70 height:18
label NewFramesLabel "Start Frame" pos:[25,318] width:70 height:18
on SelectObjButton picked obj do
(
SelectObjButton.text = obj.name
userAnimatedObj = obj
)
on PitchButton picked obj do
(
PitchButton.text = obj.name
PitchAnimation = obj
if obj != undefined do
(
PitchEdit.enabled = true
PitchScaleEdit.enabled = true
CopyPitchChk.enabled = false
)
)
on CopyMinEdit entered firstFrameCopy do -- Set Minimum Frame to Export
(
firstFrameCopyVal = firstFrameCopy as float
)
on CopyMaxEdit entered lastFrameCopy do -- Set Maximum Frame to Export
(
lastFrameCopyVal = lastFrameCopy as float
)
on NewFramesEdit entered newFrame do
(
NewFrameVal = newFrame as float
)
--Gray out PickButtons for NonVMGroup, when P/R/H/Y/T checkboxes state changed.
on CopyPitchChk changed theState do
(
if CopyPitchChk.state == true then
(
PitchButton.enabled = false
)
else
(
PitchButton.enabled = true
)
)
on CopyRollChk changed theState do
(
if CopyRollChk.state == true then
(
RollButton.enabled = false
)
else
(
RollButton.enabled = true
)
)
on CopyHeaveChk changed theState do
(
if CopyHeaveChk.state == true then
(
HeaveButton.enabled = false
)
else
(
HeaveButton.enabled = true
)
)
on CopyYawChk changed theState do
(
if CopyYawChk.state == true then
(
YawButton.enabled = false
)
else
(
YawButton.enabled = true
)
)
on CopyTransChk changed theState do
(
if CopyTransChk.state == true then
(
PropButton.enabled = false
)
else
(
PropButton.enabled = true
)
)
on CopyKeysBtn pressed do
(
--Pitch Checked
if (CopyPitchChk.state) then
(
SelectedObject = userAnimatedObj.custom_attributes[#Pitch][#Pitch_Animation].controller
VehicleMotion = $VehicleMotion.custom_attributes[#Pitch][#Pitch_Animation].controller
CheckBox SelectedObject VehicleMotion
)
--Roll Checked
if (CopyRollChk.state) then
(
selectedObject = userAnimatedObj.custom_attributes[#Roll][#Roll_Animation].controller
VehicleMotion = $VehicleMotion.custom_attributes[#Roll][#Roll_Animation].controller
CheckBox SelectedObject VehicleMotion
)
--Heave Checked
if (CopyHeaveChk.state) then
(
selectedObject = userAnimatedObj.custom_attributes[#Heave][#Heave_Animation].controller
VehicleMotion = $VehicleMotion.custom_attributes[#Heave][#Heave_Animation].controller
CheckBox SelectedObject VehicleMotion
)
--Yaw Checked
if (CopyYawChk.state) then
(
selectedObject = userAnimatedObj.custom_attributes[#Yaw][#Yaw_Animation].controller
VehicleMotion = $VehicleMotion.custom_attributes[#Yaw][#Yaw_Animation].controller
CheckBox SelectedObject VehicleMotion
)
--Transport Checked
if (CopyTransChk.state) then
(
selectedObject = userAnimatedObj.custom_attributes[#Transport][#Transport_Animation].controller
VehicleMotion = $VehicleMotion.custom_attributes[#Transport][#Transport_Animation].controller
CheckBox SelectedObject VehicleMotion
)
--Pitch Selected
if PitchButton != undefined then
(
SelectedObject = (pitchanimation as string + ".rotation." + pedit + ".controller") -- controller I want to read
VehicleMotion = $VehicleMotion.custom_attributes[#Pitch][#Pitch_Animation].controller -- controller I'm writing to
CheckBox SelectedObject VehicleMotion --current function (works when both Selected Object and VehicleMotion are custom_attributes)
)
)
)
createDialog MotionKeyCopy style:#(#style_titlebar, #style_border, #style_sysmenu, #style_minimizebox)
--createDialog KeyCopyRollout