Some parts of my script are only working in specific circumstances

(
	clearlistener()
	obj = $
	clearselection()
	if (classOf obj.modifiers[1] != unwrap_UVW) then (
	addModifier obj (unwrap_UVW())
	)
	uv = obj.modifiers[1]
	uv.unwrap.edit()
	uv.unwrap2.setTVSubObjectMode(3)
	totalFaces = uv.unwrap.numberPolygons()
	print totalFaces
)

What its supposed to do is apply an unwrap_UVW modifier if one doesnt exist, then count the amount of faces on the object. However the count is only correct if there is a pre-existing unwrap modifier on the object, otherwise the print returns 0

Its an easy task to do but the catch is i need it to happen when the object isnt selected.

The above script works, sort of. If an unwrap_UVW is already present, the script correctly detects this and goes through the rest of the logic flawlessly, returning the correct number at the end.

However if an unwrap UVW is not preset, it correctly applies one, but then it seems to skip most of the logic after that, and the print returns 0 at the end.

My feeling is that this is some sort of problem with the script not refreshing the modifier stack properly after the new modifier is created. I dont know how i could do this though.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ZalitZ's picture

max modify mode

Hi,
I found a solution by keeping the obj selected and making sure you are on the modify panel.
Also you don't have to enter edit mode to get the number of polygons.

(
	clearlistener()
	obj = $
 
	if (classOf obj.modifiers[1] != unwrap_UVW) then (
	addModifier obj (unwrap_UVW())
	)
	uv = obj.modifiers[1]
 
	max modify mode
	totalFaces = uv.unwrap.numberPolygons()
	print totalFaces
)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.