JokerMartini
03-03-2012, 06:13 PM
I've written a few functions that check if the selection of objects are either all "l" or "r", which stand for left and right. They also have to be point helpers.
The selection of objects has to meet 3 requirements and I've got a feeling that what I've written could be a bit more condensed so I figured I would go to the forums to get others opinions.
So what they need to require.
1. All objects have to be "classof Point"
2. All objects have to either contain "_l_" or "_r_". And only one or the other, not both.
3. Selection has to be greater >= 1
I'm using this as a callback selection-changed function which controls the enabled state of a button. Here is what I have.
fn state_LMirrorOK =
(
if selection.count <= 0 do return false
for obj in selection do
(
if (findString (obj.name) "_l_") == undefined do
return false
)
return true
)
fn state_RMirrorOK =
(
if selection.count <= 0 do return false
for obj in selection do
(
if (findString (obj.name) "_r_") == undefined do
return false
)
return true
)
fn state_GuideOK =
(
if selection.count <= 0 do return false
for obj in selection do
(
if classof obj != point do
return false
)
return true
)
fn fnMirrorGuidesCtrl = (
if state_LMirrorOK() OR state_RMirrorOK() AND state_GuideOK() then
(
rlRigCreator.btnMirrorGuides.enabled = true
)else(
rlRigCreator.btnMirrorGuides.enabled = false
)
)
The selection of objects has to meet 3 requirements and I've got a feeling that what I've written could be a bit more condensed so I figured I would go to the forums to get others opinions.
So what they need to require.
1. All objects have to be "classof Point"
2. All objects have to either contain "_l_" or "_r_". And only one or the other, not both.
3. Selection has to be greater >= 1
I'm using this as a callback selection-changed function which controls the enabled state of a button. Here is what I have.
fn state_LMirrorOK =
(
if selection.count <= 0 do return false
for obj in selection do
(
if (findString (obj.name) "_l_") == undefined do
return false
)
return true
)
fn state_RMirrorOK =
(
if selection.count <= 0 do return false
for obj in selection do
(
if (findString (obj.name) "_r_") == undefined do
return false
)
return true
)
fn state_GuideOK =
(
if selection.count <= 0 do return false
for obj in selection do
(
if classof obj != point do
return false
)
return true
)
fn fnMirrorGuidesCtrl = (
if state_LMirrorOK() OR state_RMirrorOK() AND state_GuideOK() then
(
rlRigCreator.btnMirrorGuides.enabled = true
)else(
rlRigCreator.btnMirrorGuides.enabled = false
)
)
