Notifications
Clear all

[Closed] flattenMap call from inside a function does not work

Hi
I’m new to maxscript (started yesterday) and have a problem calling flattenMap from inside a function:


function AO_UVWUnwrap _Object =
(
	Unwrapper = UVWunwrap()
	Unwrapper.setApplyToWholeObject true
	addModifier _Object (Unwrapper)
	Unwrapper.setMapChannel 2
	Unwrapper.flattenMap 45.0 #() 0.001 true 0 true true
)

The ,appingchannel is properly changed, but flattening did not work at all
The funny thing about this is, that if I return the Unwrapper object and call the line


Unwrapper.flattenMap 45.0 #() 0.001 true 0 true true

OUTSIDE of the function it works perfectly.
I’m totally clueless why this happens …

4 Replies

– i think the flatten is different to each object.
– so the flatten command should after some objects.
– and after flatten, the flattenMap is different too .


function AO_UVWUnwrap _Object =
(
 Unwrapper = unwrap_uvw()
 Unwrapper.setApplyToWholeObject true
 addModifier _Object (Unwrapper)
 Unwrapper.setMapChannel 2
 --Unwrapper.flattenMap 45.0 #() 0.001 true 0 true true
)
theBox = box()
thesphere=sphere() 
-------------------------
AO_UVWUnwrap theBox
theBox.modifiers[1].flattenMap 45.0 #() 0.001 true 0 true true
--------------------------
AO_UVWUnwrap thesphere
theSphere.modifiers[1].flattenMap 45.0 #() 0.03 on 0 on on 

Second day, and you have already hit a strange behaviour of the modifier stack!

This is really a very special case – what happens is that the modifier is added to the modifier stack, but the stack has not been properly updated internally when you call the flattenMap() function.

What you have to do just before calling the flattenMap() is to force an update of the stack. There are multiple ways to do this, including

classof _Object –probably the fastest way, although it looks like a hack

max modify mode –relatively fast, but updating the UI can still be slower than classof()

max select none –relatively slow, as it has to change the selection and redraw viewports
select _Object


 
  function AO_UVWUnwrap _Object =
  (
  	Unwrapper = UVWunwrap()
  	Unwrapper.setApplyToWholeObject true
  	addModifier _Object (Unwrapper)
  	Unwrapper.setMapChannel 2
 	classof _Object --asks for the class on top of the stack, thus forces an internal update
  	Unwrapper.flattenMap 45.0 #() 0.001 true 0 true true
  )

Thanks a lot – that classof hack helped

hehe, exactly what I needed.

thanks to bobo and his experience!