CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
To minimize the ads you see on this page create a CGTalk account and log in HERE
Thread Closed share thread « Previous Thread | Next Thread »
 
Thread Tools Search this Thread Display Modes
Old 03-03-2009, 12:34 PM   #1
lellis2k
New Member
portfolio
Leigh Ellis
Sheffield, United Kingdom
 
Join Date: Mar 2009
Posts: 15
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
 
Old 03-03-2009, 05:22 PM   #2
Piflik
MXS Padawan
 
Piflik's Avatar
portfolio
Philipp Jutzi
Munich, Germany
 
Join Date: Apr 2008
Posts: 1,313
If they have the exact same name that should work:

Code:
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-03-2009 at 05:26 PM.
 
Old 03-03-2009, 06:32 PM   #3
ZeBoxx2
Lord of the posts
 
ZeBoxx2's Avatar
Richard Annema
Caustic Graphics / SplutterFish
Groningen, Netherlands
 
Join Date: Jul 2006
Posts: 1,461
Quote:
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:

Code:
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 ).

==========

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

Code:
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)
 
Old 03-03-2009, 07:46 PM   #4
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
Quote:
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.

Code:
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 | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Old 03-03-2009, 08:15 PM   #5
ZeBoxx2
Lord of the posts
 
ZeBoxx2's Avatar
Richard Annema
Caustic Graphics / SplutterFish
Groningen, Netherlands
 
Join Date: Jul 2006
Posts: 1,461
Quote:
Originally Posted by JHN
Not directly but you could build a namepath string and execute it.

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



The problem with that approach is when your objects have a period in their name. E.g.
Code:
-- 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-03-2009 at 08:18 PM.
 
Old 03-03-2009, 09:22 PM   #6
Insanto
Ghost Raccoon
 
Insanto's Avatar
portfolio
Raphael Steves
Technical Artist
Dusseldorf, Germany
 
Join Date: Nov 2008
Posts: 167
i don't know the exact notation but with special character you should use ''

$'bla.kjasd 3'
as far as i remember
 
Old 03-03-2009, 09:27 PM   #7
PiXeL_MoNKeY
Expert
 
PiXeL_MoNKeY's Avatar
Eric Craft
Dallas, USA
 
Join Date: Mar 2002
Posts: 5,630
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."
 
Old 03-03-2009, 09:39 PM   #8
ZeBoxx2
Lord of the posts
 
ZeBoxx2's Avatar
Richard Annema
Caustic Graphics / SplutterFish
Groningen, Netherlands
 
Join Date: Jul 2006
Posts: 1,461
Oh yeah, that's right!

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

... but what happens if it contains a quote?
 
Old 03-03-2009, 10:18 PM   #9
thatoneguy
Interesting User Title
 
thatoneguy's Avatar
portfolio
Gavin Greenwalt
Exec. VP of Pixel Mergers and Acquisitions
Straightface Studios
Seattle, USA
 
Join Date: Jan 2005
Posts: 2,332
I always use: \" which is the literal for ".
 
Old 03-03-2009, 10:26 PM   #10
ZeBoxx2
Lord of the posts
 
ZeBoxx2's Avatar
Richard Annema
Caustic Graphics / SplutterFish
Groningen, Netherlands
 
Join Date: Jul 2006
Posts: 1,461
Quote:
Originally Posted by thatoneguy
I always use: \" which is the literal for ".


as in the following...?
Code:
select (execute ("$*\""+a.name+"\"*"))
 
Old 03-03-2009, 10:30 PM   #11
thatoneguy
Interesting User Title
 
thatoneguy's Avatar
portfolio
Gavin Greenwalt
Exec. VP of Pixel Mergers and Acquisitions
Straightface Studios
Seattle, USA
 
Join Date: Jan 2005
Posts: 2,332
Yes.

EDIT: Wait... no.

EDIT: Wait... Wait... Yes.
 
Old 03-03-2009, 10:37 PM   #12
PiXeL_MoNKeY
Expert
 
PiXeL_MoNKeY's Avatar
Eric Craft
Dallas, USA
 
Join Date: Mar 2002
Posts: 5,630
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-03-2009 at 10:43 PM.
 
Old 03-03-2009, 10:39 PM   #13
thatoneguy
Interesting User Title
 
thatoneguy's Avatar
portfolio
Gavin Greenwalt
Exec. VP of Pixel Mergers and Acquisitions
Straightface Studios
Seattle, USA
 
Join Date: Jan 2005
Posts: 2,332
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-03-2009 at 10:43 PM.
 
Old 03-04-2009, 02:59 AM   #14
ZeBoxx2
Lord of the posts
 
ZeBoxx2's Avatar
Richard Annema
Caustic Graphics / SplutterFish
Groningen, Netherlands
 
Join Date: Jul 2006
Posts: 1,461
Well, what I was getting at with the first one (single quotes)...

This fine...
Code:
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...
Code:
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...
Code:
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?
 
Old 03-04-2009, 07:56 AM   #15
JHN
maxscript/c# lover
 
JHN's Avatar
Johan Boekhoven
Technical Artist
nmtrix.com
Netherlands
 
Join Date: Apr 2002
Posts: 1,714
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 | blog | nmtrix.com
Code: mxs+.net | c# | mb-python | php | html+js | mysql | python
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:52 AM.


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