Select by prefix name

Select by prefix name

Anonymous
Not applicable
4,735 Views
16 Replies
Message 1 of 17

Select by prefix name

Anonymous
Not applicable
I want to select objects based on their prefix name.

Example:
I have a master control called "Bunnies_ctrl"

I have 3 helper objects called "Bunnies_helper"
I have 3 helpers objects called "Bunnies_temp"

First how do I collect the prefix of the selected objects name? I want to collect all the characters until i get to the underscore "_" so the result of the variable would then be "Bunnies"

Then I would use that variable to select the other helper objects. For example
select "Bunnies" + "_helper"
select "Bunnies" + "_temp"

The reason I want to collect the prefix is because it changes from "Bunnies" to "Donuts"
0 Likes
4,736 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable
I want to select objects based on their prefix name.

Example:
I have a master control called “Bunnies_ctrl”

I have 3 helper objects called “Bunnies_helper”
I have 3 helpers objects called “Bunnies_temp”

First how do I collect the prefix of the selected objects name? I want to collect all the characters until i get to the underscore “_” so the result of the variable would then be “Bunnies”

Then I would use that variable to select the other helper objects. For example
select “Bunnies” + “_helper”
select “Bunnies” + “_temp”

The reason I want to collect the prefix is because it changes from “Bunnies” to “Donuts”


I'm assuming that by 'collect' you mean select, in which case the easiest way to select objects based on a prefix is to use a wildcard.


select $Bunnies*


But, that doesn't sound like what you want. I'm having a bit of trouble understanding exactly what the workflow you're looking for is. So I'm assuming you want to select the master control object (*_ctrl), run your script script, and have it select all of the associated helper objects.

First part is pretty straightforward. Get the selected object's name, parse through it using "_" as a delimiter, store that prefix as a variable.


ssSelected = $.name as stringStream --gets the name of the selected object as a stringstream and puts that into a ssSelected variable
strPrefixSelected = readDelimitedString ssSelected "_" --reads ssSelected using "_" as a delimiter and puts that into strPrefixSelected variable


I hope you're not actually using the exact same name for multiple nodes...that's generally a bad practice, but here's the bit you asked for:

strHelpers = strPrefixSelected + "_helper"
strTemp = strPrefixSelected + "_temp"
select strHelpers
selectmore strTemp


I would probably take a slightly different approach though, and select any node with the prefix:

nodeControl = $ --stores originally selected "_CTRL" node so we can remove it from selection at the end
strSelectWithWildcard = "$" + strPrefixSelected + "*" --building the full string with node identifier and wildcard so we can select every node that starts with "Bunnies"
select (execute strSelectWithWildcard) --execute Compiles and evaluates the contents of the string as a MAXScript expression and returns the result of the evaluation. Coverts "$Bunnies*" string into $Bunnies* maxScript code.
deselect nodeControl --deselects _CTRL" node, leaving us with "_Helper" and "_temp" nodes selected.
0 Likes
Message 3 of 17

Steve_Curley
Mentor
Mentor

prefix = (filterString $.name "_")

select (execute ("$" + prefix + "_*")) --all "Bunnies_" objects
--or
select (execute ("$" + prefix + "_helper*")) --all "Bunnies_helper" objects
-- or whatever else you want


What you really should be wanting to do is to reply to your existing threads, especially when they have replies which you have not yet even acknowledged, before posing further questions...

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 4 of 17

Anonymous
Not applicable
That is essentialy the same thing, but in a much more condensed format.
0 Likes
Message 5 of 17

Anonymous
Not applicable
now say for example my object is names this

"Rabbit_alt_01"

I've got the way to select the first part of the word which would be
"Rabbit"

now is there a way to select all the characters between the first and second underscore no matter what the character count is. Then store the remaining letters into a variable.

so if i have to objects
"Rabbit_alt_05"
"Donut_helper_07"

I could extract the variables

var1 = Rabbit
var2 = alt
var3 = 05
or if i used it on the second word it would result
var1 = Donut
var2 = helper
var3 = 07
0 Likes
Message 6 of 17

Steve_Curley
Mentor
Mentor
Just read the Maxscript help for FilterString - it returns an array of strings containing exactly what you're asking for.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 7 of 17

Anonymous
Not applicable
What I was initially searching for in the help file was not returning the results I needed. I did however find the filterstring stuff and got everything I needed with using tokens. Thanks guys for the help.
0 Likes
Message 8 of 17

danny.austin
Advocate
Advocate
how would one go about selecting an object whos name had a prefix containing a "* </code>

This doesn't work and no errors are shown in the listener.

Any thoughts?

Thanks
0 Likes
Message 9 of 17

Steve_Curley
Mentor
Mentor
select $\* 

Brackets are "special characters" so they need to be escaped (the backslash) so Max gets the [ character rather than thinking it has to do something special with it. Exactly the same as having to escape a double-quote in order to put one into a string.

var = "fred" (results in var being equal to fred)
var = "\"" + "fred" + "\"" (results in var being equal to "fred")

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 10 of 17

Anonymous
Not applicable
I have not Max here to test, but may try enclosing with single quote:
select $''*
0 Likes
Message 11 of 17

Anonymous
Not applicable
Ah, we post at the same time 🙂 is my suggestion above will work too?
0 Likes
Message 12 of 17

Steve_Curley
Mentor
Mentor
Hi Anubis - where have you been hiding? 😉

Unfortunately no, that doesn't work in this particular instance (I just tried it). I don't think Maxscript can use ' as a replacement for " unlike some languages.

For example, var = '"fred"' (results in Undefined)

I was in the process of explaining why the backslashes work when you posted 😉

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 13 of 17

Anonymous
Not applicable
Hi Steve, interesting... as I remember, single quote was used in such literal form when within the name has space (interval), but as I not use special characters, I not thought about them.

As about me... well, am start learning programming languages and somehow turn Max'ing on the background, mostly as hobby 🙂
0 Likes
Message 14 of 17

Steve_Curley
Mentor
Mentor
Programming is fun, and satisfying when the program works as intended. Likewise Max, so when you can combine the two it's pretty much a no-brainer 🙂

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 15 of 17

Anonymous
Not applicable
Agree, I appreciate the way you encourage me to return to Max, and probably I will 🙂
0 Likes
Message 16 of 17

Steve_Curley
Mentor
Mentor
And they said I was a lousy salesman - pfft! 😄

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 17 of 17

Anonymous
Not applicable
😄

btw, I test a little and $'' still work but for exact name, w/o pattern (*) at the end. And for interval - $'N A M E' and $'N A M E'* - both works. Ahh, and if there both pressent (spec. chars and interval) like "", then needs single quotes + escape (\) - $'\'*
0 Likes