PDA

View Full Version : If All Objects - Checker


JokerMartini
03-03-2012, 07: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
)
)

denisT
03-03-2012, 07:51 PM
$selection/helpers/*_l_*.count == $selection.count

:)

JokerMartini
03-03-2012, 07:58 PM
once again you condense it quite a bit id say.

wont that bug out my code because it things that /* is a comment and now its all green.

Thanks Denis

denisT
03-03-2012, 08:37 PM
wont that bug out my code because it things that /* is a comment and now its all green.

oops...

$selection/helpers/'*_l_*'.count == $selection.count

that's more correct

JokerMartini
03-03-2012, 09:01 PM
is it possible to put a variable in the name. Because right now it is evaluating the entire scene for that "_l_" which every object on the left has that. I need it to evaluate just the selection of objects.

theGuide = "leg_l_"
$selection/helpers/'*theGuide*'.count == $selection.count

denisT
03-03-2012, 10:04 PM
is it possible to put a variable in the name. Because right now it is evaluating the entire scene for that "_l_" which every object on the left has that. I need it to evaluate just the selection of objects.

theGuide = "leg_l_"
$selection/helpers/'*theGuide*'.count == $selection.count

i don't have max at the moment but after thought a little i see that my method probably wrong. you have to double check it.
to pass a string variable is easy. make a string and execute it:

(execute ("$selection/helpers/'*" + pattern + "*'")) as array

CGTalk Moderation
03-03-2012, 10:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.