ScriptSpot home

Forum topic · General Scripting

Error when used with more then one object

By titane357 · 2021-11-24

Description

Hi,
I tried to make a script to "Freeze" some objects:
I have spline object with subdivide, tyconform,.. in the stack, so to remove the need max calculate these objects, I do :
- create a snapshot of the object
- deactivate all modifiers
- add editpoly modifier
- remove all geometry in the modifier
- attach snapshot to the geometry.
It works fine for one object.( and I did a script to revert to "normal" geometry )
But when I use this script on multiple selection I got error.
"-- Runtime error: Requested sub-object level out of range: 1"
Anybody could help ? Thanks


(
	for o in selection where o.modifiers.count > 0 do 
		(			
		theTMesh = snapshotAsMesh o
		theNewMesh = Editable_mesh()
		theNewMesh.mesh = theTMesh 
		convertTo theNewMesh Editable_Poly
		delete theTMesh 

		o.modifiers.enabled = off

		cep = edit_poly()
		addModifier o cep
		max modify mode -- !!!

		subobjectLevel = 1
		max select all
		o.modifiers[#Edit_Poly].ButtonOp #DeleteVertex

		o.modifiers[#Edit_Poly].attach theNewMesh
		subobjectLevel = 0
		cep.name = "FREEZED"
		)
)
Comments (5)
miauu

.

(
selObjsArr = selection as array
for o in selObjsArr where o.modifiers.count > 0 do

Reply to miauu
titane357

Hi, Miauu !
Unfortunately, it make no difference...

Reply to titane357
Panteleev Sergey

.

you have to select each object inside the loop individually and activate modify panel to make it work

Reply to Panteleev Sergey
titane357

Hi jahman !
I read your post carefully and several times.
But I still don't know what I can do...
Cheers

Reply to titane357
obaida

AND

what you mean BY : "I have spline object with subdivide, tyconform,.. in the stack, so to remove the need max calculate these objects, I do :"

why not just (make a copy , delete all the modifiers and call the object "FREEZED" ?