[Maxscript] Faster way to add selection sets to verts

I been trying to get this bit of code to run faster.

Fn Make_In_Pos Type =
		(
			for i in (polyop.getVertSelection obj) do
				(	
					b += 1
					fs = obj.verts
					fs[(Type + (b as string))] = #{i}
					print Type
				)
			b = 0	
		)

What I am doing is taking an editable poly and selecting the verts I want and putting each vert into its own selection set. This code works fine for 300 or so verts but when you have 1000 or more verts the time it takes to add a selection set to each vert is a long time. Was wondering if there is a faster way to do this or a better. Thanks

Sorry I couldn’t make anything out of this, b is not declared outside the for loop scope so you get an error there, I can’t understand what is Type. Can you post a full working example so it’s easier to help? Cheers.

Make a plane or box. Convert to editiable poly. Select vert and run this code

		obj = $
		b = 0
			
		Fn Make_In_Pos Type =
		(
			for i in (polyop.getVertSelection obj) do
				(	
					b += 1
					fs = obj.verts
					fs[(Type + (b as string))] = #{i}
					--print (Type+b)as string
				)
			b = 0	
		)
		
		Make_In_Pos "Pos"

Sorry for the incomplete code.

Your script had no problem at all, this seems to be a bug related with arrays in Max. So your script executed fast but then it would get slow when creating the array in the selectionSets, this AFTER the script execution.

I’ve solved it by disabling the commandPanel with suspendEditing() and then resumeEditing()… Don’t ask me why, its usually the type of things I go for when having issues similar to this one, the usual hacks :slight_smile:

Here’s my version of your code, let me know if that helped.


fn Make_In_Pos_Optimized obj Type =
	(
		with redraw off with undo off (
			suspendEditing alwaysSuspend:true
			b = 1
			fs = obj.verts
			for i in (polyop.getVertSelection obj) do (					
				selName = Type + "_" + (formattedPrint b format:"03u")
				fs[selName] = #(i)
				b += 1
			)
			resumeEditing()
		)
	)

Cheers!
Artur

Yes thank you so much. Was not aware of that error.