Script to select all objects with same name as current selection

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2009
Script to select all objects with same name as current selection

Hi Guys,

Im a total n00b at MaxScript and have hit a wall.

I select an object then when I click my button I want it to select all objects that have the same name as that object.

I attempted it with:

sname = $.name
for i in $.(sname) do selectmore i

as this works to select all objects with 'tree' in the name:

for i in $*tree* do selectmore i

however I can't get it to work,

any ideas?

Thanks,

Leigh
 
  03 March 2009
If they have the exact same name that should work:

on Button pressed do
(
if selection.count == 1 do
(
Name_Var = $.name
for o in objects where o.name = Name_Var do selectmore o
)
)


Last edited by Piflik : 03 March 2009 at 05:26 PM.
 
  03 March 2009
Originally Posted by lellis2k: sname = $.name
for i in $.(sname) do selectmore i


You can't use a variable in a name path, I'm afraid.
If your object is "Teapot" and you're looking for objects such as "Hello.Teapot", "World.Teapot" (i.e. ending in ".Teapot"), you'd have to use something like:


sname = $.name
nodes = for o in objects where (matchPattern o.name pattern:("*." + sname)) collect ( o )
selectMore nodes


( if sname doesn't contain periods, there's a few other methods you can use, but the above is pretty flexible ).

==========

Originally Posted by Piflik: If they have the exact same name that should work:

on Button pressed do
 (
 if selection.count == 1 do
 (
 Name_Var = $.name
 for o in objects where o.name = Name_Var do selectmore o
 )
 )
 


Note that the above should be "o.name == Name_Var" (comparison, instead of variable value assignment)
 
  03 March 2009
Originally Posted by ZeBoxx2: You can't use a variable in a name path, I'm afraid.


Not directly but you could build a namepath string and execute it.


on button pressed do
(
  if selection[1] != undefined then
	select (execute ("$*"+selection[1].name+"*"))
)

Which off course only makes sense if the name can be found in other object completely... which won't be the case often, me thinks...

-Johan
__________________
Online: LinkedIn
 
  03 March 2009
Originally Posted by JHN: Not directly but you could build a namepath string and execute it.


  select (execute ("$*"+selection[1].name+"*"))
  



The problem with that approach is when your objects have a period in their name. E.g.

 -- This works
 a = sphere name:"Foot_L"
 b = sphere name:"OtherDude.Foot_L"
 select (execute ("$*"+a.name+"*"))
 $Sphere:Foot_L @ [0.000000,0.000000,0.000000]
 $Sphere:OtherDude.Foot_L @ [0.000000,0.000000,0.000000]
 OK
 
 -- This goes boink.
 a = sphere name:"Foot.L"
 b = sphere name:"OtherDude.Foot.L"
 select (execute ("$*"+a.name+"*"))
 
 $Sphere:Foot.L @ [0.000000,0.000000,0.000000]
 $Sphere:OtherDude.Foot.L @ [0.000000,0.000000,0.000000]
 -- Error occurred during fileIn in StringStream:"$*Foot.L*"
 -- Error occurred in anonymous codeblock; filename: none; position: 0
 --  Frame:
 -- Syntax error: at end, expected <factor>
 --  In line: 
 


At one point I tried a workaround and it told me there's no such property 'L' in "$*Foot//etc.". Might've missed some magic there, not sure.
Edit: like escaping the period character. Though at that point you might as well matchpattern >_<

ideally, getNodeByName would take wildcard characters - but alas %)

Last edited by ZeBoxx2 : 03 March 2009 at 08:18 PM.
 
  03 March 2009
i don't know the exact notation but with special character you should use ''

$'bla.kjasd 3'
as far as i remember
 
  03 March 2009
Insanto is correct, anything that has anything but alphanumeric characters should be wrapped in ' '. Richard if you modify your second script to:
Quote: a = sphere name:"Foot.L"
b = sphere name:"OtherDude.Foot.L"
select (execute ("$*'"+a.name+"'*"))
It won't error any more.

-Eric
__________________
"The Evil Monkey hiding in your closet."
 
  03 March 2009
Oh yeah, that's right!

well... screw the matchpattern, then - just go with dollarasteriskquotedoublequoteplus

... but what happens if it contains a quote?
 
  03 March 2009
I always use: \" which is the literal for ".
 
  03 March 2009
Originally Posted by thatoneguy: I always use: \" which is the literal for ".


as in the following...?
select (execute ("$*\""+a.name+"\"*"))
 
  03 March 2009
Yes.

EDIT: Wait... no.

EDIT: Wait... Wait... Yes.
 
  03 March 2009
Yes, if you wanted to search for "$*"'Foot.L'"*" (NOTE: you would still need the ', because of the non-alphanumeric characters), instead of "$*'Foot.L'*".

-Eric
__________________
"The Evil Monkey hiding in your closet."

Last edited by PiXeL_MoNKeY : 03 March 2009 at 10:43 PM.
 
  03 March 2009
Oh I thought the literal escape would force it.

What about


@"Foot.l"

EDIT: Haha nope that doesn't format right at all. I see what the problem is now. ' it is.

Last edited by thatoneguy : 03 March 2009 at 10:43 PM.
 
  03 March 2009
Well, what I was getting at with the first one (single quotes)...

This fine...

a = sphere name:"Foot.L"
b = sphere name:"OtherDude.Foot.L"
select (execute ("$*'"+a.name+"'*"))
$Sphere:Foot.L @ [0.000000,0.000000,0.000000]
$Sphere:OtherDude.Foot.L @ [0.000000,0.000000,0.000000]
OK
selection.count
 2


This is not so fine...

a = sphere name:"Foot'L"
b = sphere name:"OtherDude.Foot'L"
select (execute ("$*'"+a.name+"'*"))
$Sphere:Foot'L @ [0.000000,0.000000,0.000000]
$Sphere:OtherDude.Foot'L @ [0.000000,0.000000,0.000000]
OK
selection.count
0


This is definitely not fine...

a = sphere name:"'Foot.L"
b = sphere name:"OtherDude.'Foot.L"
select (execute ("$*'"+a.name+"'*"))
$Sphere:'Foot.L @ [0.000000,0.000000,0.000000]
$Sphere:OtherDude.'Foot.L @ [0.000000,0.000000,0.000000]
-- Error occurred during fileIn in StringStream:"$*''Foot.L'*"
-- Error occurred in anonymous codeblock; filename: none; position: 0
--  Frame:
-- Syntax error: at end of script, expected end of literal
--  In line: $*''Foot.L'*


Did I miss one?
 
  03 March 2009
By the time this thread is finished everybody is well educated in path literals.

@Zeboxx2: Funny thing you mention the use of . and ' in a name. Where I work we shoot people for using that, no questions, no trial.

Only underscores _ and and minus - are allowed. I mean really c'mon...

-Johan

P.s. I agree that getNodeByName should take wildcards, I cannot remember I ever used it's ability to return an array... of what, objects with the same name(!?) you have to really do your best to make a scene with objects with the same name...
__________________
Online: LinkedIn
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 07:51 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.