MarcoBrunetta
05-28-2009, 03:21 AM
Here's a little experiment I've been playing with. For some time I've wanted to have in MAX the ability to "link" individual object properties so that whenever one changes the other does too. Think of it as "selective instancing", changing one object modifies another, but on a predefined way.
The following bit of code will create a rollout, where you can choose a Source Box and a Target Box and link them. Then, changing the height of the first will modify the width of the second. If this was extended so you could choose any two properties in any object (easy), or maybe something more elaborate like the distance between vertices (not so easy?), it could become useful perhaps.
IF LinkItArray == undefined DO LinkItArray = #()
struct linkItLink
(
sourceObj,
targetObj,
sourceProp,
sourcePropValue,
targetProp
)
rollout linkRoll "Link It!"
(
local sourceObj
local targetObj
pickButton linkSource "Source"
pickButton linkTarget "Target"
button linkBtn "Link It!"
ON linkSource PICKED arg DO
(
IF classOf arg == Box DO
(
sourceObj = arg
linkSource.text = arg.name
)
)
ON linkTarget PICKED arg DO
(
IF classOf arg == Box DO
(
targetObj = arg
linkTarget.text = arg.name
)
)
ON linkBtn PRESSED DO
(
IF targetObj != undefined AND sourceObj != undefined THEN
(
local newLink = linkItLink sourceObj:sourceObj targetObj:targetObj sourceProp:"height" sourcePropValue:sourceObj.height targetProp:"width"
append LinkItArray newLink
destroyDialog linkRoll
fn callbackFn theEvent theNode =
(
--print "Object Geometry Changed"
local objToCheck = GetAnimByHandle theNode[1]
FOR theLink in linkItArray DO
(
IF theLink.sourceObj == objToCheck DO
(
--print "Match Found!"
local theDifference = (theLink.sourcePropValue-(getProperty theLink.sourceObj theLink.sourceProp))
theLink.sourcePropValue = (getProperty theLink.sourceObj theLink.sourceProp)
setProperty theLink.targetObj theLink.targetProp ((getProperty theLink.targetObj theLink.targetProp)+theDifference)
)
)
)
local callbackItem = NodeEventCallback mouseUp:false geometryChanged:callbackFn
)
ELSE
(
messageBox "Select some boxes shmuck!" title:"DOH!"
)
)
)
createDialog linkRoll
The following bit of code will create a rollout, where you can choose a Source Box and a Target Box and link them. Then, changing the height of the first will modify the width of the second. If this was extended so you could choose any two properties in any object (easy), or maybe something more elaborate like the distance between vertices (not so easy?), it could become useful perhaps.
IF LinkItArray == undefined DO LinkItArray = #()
struct linkItLink
(
sourceObj,
targetObj,
sourceProp,
sourcePropValue,
targetProp
)
rollout linkRoll "Link It!"
(
local sourceObj
local targetObj
pickButton linkSource "Source"
pickButton linkTarget "Target"
button linkBtn "Link It!"
ON linkSource PICKED arg DO
(
IF classOf arg == Box DO
(
sourceObj = arg
linkSource.text = arg.name
)
)
ON linkTarget PICKED arg DO
(
IF classOf arg == Box DO
(
targetObj = arg
linkTarget.text = arg.name
)
)
ON linkBtn PRESSED DO
(
IF targetObj != undefined AND sourceObj != undefined THEN
(
local newLink = linkItLink sourceObj:sourceObj targetObj:targetObj sourceProp:"height" sourcePropValue:sourceObj.height targetProp:"width"
append LinkItArray newLink
destroyDialog linkRoll
fn callbackFn theEvent theNode =
(
--print "Object Geometry Changed"
local objToCheck = GetAnimByHandle theNode[1]
FOR theLink in linkItArray DO
(
IF theLink.sourceObj == objToCheck DO
(
--print "Match Found!"
local theDifference = (theLink.sourcePropValue-(getProperty theLink.sourceObj theLink.sourceProp))
theLink.sourcePropValue = (getProperty theLink.sourceObj theLink.sourceProp)
setProperty theLink.targetObj theLink.targetProp ((getProperty theLink.targetObj theLink.targetProp)+theDifference)
)
)
)
local callbackItem = NodeEventCallback mouseUp:false geometryChanged:callbackFn
)
ELSE
(
messageBox "Select some boxes shmuck!" title:"DOH!"
)
)
)
createDialog linkRoll
