ScriptSpot

Forum topic · General Scripting

How can you apply the mod individually?

By othoap · 2011-09-16

Description

You can select multiple objects and apply a material to them. How ever apply a UVWmap modifier to the same selected objects the mod is applied to the group as a whole not independently.

This applies a cylindrical UVWmap to one object.

macros.run "Modifiers" "UVWmap"
$.modifiers[#UVW_Mapping].maptype = 1

How could you apply the mod to a select group individually?

Comments (12)

tassel · 2011-09-19

try this one instead (Anubis has probably a much better solution) ;o)
This keeps other modifiers in the stack and remove uvw map only.


-- Delete UVW Map Modifier in selection
	on btn_DeleteUVWMod pressed do
		(		
			for i in selection do
			(
			modPanel.setCurrentObject $.modifiers[#UVW_Map] 
			deleteModifier i i.uvw_Map
			)
			
		
		) -- End On

Doh

othoap · 2011-09-21

Good point. I didn't try it with other mods in the stack. How ever Now it adds two maps and will not delete ether.

about deleteModifier()

Anubis · 2011-09-20

Yes, Tassel is right about deleting. Delete by index is not safe. Well, somehow ".uvw_Map" return error here, but ".UVW_Mapping" works fine --

for i in selection do (deleteModifier i i.UVW_Mapping)

Update

othoap · 2011-09-19

Thanks to Tassel and Anubis for there update's

I rolled in "check for modifier compatibility" from Anubis. I also added a delete button.



--Destroy the dialog if it is already open 
try(destroyDialog roll_umm)catch()
 
-- UI STUFF
rollout roll_umm "UVW Multi Mapper"
(
group "UVW Map Type:"
	(
	radiobuttons rad_buttons "Map:" labels:#("Plane",  "Cylindrical",  "Cylindrical Cap", "Spherical", "Shrink Wrap", "Box", "Face", "xyz to UVW") default:0 columns:1
	)
	button btn_Add "Add" pos:[4,170] height:22 width:50 tooltip:"Add UVW map Modifier to selected objects" align:#center
	button btn_Delete "Delete" pos:[57,170]  height:22 width:50 tooltip:"Add UVW map Modifier to selected objects" align:#center
-- END UI STUFF
 
-- Radiobutton labels. Add UVW MapType
on rad_buttons changed state do (
	case state of
		(
		1: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:0)))
		2: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:1)))
		3: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:1 cap:on)))
		4: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:2)))
		5: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:3)))
		6: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:4)))
		7: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:5)))
		8: (for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:6)))
		)
) -- End On
 
-- Add UVW Map Modifier to selection
on btn_Add pressed do
	(
		for obj in selection do addModifier obj (uvwMap maptype:4)
	) -- End On
		
-- Delete UVW Map Modifier to selection
on btn_Delete pressed do
	(
	deleteModifier $ 1
	) -- End On
)
-- Create Dialog Stuff
createDialog roll_umm 110 200 pos:[1300,200] 

tassel · 2011-09-19

Thank you for the info Anubis :)

RE: small question

Anubis · 2011-09-19

I see you done what you need, but as you ask about shapes - yes, they're separate category (not belong to Geometry).

Ah, and one more advise :)
GeometryClass is too large category that include standard and extended primitives, polys, meshes, compound and dynamics objects, targetObject, particles, patches, nurbs, bones, biped, CATs, conteiners, body, mr_Proxy, some DWG helpers ... etc.

In other words, more safety expression would be if you check for modifier compatibility, i.e. is concrete modifier applicable to selected object, something like:

for obj in selection where (validModifier obj uvwMap) do (addModifier obj (uvwMap maptype:4))

Cheers!

tassel · 2011-09-18

A small question since this thread is about UV's:)

I tried to add a UVW map modifier to an spline object with this code (Dosn't work):


for obj in selection where superClassOf obj == geometryClass do (addModifier obj (uvwMap maptype:4))

But this works:


for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:4))

Any idee why? I thought splines/Shapes belonged to geometryClass ?

I ended up with modifying othoap's script to this:


--Destroy the dialog if it is already open 
try(destroyDialog roll_umm)catch()

-- UI STUFF
rollout roll_umm "UVW Multi Mapper"
(
		group "UVW Map Type:"
		(
			radiobuttons rad_buttons "Map:" labels:#("Plane",  "Cylindrical",  "Cylindrical Cap", "Spherical", "Shrink Wrap", "Box", "Face", "xyz to UVW") default:0 columns:1
		)
		button btn_AddUVWModifier "Add UVW Map Modifier" height:22 width:130 tooltip:"Add UVW map Modifier to selected objects" align:#center
-- END UI STUFF

-- Radiobutton labels. Add UVW MapType
		on rad_buttons changed state do (
			case state of
			(
				1: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:0)))
				2: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:1)))
				3: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:1 cap:on)))
				4: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:2)))
				5: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:3)))
				6: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:4)))
				7: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:5)))
				8: (for obj in selection where superClassOf obj == geometryClass or isKindOf obj Shape do (addModifier obj (uvwMap maptype:6)))
			)
		) -- End On
		
