Material Randomizer Script Download

Written March 12th, 2011
Categories: Downloads, Scripts
8 comments

This script will allow you to assign material IDs randomly to a selection of editable_poly objects in 3dsMax.  They must be editable_poly objects and it will replace the material of the objects.  Don’t worry- you can hit “undo” and it’ll reverse the assignment if you don’t like the outcome.  It’s a fast and easy way to assign random colors to your selection

  • By Object
  • By Sub-Object (element)
  • By Smoothing Group
  • By Polygon

To use the tool, just run the script from any location and it’ll pop up with the dialog window with your options.  Make sure you’ve selected the objects you want to assign random materials to!

Enjoy!

Click this link to download the Material-Randomizer-v0.84. To install, just download the zip file and decompress it into your plugins/std folder. You can also run it directly by running it from the Maxscript menu.

Assign Random Material ID to Selection

Written March 12th, 2011
Categories: Articles, Scripting / Programming, Textures / Materials
5 comments

Hey all,

I’ve put together the following short MaxScript to allow you to assign a random material ID to a selection in 3dsMax.  I’ll update it into a full tool if I get enough comments asking for it.

Here’s how you use it

  1. Select an edit_poly object,
  2. Select the polygons you’d like to assign random IDs to,
  3. Copy this script into a maxscript file (MaxScript > New Script…),
  4. Hit Ctrl + E to run the script.
numberOfSubMaterials = 3  -- Set the number of sub-materials here!!
originalSelection = polyop.getFaceSelection $
countOriginalSelection = originalSelection.count

for i=1 to numberOfSubMaterials do
(
	antiArray = #{1..countOriginalSelection}
	for i=1 to antiArray.count do antiArray[i] = (random 0 1) >= 1
	mergedArray = originalSelection * antiArray
	polyop.setFaceMatID $ mergedArray (random 1 numberOfSubMaterials)
)

Also, here’s another that assigns a random material/materialID to a collection of objects.

undo on
(
	newMaterial = multiMaterial numsubs:32
	for i = 1 to 32 do
		newMaterial[i].diffuse = random (color 0 0 0) (color 255 255 255)
	$.material = newMaterial

	for obj in $ do obj.material = newMaterial[random 1 32]
)

How to Deploy MaxScript Scripts

Written December 1st, 2010
Categories: Articles, Scripting / Programming
1 Comment »

You’ve spent a lot of time putting together a useful MaxScript and you want the whole world to enjoy it!  Unfortunately, you’re not sure of the best way to get it into the hands of the people.  Luckily, MaxScript comes with three major techniques for deploying a script and we’re going to cover them today.  These three techniques are

  1. Executable script – run it when necessary
  2. Macroscript (optional auto-deploy) – bind it to a hotkey or menu item
  3. Scripted plug-ins – connect to the 3ds Max interface directly

We’ll be going through these examples with a simple “Select Non-Quad Polygons” script from the MaxScript documentation.

Method 1- Executable Script

The first way is best for beginners and involves coding up a script that executes in a single go.  The script below operates in that way.  It iterates across all faces in the object to select non-quadrilateral faces.  Note that this script only works for editable poly objects and will throw an error for anything else!

local face_selection = #{}
local base_obj = $.baseobject
local num_faces = polyop.getNumFaces base_obj
for f = 1 to num_faces do
(
	local num_face_verts = polyop.getFaceDeg base_obj f
	if num_face_verts != 4 do face_selection[f] = true
)--end f loop
polyop.setFaceSelection base_obj face_selection
max modify mode
modPanel.setCurrentObject base_obj
subobjectlevel = 4

In this case, when the script is run, the faces are selected and the user is unceremoniously dropped off at the object’s “Polygon Select” level.  For a script with this level of involvement, this is an appropriate deployment mechanism.  The user just runs the script whenever they need it.  The script usually sits in a folder somewhere waiting for the user to invoke it.

Method 2- Macroscript (With optional auto-deploy)

