ScriptSpot

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 · 2021-11-24

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

titane357 · 2021-11-25

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

.

jahman · 2021-11-25

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

titane357 · 2021-12-28

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

AND

obaida · 2022-01-19

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" ?