[Closed] Using controllers with scripted plugins – "this node"
I working on scripted camera plugin. I want to assign created camera as target in look at constrain controller of another object, but no success.
plugin Camera TestCamera
name:"Test Camera"
classID:#(0x4e7b5f95, 0x4e4b5f95)
category:"Standard"
extends:FreeCamera replaceUI:true
(
local nodeHandle = undefined
parameters main rollout:params
(
targ type:#node
)
rollout params "Test camera"
(
pickbutton pickTarg "pick object" width:140
on pickTarg picked obj do
(
if obj != undefined do
(
targ = obj
print (maxOps.getNodeByHandle nodeHandle) -- debug
targ.rotation.controller = LookAt_Constraint()
targ.rotation.controller.appendtarget (maxOps.getNodeByHandle nodeHandle) 100
-- targ.rotation.controller.appendtarget (TestCamera()) 100 -- works
targ.rotation.controller.target_axis=2
)
)
)
on attachedToNode obj do
nodeHandle = obj.inode.handle
)
Problem seems to be in getting node created by the script. I also tried to obtain it by refs.dependentNodes this but also without luck.
too many mistakes in this code. actually they are not too bad but they make the code not workable.
so there is the way how to do these things:
plugin Camera TestCamera
name:"Test Camera"
classID:#(0x4e7b5f95, 0x4e4b5f95)
category:"Standard"
extends:FreeCamera replaceUI:true
(
fn updateTarget = if this != undefined do
(
this.params.pickTarget.text = if iskindof this.targetNode NodeMonitor and isvalidnode this.targetNode.node then this.targetNode.node.name else "Pick Target"
)
parameters main rollout:params
(
node type:#maxobject
targetNode type:#maxobject
on targetNode set val do
(
updateTarget()
)
)
rollout params "Test Camera"
(
pickbutton pickTarget "Pick Target" width:140
on pickTarget picked obj do if obj != undefined do undo "Set the Target" on
(
targetNode = NodeMonitor node:obj
c = obj.rotation.controller = createinstance LookAt_Constraint target_axis:2
c.appendtarget node.node 100
)
on params open do updateTarget()
)
on attachedToNode obj do
(
format "attach >> %
" obj
node = NodeMonitor node:obj
)
)
using NodeMonitor we avoid Dependency Loop.
also… because the plugin allows multiple targets (at least it doesn’t do anything to prevent it) it’s better to have a target tab instead of a single target.
try adding this function and use it to get the node
fn getNode = (refs.dependentNodes ((refs.dependents this)[1]))[1]
Error message says that there is no refs.dependentsNodes
I’m using Max 9.
try this one
fn getNode = refs.dependentnodes (custAttributes.getOwner this) firstonly:on
Hmm, I have extra ‘s’ just in my reply.
Seems my refs not contains member dependentNodes:
Unknown property: "dependentNodes" in #Struct:refs(
dependents:<fn>,
DependencyLoopTest:<fn>,
dependsOn:<fn>)
I wrote this function:
fn getNode =
(
local theNode = undefined
local con = true -- continue loop
for obj in refs.dependents this where con and isValidNode obj and obj.baseobject == this do
(
theNode = obj
con = false
)
theNode -- return
)
It returns vaild scene node, but anyway the controller wont works with it :banghead:
Since the rollouts only appears if and only if this single object is selected, with plug-ins, custom attributes or so, I tend to use $ or selection[1], or any way to retrieve the first (and only) selected item.
I did tried to used this with various results so I returned to mxs fundamentals.
because this is not true
this one is not right.
user can work with “Pinned Stack” which makes CA UI visible for unselected nodes.
Ow, never thought of this (neither did i found someone using it, but still, you’ve got a point ) My bad then !
I found what’s going on. I tried to use parameter type of #node, but seems no works how I supposed to.
For obtaining current scripted plugin node I figured out two methods that works fine.
Function:
fn getNode =
(
for n in refs.dependents this do
print n
local theNode = undefined
local con = true -- continue loop
for obj in refs.dependents this where con and isValidNode obj and obj.baseobject == this do
(
theNode = obj
con = false
)
theNode -- return
)
Or handle to node stored as parameter:
parameters main
(
nodeHandle type:#integer animatable:false
)
on attachedToNode obj do (nodeHandle = obj.inode.handle)
fn getNode = (maxOps.getNodeByHandle nodeHandle)