Notifications
Clear all

[Closed] Problem using FlattenMap within a Loop

I am currently stuck with a problem using the flattenMap function within a loop. If I evaluate the code for a single object it works perfectly fine. However, as soon as the selection contains more than one object, it still performs the flattenMap operation for only one object within the selection.

for o in selection do
  (
  addModifier o (unwrap_uvw())
  o.modifiers[#unwrap_uvw].setMapChannel 2
  o.modifiers[#unwrap_uvw].flattenMap 0.0 #() 0.001 true 0 true true
  )

I don’t know what I am doing wrong here?!

4 Replies

I think it’s best to store the selection with getCurrentSelection() or “selection as array” rather than iterate through the dynamic variable “selection”


local objs = getCurrentSelection()
for o in objs do (
  addModifier o (unwrap_uvw())
  o.modifiers[#unwrap_uvw].setMapChannel 2
  o.modifiers[#unwrap_uvw].flattenMap 0.0 #() 0.001 true 0 true true
)

I have made the changes but it still doesn’t work. It loops through all objects, adds the unwrap modifier and selects the right channel. But the flatten mapping does not happen…

Hi,

It seems that the object you wish to add the unwrap_uvw modifier has to be selected in order for the flatten function to work correctly.
Try this:


(
max modify mode
local sel = getCurrentSelection()
for o in sel do
  (
  select o 
  addModifier o (unwrap_uvw())
  o.modifiers[#unwrap_uvw].setMapChannel 2
  o.modifiers[#unwrap_uvw].flattenMap 0.0 #() 0.001 true 0 true true
  )
)

hOpe this helps,
o

Thx for the response. Well I have tried your code with a couple of teapots and it still doesn’t do the flattening.

Edit: I found an older post where the same problem appeared when the operation is called from a function. -> http://forums.cgsociety.org/showthread.php?t=318851


 sel = getCurrentSelection()
 
 for _Object in sel do
 (
 	  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
 )

If I dont store the unwrap modifier in a variable and then add it to the object it doesnt work for me. Anayways working now.