A Macroscript is a wrapper that goes around your entire script and allows it to be bound to a hotkey or made a UI item.  This deployment method is good for intermediate users and for larger scripts that are a little more involved.  Let’s try wrapping the script above into a Macroscript and see it in the 3ds Max user interface.

macroscript SelectNonQuadPolys category:"Bluesummers" \
tooltip:"Select Non-Quads"
(
	on isEnabled return
	(
		selection.count == 1 and classOf selection[1].baseobject == Editable_Poly
	)
	on execute do
	(
		local face_selection = #{}
		local base_obj = $.baseobject
		local num_faces = polyop.getNumFaces base_obj
		for f = 1 to num_faces do
		(
			local num_face_verts = polyop.getFaceDeg base_obj f
			if num_face_verts != 4 do face_selection[f] = true
		)--end f loop
		polyop.setFaceSelection base_obj face_selection
		max modify mode
		modPanel.setCurrentObject base_obj
		subobjectlevel = 4
	)--end on execute
)--end script

Notice that in this case we’ve added two important elements. The first is a check to make sure we have an editable_poly object selected.  The second is the Macroscript wrapper that allows this tool to become part of the user interface. It has a name, a tooltip, a category, and can even take on a standard or custom icon (see MaxScript documentation). If you execute the script above and then go to “Customize > Customize User Interface” and select the “Bluesummers” Category, you’ll see the script appear.  You can bind it to a hotkey or add it to a Quad Menu or rollout floater.

In order to deploy this kind of script, you’ll need to have the user drop it into their “StdScripts” folder of their 3d Studio Max installation.  This is no fun since it adds some complexity.  For most 3dsMax installations, that folder is

C:\Program Files\Autodesk\3ds Max 2009\stdplugs\stdscripts

Any scripts in this folder will be run during 3dsMax’s startup process, and when you have the Macroscript wrapper around your script then you’re effectively “registering” a new tool during startup.

You can get pretty creative during this process. For example, during startup you can register the Macroscript into the user’s interface which basically “installs” it into 3d Studio Max. Consider the following snippet from my WedTexVerts script that installs it into the 3d Studio Max UnwrapUVWs modifier UI automatically.

Macroscript <...>
(
	<...shortened...>
)
-- If the registration fails, that means it's already there.
if menuMan.registerMenuContext 0x1c413679 do
(
	local ToolsMenuIndex, ToolsMenuItem
	local ToolsMenu, WeldVertTool, UVW_MenuBar

	-- Get the main UVW menu bar
	UVW_MenuBar = MenuMan.getMenu 128 

	-- The above is not always true.  Let's check to make
	-- sure so we don't totally wreck the UI
	if UVW_MenuBar.getTitle() != "UVW Unwrap - Menu Bar"
	do throw "Critical Error: Your UI Could not be modified \
				because you have made changes to your .mnu \
				file."

	-- Get the tools index.  Should be 4th from the left.
	-- Double check the title to make sure.
	for i = 1 to UVW_MenuBar.numItems() do
		if (UVW_MenuBar.getItem i).getTitle() == "Tools" do
			ToolsMenuIndex = i

	-- Get the menu item that holds the help menu
	ToolsMenuItem = UVW_MenuBar.getItem(ToolsMenuIndex)

	-- Get the menu from the item
	ToolsMenu = ToolsMenuItem.getSubMenu()

	-- Create a menu item that calls the WeldTexvert Tool.
	WeldVertTool = (menuMan.createActionItem "WeldSelectedFloater" "Bluesummers' Tools")

	-- Add the action item to the end of the help menu.
	ToolsMenu.addItem WeldVertTool 7

	-- redraw the menu bar with the new item
	MenuMan.updateMenuBar()
)

This is a pretty complicated process, so I’ll leave it to you to read more about the MaxScript MenuMan object. You should just be aware that your users may not always be smart enough to bind up your tools to a hotkey and you can take the liberty of putting your new functionality directly into their interface.  However, you should also be extremely careful as the smallest mistake could damage the user’s interface.

Method 3- Scripted Plug-Ins

