ScriptSpot

Forum topic · General Scripting

Select objects by prefix and group them using group name same as prefix

By zwrtron · 2015-07-23

Description

Hello everyone, I started with maxscript few days ago and I'm stuck in this.
I have multiple objects in scene, like: (objectnames)

color_black
color_red
color_blue
bar_1
bar_2
plane001
plane002
...

and I would like to ask how do I use "select" function to select them.

I've used this to select one of them.

select ($color_black)

How can I select all object in scene starting with "color" "bar" "plane"?
and make group with names "color" "bar" and "plane"
Thanks for any help.

Comments (9)

`

pixamoon · 2015-07-25

I think you can use just:

select $color* 

or

select $bar*

etc :)

Thank you!

zwrtron · 2015-07-26

Thank you very much! It working well.
Could you please help me?

I have script to select and group these objects but I have an issue with object names inside the group.

Example:

I have objects:


Plane001
Plane002
Plane003

And I have following script:


clearSelection()
select $plane*
actionMan.executeAction 0 "40140"
$.name ="plane"
clearSelection()

The problem is, that it renames also objects inside the group.

So the group called 'plane' contains objects all named 'plane' instead of original names (plane001, plane002 ...);

I've also tried and doesnt help.


clearSelection()
select $body*
actionMan.executeAction 0 "40140"
clearSelection()
select $Group001
$.name ="body"
clearSelection()

`

pixamoon · 2015-07-26

try this one:


a = $plane*
g = group a
g.name = "plane"

or


a = $plane*
g = group a name:"plane"

or one line:


g = group ($plane*) name:"plane"

zwrtron · 2015-07-26

Wow, thank you! It's working.

`

pixamoon · 2015-07-26

no prob :) got one more idea, if you want to do it for multiple names at once:


names = #("box","plane","sphere","teapot")
for a in names do execute("g = group $"+a+"* name:\""+a+"\"")

Cheers
Pixamonn

zwrtron · 2015-07-26

Thank you very much, working as expected. :)

thanks

mani_kalantar · 2017-01-18

hi.
i rummade maxscript help for about 3 weeks and it was just dumb. i found the answer here. thanks.

select all groups

maryamabdulrazaq@hotmail.com · 2017-03-22

I am trying to write a line of a script which basically tells 3ds max to select all groups. All I am able to do in max script listener is to see the name of objects selected in one line. If you can write that line for me, I can integrate it with some other lines to make a script that aims to export each individual group to a separate file. I really need that to breakdown the weight of a massive interior project which will, hopefully, reduce the render time after being combined by using the method of "xref scene".

Code

sable806 · 2017-03-30

Hello, this should work but i'm not sure this is the simplest way to do it, but it works for me.


groupArr = #()

for i in helpers do
(
	if (isGroupHead i) == true then
	(
		append groupArr i
	)
)

select groupArr