Unable to Apply UVW Map on multiple Selection with simple MaxScript

Hi all,

I've recently created a maxscript to apply a 10x10x5m box UVW Map on objects.
I copied the code from the maxscript listener after applying it manually on an object. Edited some of the information to better organize it in my CUI. The code goes like this

macroScript UVW10x10x5m
category:"1Essential Scripts"
toolTip:"UVW10x10x5m"
Buttontext:"UVW10x10x5m"
 
(
	modPanel.addModToSelection (Uvwmap ()) ui:on
	$.modifiers[#UVW_Map].maptype = 4
	$.modifiers[#UVW_Map].length = 10000
	$.modifiers[#UVW_Map].width = 10000
	$.modifiers[#UVW_Map].height = 5000
)

After that, I set a shortcut key for it in my CUI for easier access while working.

It works perfectly when I use it on a single object. However, when using it on multiple object I get the below error

"-- Unknown property: "modifiers" in $selection"

pardon the noobish terms I used in my questions.

I tried to search for a similar script for reference, however the scripts I found looks very complicated. Is there a quickfix for this script or will the script need to be in a totally different "format"

Many thanks in advance!

Comments

Comment viewing options

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

Use this: With instances

Use this:

With instances modifier:

Uv= Uvwmap()
for i in selection do
(
addModifier i ( Uv)
i.modifiers[#UVW_Map].maptype = 4
i.modifiers[#UVW_Map].length = 10000
i.modifiers[#UVW_Map].width = 10000
i.modifiers[#UVW_Map].height = 5000
)

Without instances:

Uv= Uvwmap()
for i in selection do
(
addModifier i (copy Uv)
i.modifiers[#UVW_Map].maptype = 4
i.modifiers[#UVW_Map].length = 10000
i.modifiers[#UVW_Map].width = 10000
i.modifiers[#UVW_Map].height = 5000
)

Comment viewing options

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