Finally, it’s possible for us to deploy scripted plug-ins. These tend to be the largest scripts of all and are basically full extensions of 3dsMax functionality. You can create render filters, meshes, modifiers, and more. You’ll basically deploy your script similarly to a Macroscript- by having your user insert the script into their 3dsMax C:/…/stdscripts/ folder. However, instead of wrapping your functionality in a Macroscript, you’ll wrap it in a scripted plug-in context.

Take a look at the code below, where the script creates a new object type called a Cuboid.

plugin geometry Cuboid
name:"Cuboid"
classID:#(0x133077, 0x54375)
category:"Scripted Primitives"
extends:Box
(
	fn fmax val1 val2 = if val1 > val2 then val1 else val2
	tool create
	(
		on mousePoint click do
		case click of
		(
			1: nodeTM.translation = gridPoint
			2: #stop
		)

		on mouseMove click do
			if click == 2 then
				delegate.width = delegate.length = delegate.height = \
				2 * fmax (abs gridDist.x) (abs gridDist.y)
	)
)

Granted this procedure takes significantly more work than the other two options, it does integrate your tools more deeply into 3d Studio Max and can be quite useful for circumstances where you want to create a “normal” extension of the tools available.

And there you have it!  Those are three awesome ways to deploy your scripts to anyone who needs them.  Happy coding!

Wire Bundle Script

Written November 5th, 2010
Categories: Downloads, Scripts
18 comments

This is a simple script that you can use to create bundles of wires with ease in 3d Studio Max. Just drop the .MS file into your <3dsMax>/stdplugs/stdscripts folder. Then it’ll show up in your “Customize>Customize User Interface…” window, under the “Bluesummers” Category. Bind it up to a hotkey and you’re good to go!

Click this link to download the WireBundle_0.90.zip. To install, just download the zip file and decompress it into your <3dsMax>/stdplugs/stdscripts folder. You can also run it directly by running it from the Maxscript menu.

Creating Custom 3d Studio Max Rollouts

Written October 8th, 2010
Categories: Articles, Scripting / Programming
3 comments

In this quick tutorial, we’ll look at how you can create custom 3d Studio Max rollouts for your tools.  You can make custom floating or docked windows or toolbars that hold your tools and that make it easy to customize your workspace.  These tools are usually called “actions” and can be almost anything you imagine!  They can be

  • 3dsMax modifiers like bevel, extrude, etc,
  • actions like “Convert to Editable Poly…”, or
  • tools like align, hide, etc.

It can save you time and that’s part of what getting better at 3d is all about.

Step 1- Right click on an empty interface area

Right click on an empty interface area to get the interface customization menu.  Select “Customize…”  Otherwise, you can go to Customize > Customize User Interface… and select the “Toolbars” tab.

3dsmax-custom-rollouts-step-1

Step 1- Right click on an empty interface area, and select "Customize…"

Step 2- Create a new rollout

What you need to do is create a new rollout by clicking the “New…” button.

3dsmax-custom-rollouts-step-2

Step 2- Create a new rollout by clicking the "New…" button.

Go ahead and give your new rollout a name.  I’m calling mine “Common Tools”.

3dsmax-custom-rollouts-step-3

Assign your custom toolbar a name.

Step 3- Assign some actions to the new toolbar

Click and drag some actions into the new toolbar.  The vast majority of what you can do in 3d Studio Max can be assigned to buttons in toolbars.  Interestingly, all of these actions are also scriptable via MaxScript.

3dsmax-custom-rollouts-step-4

Select the actions that you want to appear in the new toolbar by click+dragging them over.

You now have a new custom toolbar.  You can access it using the right-click menu we used to start this process.  Right-click on an empty area of the UI and select your new “Custom Tools” toolbar.

3dsmax-custom-rollouts-step-6

You now have a custom toolbar!

BONUS: Assign custom actions to your toolbar using MaxScript

You can assign custom actions to your toolbar with the MaxScript Macro Recorder Window.  Press F11 or open the listener through MaxScript > MaxScript Listener…

3dsmax-custom-rollouts-step-7

Enable the MaxScript Macro Recorder from the Listener window.

