Maxscript help - weld vertices

Hello maxscript genuises!

looking for a script that will do the following nice and quickly:

- take 1 or several editable meshes
- weld vertices (with a low threshold of 0.01 or 0.001 - doesnt need to have a UI)
- auto smooth the geometry with a value of 30

thats it!

it can convert them to editable poly if thats easier/quicker, the main thing is that all scripts I have found take ages on heavy geometry

The welding is what takes ages! Especially on heavy geometry. I deal with a lot of engineering data and some of the more complex pieces can take upwards of two (2) hours to weld with a threshold of 0.001. So I usually end of having about 4-5 copies of max running on my computer welding different pieces and then merging them all together.

I would be interested in a similar script as well. So I’m interested in how this turns out.


-- TYPE IN YOUR WELD VALUE HERE

theWeldThresh = 0.1

-- TYPE IN YOUR SMOOTH ANGLE HERE

theSmoothAngle = 30

theMeshes = selection as array

for i = 1 to theMeshes.count do
(

	theWeldMod = Welder threshold:theWeldThresh weldMethod:0

	--theWeldMod.threshold = theWeldThresh
	--theWeldMod.weldMethod = 0

	addModifier theMeshes[i] theWeldMod

	theSmoothmod = smooth autosmooth:on threshold:theSmoothAngle

	addModifier theMeshes[i] theSmoothmod

)

That’ll do it, but you can also use the welder modifier - it’s for welding cloth that’s to be ripped in a cloth sim later but it’s the same command as weld in edit poly or mesh. Then the smooth modifier. You can select all your objects and just apply these two modifiers and get them as instances if one value will work for the lot!

thanks John, very useful!

for some reason, having ‘don’t weld sel edges’ unticked seems to work better (in that it doesnt make otherwise invisible edges visible) how would we add that in to the magical recipe?

and at the end, could it collapse to editable poly?

actually the bit about ‘don’t weld sel edges’ might not be accurate. < EDIT: It is

Man, I wish 3dsmax didnt insist on only using 2% of the available processor power for things like this!!!

what I have done in the past, is convert an editable mesh to editable poly, and then weld vertices in the editable poly options, it seems to be MUCH faster.

Would converting to editable poly in the script speed things up?

Yeah, maxscript operations aren’t multithreaded. ;/

What usually speeds up the calculation is to switch off undo and switch to the create panel, also disable viewport updates.


max create mode
with redraw off(
undo off (
--code here
)
)
-- TYPE IN YOUR WELD VALUE HERE

theWeldThresh = 5.0

-- TYPE IN YOUR SMOOTH ANGLE HERE

theSmoothAngle = 30

theMeshes = selection as array

max create mode

with redraw off
(
undo off 
(

for i = 1 to theMeshes.count do
(

	theWeldMod = Welder threshold:theWeldThresh weldMethod:0 dontWeldSelectedEdges:off

	--theWeldMod.threshold = theWeldThresh
	--theWeldMod.weldMethod = 0

	addModifier theMeshes[i] theWeldMod

	theSmoothmod = smooth autosmooth:on threshold:theSmoothAngle

	addModifier theMeshes[i] theSmoothmod

	convertTo theMeshes[i] Editable_Poly

)
)
)

Those bits and Rens’ speed bits added.

Good geekery John!

What’s the main advantage to using the welder modifier or the Weld Vertex modifier in this situation?

Just curious.