ScriptSpot

Forum topic · Scripts Wanted

Convert Group to mesh

By crystal3d · 2010-04-17

Description

summary:
lets say; you have a tree object with all leaves as separate meshes , when attach them into one big heavy mesh at once, max crashes.

but i can attach them one by one which takes quite alot of time...

the script will divide the group of high level geometery into 3-10 meshes.

how long does it take to make a script like this one below?is it beginner level?

get selected group's name

explode group

rename the meshes inside , sequentially according to group name like: "groupname_01-02-03"

count polygon of each mesh.

attach small(number of polygon) meshes to "groupname_01" until
mesh reaches 1000 polygons.then

attach medium meshes untill mesh reaches 1000 polygons and name it:"groupname_M_01,02..."

rename large meshes that has more than 1000 polygons as "groupname_L_01,02,03.."

attach all created meshes in to one big mesh , named"groupname"

looking foward to any replies.

thanks.

Comments (16)

thanks

pproestos · 2019-03-10

Great and useful script, thanks Graph.
God bless you.

Graph · 2010-05-30

select what you want to combine and run the script ;)

tassel · 2011-10-04

Nice one Graph :)

An "max group ungroup" at the end is also nice ;)

Break face material id

A.Kavyani · 2016-02-01

Hi dear raphael,
your code works like a charm but when I apply it to my objects with diffrent material id,material id break and all of the material are in 1.

Graph · 2010-05-24

tested this one with 2k objects and max didnt crash, just froze a bit:
have phun


(
	max create mode
	disableSceneRedraw()
	with undo off
	(
		
		local sel = for o in selection where superclassOf o == geometryClass collect o
		local meshO = sel[1]
		deleteItem sel (findItem sel meshO)
		
		convertToMesh meshO
		
		for o in sel do attach meshO o
		
	)
	enableSceneRedraw()
)

crystal3d · 2010-05-24

hello and thanks for interest;

i copy pasted your script , and ran it but nothing happened?

as i stated before, i have no scripting experience

Hey, this is partially working great!

crystal3d · 2011-10-04

Some problems though...

1)It does not give the group's name to the attached object

2) if i run it without a selection, it gives an error and stops,
the real problem is it stops after the command :" disableSceneRedraw()" so the viewpot stops untill i restart max,

can it just warn instead?

crystal3d · 2010-05-21

i am still looking for a one-click solution :)

crystal3d · 2010-04-26

this example script of yours is "no-go" for non-scripters sadly.

atm i explode the group , select one and use attach list to sort by face count , attach them gradually...

Anubis · 2010-04-26

Ok, you need to sort them by face count and then attach them gradually, and I'll try to help you, but is there a script for non-scripters?... So try this for illustration:

b = box() -- create a box
(getPolygonCount b)[1] --> 12
-- so? this return poly-count
b.name = (getPolygonCount b)[1] as string --> rename the box to "12"
-- now make an example array of strings (just for test):
a = #("13", "0", "-22", "7")
sort a --> #("-22", "0", "13", "7")

With this in mind I hope you catch my idea that is to (1) rename the objects (using their poly-count as names), (2) collect their names to array, (3) sort array, (4) attach. Lets try then, - after explode the group, select all its objects and run the script:

-- 1st rename them
for i in selection do (i.name = (getPolygonCount i)[1] as string)
a = for i in selection collect i.name -- collect their names
sort a -- sort the array
select (getNodeByName a[1]) -- select first object
deleteItem a 1 -- remove it from the array (this not delete the node, just array item)
-- last step: attach
-- if in 1 loop will be:
for i in a do attach selection[1] (getNodeByName i)
-- and if is this to "hard", you can break the procedure, e.g.
for i=1 to 5 do ( -- this will attach only the first 5 objects
    attach selection[1] (getNodeByName a[i])
    deleteItem a i
) -- end of step 1
-- end so on...

crystal3d · 2010-04-20

Hi Anubis ;
i copied and pasted your script , i grouped 27 objects , selected the group01 and ran the script:

-unable to convert:undefined to type:

and highlights this string at 7:
"if (getPolygonCount allObjs[i])[1] <= 500 do ("

http://yfrog.com/j3test1grp2meshj (error screen)

Anubis · 2010-04-20

Ok, I suspect so you have not MaxScript knowledge. This is a snippet code that you need to modify for your needs. The error itself come from the "allObjs" that Max see as undefined. In this 1st step:

allObjs = selection as array -- collect all to array

you need to select your objects first and collect them to the array. If they are grouped, just ungroup before.

crystal3d · 2010-04-20

yes indeed ;i am at scripting 0 , if "collect to array "means that i really have to create an array some how :) will try...

i hope just mean to explod the group+select the objects and run the script... which is my cup of tea.

Anubis · 2010-04-20

Well, when my code will not help alot :) My idea was to select all objects what need to be attached and organize them into arrays (by objects poly-count). But as you group as you dont need this organazing step. So, shortly, all what you need is to know the name of the object to wich you will attach. Lets to sey it is named "main"; [1] ungroup 1st group; [2] select ungrouped objects and [3] run this code line:

for i in selection do attach $main i

...and repeat steps 1-3 for all groups.

I hope this help allObjs =

Anubis · 2010-04-19

I hope this help

allObjs = selection as array -- collect all to array
trgMesh = allObjs[1] -- mesh to attach to
deleteItem allObjs 1 -- remove it from the array

pass1 = #() -- array to store (for example) obj with poly's <= 500
for i=1 to allObjs.count do (
    if (getPolygonCount allObjs[i])[1] <= 500 do (
        append pass1 allObjs[i]
        deleteItem allObjs i
    )
)

pass2 = #() -- array to store (for example) obj with poly's <= 1000
for i=1 to allObjs.count do (
    if (getPolygonCount allObjs[i])[1] <= 1000 do (
        append pass2 allObjs[i]
        deleteItem allObjs i
    )
)
-- and so on...

for i in pass1 do attach trgMesh i -- attach process pass 1
for i in pass2 do attach trgMesh i -- attach process pass 2
-- and so on...

crystal3d · 2010-04-17

for example it took 20 minutes to attach a 500k faced furniture model into one mesh, i had to do it in 5 passes...
if i did it on one go! my system would hang , its 2 gbs xp64..