Enable the MacroRecorder as shown.  This will record everything you do in 3d Studio Max in the pink window, and allow you to record a pre-defined set of actions.  This could be everything from making flower petals to building a skyscraper.

3dsmax-custom-rollouts-step-8

When you have your action recorded, drag the script to your toolbar.

When you have your action recorded, select all of the text in the pink window and drag it over to your toolbar.  If you have extra actions recorded, you may have to remove those.  Remember that everything you click or do is being recorded, so make sure you did what you want to record and nothing else.

You can right-click on the button that was created and select “Edit Button Appearance…” to change the image or text of your new button.

3dsmax-custom-rollouts-step-9

I gave mine a label and tool-tip so that I don't forget what it does.

MaxScript Rollouts

Written January 18th, 2010
Categories: Scripting / Programming, Videos
4 comments

Hey Everyone!

This week I’ve got a great episode that goes into how you can create floating dialog windows for your MaxScripts.  I’ll even go into how you can create a “Random Selection” utility in MaxScript.  Hope you enjoy it!

MaxScript Basics

Written January 12th, 2010
Categories: Scripting / Programming, Videos
3 comments

Guess who’s back from vacation?

Sorry for the delay on this video: I didn’t expect to be so demolished from 25 hours of flying yesterday.  Anyway, this week is slated with some great videos and great news!

I’ll be showing you how to do some basic automation in 3dsMax’s MaxScript scripting language.  It’s a lot easier than you think and can give you a real edge!  We’ll be looking at how you can manipulate some cubes using simple MaxScript operations, and I’ll show you how to use the Macro Recorder to automate almost any process in 3dsMax.  If you’re looking to get a little more practice with scripting, after the video you can follow my Scripted Clay Rendering tutorial.

I’m also going to get transcriptions for about 10 of my Monday Movies going back a few weeks, so keep an eye out for that.  Special thanks goes out to Devanie at VideoTranscriptions.net for doing a perfect job at…well…video transcriptions.

Select Face Smoothing Group Boundaries Script

Written April 16th, 2009
Categories: Downloads, Scripts
3 comments

This script will quickly select all of the edges in your 3d Studio Max model that boarder smoothing group changes.  For example, if you have a character who’s smoothing groups change between flesh and clothing, this helps you quickly see where those changes are, and refine your smoothing groups accordingly. You can also use it to create UWV clusters based on your smoothing groups. Finally, it allows you to select all of your smoothing group boarders, or the boarders of only a particular smoothing group.

Click this link to download the Face Smoothing Group Boundaries Script. Just unzip it to your desktop or somewhere on your hard drive and run it via the Maxscript command menu in 3dsMax.

WeldTexVert 3dsMax Script

Written March 16th, 2009
Categories: Downloads, Scripts
2 comments

For the war effort, I’ve gone through my old script library and picked out some of the choicest bits I wrote back when I was still trying to be a tools programmer.  WeldTexVert is a modal window that’s automatically added to your UnwrapUVW menu bar that lets you interactively weld texture vertices in the same way you would with editable polygons.

The good news is that you can bind it to a hotkey so you never have to worry about the original weld vertex tool ever again.  The bad news is, you need to select the UVW vertices you want to weld before opening the window.  Sorry about that!

Either way, I hope you enjoy the tool.

Click this link to download the Weld Vertex Tool Script. Just unzip it to your desktop or somewhere on your hard drive and run it via the Maxscript command menu in 3dsMax.

Pflow Trajectory displayed with splines

This tutorial deals with Particle Flow in 3D Studio MAX in conneciton with a little MAX Scripting to create a outstanding image.

Particle Planting

Plant 44000 stadium chairs with 4 different materials through particle flow and maxscript

Developing Scripted Utility

“Hello everyone, this tutorial will guide you to develop a scripted utility in 3DS MAX 9. This tutorial is for users with basic knowledge in max script or any other object oriented language. Here I explained everything step by step. Actually this coding is a part in my plug-in. Due to coding complexity, I cut shorted some and add only the few things. If time permits I will explain rest.”

Designed by Alejo "Mr. Bluesummers" Grigera"
©2012 MrBluesummers.com