-- Add UVW Map Modifier to selection
		on btn_AddUVWModifier pressed do
		(
			for obj in selection do addModifier obj (uvwMap maptype:4)
		) -- End On
)
-- Create Dialog Stuff
createDialog roll_umm 140 200 pos:[1300,200] 

uvwMap maptype:1 cap:on

Anubis · 2011-09-17

You has made syntax mistake for .cap property.

(uvwMap maptype:1 .cap = on) -- wrong
(uvwMap maptype:1 cap:on) -- correct

When you create new node, modifier, material... you call their Constructor and all properties are optional and passed with "propName:Value" syntax. Once remember this, you'll have zero problems in the future ;)

Meanwhile, I post a script to Fit the UVWmap gizmo on existing modifiers:
http://www.scriptspot.com/3ds-max/scripts/fit-the-uvw-mapping-gizmo

Regards,
Anubis

thanks you-all's

othoap · 2011-09-17

I got this to work with you-all's help - thanks Anubis

How ever # 3 cylinder capping dose not work.



rollout umm "uvMultiMapper"
(
	radiobuttons rad_buttons "Map:" pos:[0,0] labels:#("Pln",  "Cyl", "Cap", "Sph", "Shr", "Box", "Fac", "xyz") columns:1 
    on rad_buttons changed state do (
        case state of
        (
            1: (for obj in selection do addModifier obj (uvwMap maptype:0))
            2: (for obj in selection do addModifier obj (uvwMap maptype:1))
            3: (for obj in selection do addModifier obj (uvwMap maptype:1 .cap = on))
			4: (for obj in selection do addModifier obj (uvwMap maptype:2))
			5: (for obj in selection do addModifier obj (uvwMap maptype:3))
			6: (for obj in selection do addModifier obj (uvwMap maptype:4))
			7: (for obj in selection do addModifier obj (uvwMap maptype:5))
			8: (for obj in selection do addModifier obj (uvwMap maptype:6))
			9: (for obj in selection do addModifier obj (uvwMap maptype:7))	
        )
        --rad_buttons.enabled = true
    )
)
createDialog umm 40 140 pos:[1300,200] 
cui.RegisterDialogBar umm minSize:[40,140] maxSize:[40,140] style:#(#cui_floatable,#cui_dock_left,#cui_dock_right,#cui_handles)

Hi Othoap,

Anubis · 2011-09-17

This works fine here (Max2009):

for obj in selection do addModifier obj (uvwMap maptype:4)

(all gizmos Fit their owner objs just fine)

Yes But

othoap · 2011-09-17

Tassel - thanks. BTW I loved "Back to the start" Every one go check out tassels website and the short "Back to the start"

Running your script puts uvwmaps on all the selected objects but dose not "Fit" them to the object. I removed the maptype l,h,w but it then put a uvwmap on all selected objects at the size of the whole group.

I looked in maxscript docs for a "Fit" function with no luck.

Wouldn't the dimensions of each selected node need to be found then applied to each of there l,w,h.
$Box01.modifiers[#UVW_Mapping].length = 39.0483
$Box01.modifiers[#UVW_Mapping].width = 83.6749
$Box01.modifiers[#UVW_Mapping].height = 94.8316

I think this is part of the puzzle http://www.scriptspot.com/bobo/mxs9/uvwgizmofit/index.html

tassel · 2011-09-16

Are you out afther something like this?


try (destroyDialog roUVW) catch()

-------------------------------------------------------------------------------------------------------------------------------
-- Selects Objects With Missing UV's.
-------------------------------------------------------------------------------------------------------------------------------
rollout roUVW  "LazyUV's" 
(	
	group "Lazy UV's"
	(
		button btn_objuv "Select Object with Missing UV's" height:22 align:#center
	
		checkbox cbAsInstance "Make Instance" checked:true height:22 align:#left across:2
		button btnUVW "Add UVW"  height:22 align:#right 
	)
		
	on btn_objuv pressed do
	(
		clearSelection()
		for a in geometry do
		(
			TotalUVNumVerts = 0
			for b in 1 to (meshop.getNumMaps a.mesh) do
			(
				UVFound  = try(meshop.getNumMapVerts a.mesh b)
				catch(results = 0)
				TotalUVNumVerts += UVFound
			)
			if (TotalUVNumVerts == 0) then selectmore a
		)
	)--end on

-------------------------------------------------------------------------------------------------------------------------------
-- add uvw's to selectet objects
-------------------------------------------------------------------------------------------------------------------------------

on btnUVW pressed do
	(
		if cbAsInstance.checked then
		(
			local uvwMapModifier = uvwMap maptype:4 length:4000 width:4000 height:4000 
			select (for obj in selection where superClassOf obj == geometryClass collect obj) 
			modPanel.addModToSelection uvwMapModifier ui:on
		)
		else
			for obj in selection where superClassOf obj == geometryClass do
				addModifier obj (uvwMap maptype:4 length:4000 width:4000 height:4000)
	)--end on
)--end of rollout

createDialog roUVW  200 85