Jump to content

3DS MAX Script Help


simonm
 Share

Recommended Posts

Hi guys

 

 

I am not a programmer nor am i anywhere near that level. However i have been playing around with the most basic functions of listener and the scripts and i want to be able to create simple scripts for my every day use.

 

 

For instance, i created the below script which placed a UVW map of 2000mm to the selected object. See below the basic script:

 

 

modPanel.addModToSelection (Uvwmap ()) ui:on

$.modifiers[#UVW_Map].maptype = 4

$.modifiers[#UVW_Map].length = 2000

$.modifiers[#UVW_Map].width = 2000

$.modifiers[#UVW_Map].height = 2000

 

 

However, when i try and run the script on a group, it doesnt work and it comes up with the error "unknown property:"modifiers" in $selection.

How can run this script on any thing that is selected, be that it is a group or not?

 

 

Thanks in advance guys

Link to comment
Share on other sites

I guess it really depends on what you are doing, as its not clear why its necessary to put a uvmap mod on a group, but id recommend you look into this script:

 

http://www.scriptspot.com/3ds-max/scripts/modifiers-clipboard

 

its very good at taking modifiers from objects, storing them, and copy/pasting them to whatever you would need. (objs or groups)

 

Cheers!

Link to comment
Share on other sites

 

modPanel.addModToSelection (Uvwmap ()) ui:on

$.modifiers[#UVW_Map].maptype = 4

$.modifiers[#UVW_Map].length = 2000

$.modifiers[#UVW_Map].width = 2000

$.modifiers[#UVW_Map].height = 2000

 

 

Short answer: A group is a special object, that is treated differently in the viewport than when accessing the scene in Maxscript.

 

 

 

Long Answer: Let me commend you for getting in and trying your hand at maxscript, it is one of my favorite things in Max, I think everyone should work through the tutorials and get a basic understanding of maxscript, it will make you interaction with 3dsmax much richer, can be a good place to start to other environments, and will allow you another way to approach problems, especially when having to do the same task over and over.

 

What you are doing in your script above is saying to maxscript:

 

modPanel.addModToSelection (Uvwmap ()) ui : on ----- same as adding a Uvwmap modifier to everything selected

$.modifiers[#UVW_Map].maptype = 4 ----- this is setting the map type on everything currently selected

$.modifiers[#UVW_Map].length = 2000 ----- sets the length

$.modifiers[#UVW_Map].width = 2000 ----- set the width.... you get the idea

$.modifiers[#UVW_Map].height = 2000

 

A couple of things to note, because this was recorded with the listener, it is just reflecting what happens in the UI and records it, and (under special circumstances) will work when played back via a script. There are a few conventions that make this possible, but also make the script brittle. The problem you ran into is an error, because you selected a group in the UI, what is actually happening when you do this is you select a hidden object (the group) which in turn selects all the members. The Group itself cannot receive the modifier, and the built-in variable "$" is not mapped properly to the objects, like it is when you select objects separately in the viewport. Using "$" in scripts is not a good idea, there are different ways to get at the current selection, but if 1 thing is selected, or many of different types (lights, helpers, geometry, cameras) they still are temporarily referenced by "$".

 

Another thing that is happening in the script you created, is that you first apply a default uvwmap modifier to each of the objects that are selected, and then you go through and change the values. The more common way to achieve the same result with more control, would be to make a uvwmap modifier with the values you want, then apply it to the objects you want. You can choose to apply the same one to all the objects, (making the modifier and instance) or a copy of the modifier on each object so that changing one wont change all the rest.

 

Here is a quick script that achieves the same result but in a more maxscripty way: (anything after -- is a comment)

 

for i in selection do -- loop to march through all objects currently selected
(
if superclassof(i) == GeometryClass do -- test to see if objects are geometry (there are other ways to do this)
	(
		newUV = Uvwmap() -- create a new UVWmap Modifier
		newUV.maptype = 4
		newUV.length = 2000
		newUV.height = 2000
		newUV.width = 2000

		addmodifier i newUV  -- apply the modifier to the object (here refrenced by "i")
	)
)

 

-Nils Norgren

Link to comment
Share on other sites

Thanks so much for your response - heaps of info there so ill need to read it 5 times to digest as this scripting/programming thing is totally new to me. I tried using that script you wrote and it works great, however it doesnt apply them as instances. It puts on individual UVW maps - how would i make them the same instance on each object?

 

Thanks again youve been great :)

 

Short answer: A group is a special object, that is treated differently in the viewport than when accessing the scene in Maxscript.

 

 

 

Long Answer: Let me commend you for getting in and trying your hand at maxscript, it is one of my favorite things in Max, I think everyone should work through the tutorials and get a basic understanding of maxscript, it will make you interaction with 3dsmax much richer, can be a good place to start to other environments, and will allow you another way to approach problems, especially when having to do the same task over and over.

 

What you are doing in your script above is saying to maxscript:

 

modPanel.addModToSelection (Uvwmap ()) ui : on ----- same as adding a Uvwmap modifier to everything selected

$.modifiers[#UVW_Map].maptype = 4 ----- this is setting the map type on everything currently selected

$.modifiers[#UVW_Map].length = 2000 ----- sets the length

$.modifiers[#UVW_Map].width = 2000 ----- set the width.... you get the idea

$.modifiers[#UVW_Map].height = 2000

 

A couple of things to note, because this was recorded with the listener, it is just reflecting what happens in the UI and records it, and (under special circumstances) will work when played back via a script. There are a few conventions that make this possible, but also make the script brittle. The problem you ran into is an error, because you selected a group in the UI, what is actually happening when you do this is you select a hidden object (the group) which in turn selects all the members. The Group itself cannot receive the modifier, and the built-in variable "$" is not mapped properly to the objects, like it is when you select objects separately in the viewport. Using "$" in scripts is not a good idea, there are different ways to get at the current selection, but if 1 thing is selected, or many of different types (lights, helpers, geometry, cameras) they still are temporarily referenced by "$".

 

Another thing that is happening in the script you created, is that you first apply a default uvwmap modifier to each of the objects that are selected, and then you go through and change the values. The more common way to achieve the same result with more control, would be to make a uvwmap modifier with the values you want, then apply it to the objects you want. You can choose to apply the same one to all the objects, (making the modifier and instance) or a copy of the modifier on each object so that changing one wont change all the rest.

 

Here is a quick script that achieves the same result but in a more maxscripty way: (anything after -- is a comment)

 

for i in selection do -- loop to march through all objects currently selected
(
if superclassof(i) == GeometryClass do -- test to see if objects are geometry (there are other ways to do this)
	(
		newUV = Uvwmap() -- create a new UVWmap Modifier
		newUV.maptype = 4
		newUV.length = 2000
		newUV.height = 2000
		newUV.width = 2000

		addmodifier i newUV  -- apply the modifier to the object (here refrenced by "i")
	)
)

 

-Nils Norgren

Link to comment
Share on other sites

The way that version of the script works it is making a new UVWmap modifier each time it finds an object in the scene(each loop), to make ONE UVWmap and apply it to multiple objects you move the UVWmap creation outside the loop, that way it only is created once and then it is applied to each of the objects as it loops over them.

 


newUV = Uvwmap() -- create a new UVWmap Modifier
newUV.maptype = 4 -- now outside the loop, there will be ONE UVWmap
newUV.length = 2000 -- applied to all the objects
newUV.height = 2000 -- otherwise this is the same as before
newUV.width = 2000 -- except now the modifier will be an instance

for i in selection do
(
if superclassof(i) == GeometryClass do
(
addmodifier i newUV
)
)
[/Code]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...