Modifiers
You might ask yourself why bother when we can either press ‘x’ and search for the modifier or add them to our Modifier Sets:
The reason I choose to write my own is for 2 reasons, I can create a button for them using an icon and more importantly set up the default behavior for each modifier – chamfer settings, loft settings, etc.
Here is an example of my chamfer modifier:
-- Switch to modifiers tab
max modify mode
-- Modifier
theMod = Chamfer()
-- Modifier Settings
theMod.SmoothType = 1
theMod.miteringType = 0
theMod.amount = 0.25
theMod.useminangle = off
theMod.tension = 0.5
theMod.smoothtoadjacent = on
theMod.segments = 2
-- Instance modifier on sub-object level or muiltiple objects
if modPanel.validModifier theMod then modPanel.addModToSelection theMod
max modify mode
– The first line is important to switch to the modifier panel so it begins the modifier mode.
-- Modifier
and -- Modifier Settings
– This block is just assigning the settings to the modifier I want, all this you can get from the listener while applying your settings on a test object. It will give you feedback such as:
$.modifiers[#Chamfer].segments = 2
if modPanel.validModifier theMod
– is especially useful, first it checks if the object is valid so it doesn’t throw an error like trying to assign a Lathe to an Editable Polygon object.
then modPanel.addModToSelection theMod
– applies to any object such as a group of objects or anything selected that is valid.
Functions
So lets get into it. First we make our maxscript .ms and assign each modifier to a function:
-- Chamfer
function vellaModChamfer =
(
-- Switch to modifiers tab
max modify mode
-- Modifier
theMod = Chamfer()
-- Modifier Settings
theMod.SmoothType = 1
theMod.miteringType = 0
theMod.amount = 0.25
theMod.useminangle = off
theMod.tension = 0.5
theMod.smoothtoadjacent = on
theMod.segments = 2
-- Instance modifier on sub-object level or muiltiple objects
if modPanel.validModifier theMod then modPanel.addModToSelection theMod
)
-- Extrude
function vellaModExtrude =
(
-- Switch to modifiers tab
max modify mode
-- Modifier
theMod = Extrude()
-- Modifier Settings
theMod.amount = 10
theMod.mapcoords = on
-- Instance modifier on sub-object level or muiltiple objects
if modPanel.validModifier theMod then modPanel.addModToSelection theMod
)
Continue to add as many as you need with your custom settings. I have created 2 functions in this case to demonstrate how to display them as I have in the above screenshot.
Rollout
Now we make the rollout that you see on the right side next to my Create panel. So in your .ms file below your functions
create a rollout
.
-- Extrude
function vellaModExtrude =
(
-- your modifier code here (as above)
)
-- Rollout for Panel "Modifiers"
rollout vellaModifierRollout "Modifiers"
(
-- Label Seperator
label label_geo "Geometry"
button btn_mvc "Chamfer" iconName:"StateSets\DisplayAsBox" tooltip:"Chamfer"
on btn_mvc pressed do vellaModChamfer()
-- Label Seperator
label label_splines "Splines"
button btn_mvx "Extrude" iconName:"CivilView\Normal" tooltip:"Extrude"
on btn_mvx pressed do vellaModExtrude()
)
-- Create Rollout Floater
rf = newRolloutFloater "Vella" 120 800
addRollout vellaModifierRollout rf
-- Dock Rollout
CUI.REGISTERDIALOGBAR rf
CUI.DOCKDIALOGBAR rf #cui_dock_right
When you run the script in the editor (ctrl+E) you will get this new rollout:
Lets break down what’s happening in the rollout:
rollout vellaModifierRollout "Modifiers"
This simply creates the rollout, give it a name which can be anything to reference back to – I chose the variable
, and “vellaModifierRollout
” will be the category title.Modifiers
-- Label Seperator
label label_geo "Geometry"
I want to keep my Geometry and Spline modifiers separate, so we can do that with a label. I chose the variable label_geo
and the name "Geometry"
button btn_mvc "Chamfer" iconName:"StateSets\DisplayAsBox" tooltip:"Chamfer"
on btn_mvc pressed do vellaModChamfer()
button btn_mvc "Chamfer"
– Create a button, assign the variable btn_mvc
, give it a name "Chamfer"
.
iconName:"
“. You can find the icons that come with 3dsmax here, Add the “Path\IconName”. Thanks to MAYOI.ME for this tip.StateSets\DisplayAsBox
tooltip:
is what will show when you hover your mouse over the button.
on btn_mvc pressed do vellaModChamfer()
– This references our variable btn_mvc
and when the button is pressed, do our function vellaModChamfer()
Continue to do this for your other modifiers/functions.
Now lets register the rollout and put it somewhere:
-- Create Rollout Floater
rf = newRolloutFloater "Vella" 120 800
addRollout vellaModifierRollout rf
-- Dock Rollout
CUI.REGISTERDIALOGBAR rf
CUI.DOCKDIALOGBAR rf #cui_dock_right
rf = newRolloutFloater "Vella" 120 800
– Build the rollout floater, give it a name, add the width and height. In this case height doesn’t really matter since it will be docked.
addRollout vellaModifierRollout rf
– Add the rollout we made to the rollout floater variable.
CUI.REGISTERDIALOGBAR rf
– register the rollout as a dockable window.
CUI.DOCKDIALOGBAR rf #cui_dock_right
– dock it to the right.
Taking your scripts with you
Ok so you have your final script. For our demonstration our final script will look like this:
-- Chamfer
function vellaModChamfer =
(
-- Switch to modifiers tab
max modify mode
-- Modifier
theMod = Chamfer()
-- Modifier Settings
theMod.SmoothType = 1
theMod.miteringType = 0
theMod.amount = 0.25
theMod.useminangle = off
theMod.tension = 0.5
theMod.smoothtoadjacent = on
theMod.segments = 2
-- Instance modifier on sub-object level or muiltiple objects
if modPanel.validModifier theMod then modPanel.addModToSelection theMod
)
-- Extrude
function vellaModExtrude =
(
-- Switch to modifiers tab
max modify mode
-- Modifier
theMod = Extrude()
-- Modifier Settings
theMod.amount = 10
theMod.mapcoords = on
-- Instance modifier on sub-object level or muiltiple objects
if modPanel.validModifier theMod then modPanel.addModToSelection theMod
)
-- Rollout for Panel "Modifiers"
rollout vellaModifierRollout "Modifiers"
(
-- Label Seperator
label label_geo "Geometry"
button btn_mvc "Chamfer" iconName:"StateSets\DisplayAsBox" tooltip:"Chamfer"
on btn_mvc pressed do vellaModChamfer()
-- Label Seperator
label label_splines "Splines"
button btn_mvx "Extrude" iconName:"CivilView\Normal" tooltip:"Extrude"
on btn_mvx pressed do vellaModExtrude()
)
-- Create Rollout Floater
rf = newRolloutFloater "Vella" 120 800
addRollout vellaModifierRollout rf
-- Dock Rollout
CUI.REGISTERDIALOGBAR rf
CUI.DOCKDIALOGBAR rf #cui_dock_right
Save this .ms file into your scripts startup directory:
%localappdata%\Autodesk\3dsMax\yourmaxversion\ENU\scripts\startup
This will load the rollout when you start 3dsmax and dock it to the right. When you switch to another computer copy that .ms script and paste it into the scripts\startup folder and you will have your toolbar with you wherever you go. No need to install your scripts\modifiers one by one!
Macroscripts vs Startup Scripts
Before I wrote these in a Macroscript. However the down side is these don’t transfer from one version of 3dsmax to another quite easily unless you know how to build an mzp file or drag them into your viewport one at a time. We can also do that however I find this is faster since all I need is one .ms file and instantly get all my modifiers from one version to another or one computer to another. We can also do this with our other custom scripts but ill explain more in Part 2. How did you get more than two icons and multiple rollouts like in your first screenshot? Also more on that in Part 2.
Pros:
- Take your scripts everywhere with you with one .ms file
- Instantly load all your scripts/buttons/icons/tooltips etc on startup
- No need to add hundreds of .mcr files to your macroscripts directory
- Scripts are loaded on button press, 3dsmax starts faster
Cons:
- Cant drag new toolbar buttons to the rollout
- Each new script has to be added into the function and rollout sections
Happy scripting!
Pingback: Maxscript – Modifiers, Rollouts and taking your scripts with you (Part 2) | James Vella