[Closed] Selecting objects with wildcard based on currently selected objects name
I’m working on a character renaming script.
Suppose I have an object, called “Character”. suppose I have two more objects called “Character – Head” and “Character – Body”
What I need to be able to do is select all objects that start with the the term “Character”.
You’d think it would be easy:
select $Character*
not quite.
You see eventually the script will be replacing the term “Character” with whatever name you give that character. Click of a button and the object “Character” is now known as “Humphrey”, the two other objects are “Humphrey – Head” and “Humphrey – Body”
Translation, i want to select all objects who’s name start with the name of the selected object.
Thanks to any and all
~Rob
Okay, you could try something like:
execute ("select $" + sStartsWith + "*")
The problem I see right now…is how do you determine the number of characters to start with?
If your selected object’s name is “Character – Head”, then doing “select $Character_-_Head*” isn’t going to select a hell of a lot…
Shane
I’ve spent way to much time thinking about this
local sName = undefined
if selection.count > 1 then
sName = $[1].name
else sName = $.name
-- User the first 60% of the name
local iNumCharacters = ((sName.count * (6.0 / 100) * 10) as integer) + 1
if iNumCharacters < 1 do iNumCharacters = 1
execute ("select $" + sName + "*")
This will take the first selected item and use 60% of the name as the bases for the wildcard.
The idea needs some tweaking, but I thought it was clever…
Shane
Rusty, I think you are over thinking… If I read the op right, your first response will work fine because we’re assuming that the selected object only has the root name. If not, a better method for extracting the root would be to search for the “–” (with findString) and use everything before that.
Yeah, I’ve been reading Windows APIs all afternoon and just need to breakout…
Ahh yes, more naming filtering conventions. Soon this forum will be filled with all sorts of code to solve “if by name…” problems. Furyofaseraph, head over to this thread just in case you need more naming filtering ideas
http://forums.cgsociety.org/showthread.php?f=98&t=546048
i had some similar problems.
also just to thro this in. If you need to change anything on selected objects in the scene
totalobjects=selection.count
for i = 1 to totalobjects do
(
sum code here
)
So long as the selection is not going to change, this will work fine. I had an interesting issue a while back that was caused by this very type of loop. You always safer casting to an array first, it will in effect take a snapshot of the collection.
But yes, you are absolutly right, that will work also.
Thank you all.
The execute trick worked perfectly, and I really don’t need anything more complex at this point. I cannot believe I forgot all about that.
And we were have so much fun to
Good to hear you found a solution…
Shane