emrahgunduz
always eats his vegetables
Blog RSS Feed
  • twitter
  • friendfeed
  • linkedin
  • facebook
  • vimeo
  • flickr
  • lastfm
Detach Using Material IDs

Detach Using Material IDs

This script detaches faces as new objects, using Material ID property of the faces. Most of the cases, matIDs are used to assign multiple materials on one object. Sometimes you might want to detach these as new objects.

Download Detach Using Material IDs Maxscript

It is possible to detach every matID as object, or simply a range, or just one with Min ID and Max ID ranges. If you keep the default settings, every matID becomes a new poly object. The remainder will be a faceless poly, script deletes this poly if this is the case. Naming will be done by adding the ID number at the end of the original name of the selected object (originalname_ID_#). Wirecolor will also be randomly changed. The pivots of the detached objects will be the same as the original object.

Before using the script please keep these in mind :

  • Script only works with polys. If you have a mesh or patch, you’ll need to convert it to poly mesh, or add an “edit poly” modifier on the stack.
  • Do not detach instanced objects, as this will cause deletion of the faces on the instances.
  • For objects with high poly count, it may take some time to process all the faces. I tried the script with a million poly object, it took 30 seconds or something close to detach every matID available. It might be better to detach some of the matID’s by hand, and then using the script.
  • Why is it slow with high poly objects ? There is no method in 3dsmax for detecting the matID count directly. Script goes through every face and count unique matID channels. Then detaches these if desired.

  • Drag and drop for starting the script
  • Detach MatID screen appears
  • Pick the object you want to explode
  • Select your range and click the button
  • Your object is detached (script will not move the new objects)

This post's short url is: http://emrg.me/5i

Maxscript to Macroscript

If you do not like running maxscript files from the maxscript utility everytime, or by drag dropping the same script over and over again, there is a better way. Macroscript. Converting a maxscript file to macroscript is simple, and after the convertion, the script can be accesed from lots of places: from a toolbar icon, quad menus, shortcuts, etc… What you have to do is writing this at the top of the script:

macroScript myScriptName category: "mycategory" tooltip: "What you want to name" ( "Your working code goes here..." )

You can expand what macroscript defines. Like, a button text, icons. Just check the maxscript reference from the Help menu of 3dsmax. Let’s assume that you have a script named “Planter” which will go to the category of “MyScripts”. This is the way to code :

macroScript myPlanter category:"My Scripts" tooltip:"Planter" buttontext:"Random Scale" ( "Your Planter Code" )

After writing the code, save and evaluate the script (from the maxscript editor File -> Evaluate, or, shortcut CTRL+E) or save the script and drag drop to 3dsmax. The script will be installed to 3dsmax automatically. If you ever change the code, just re-evaluate/reinstall it. Max will update the script. You can also add more scripts into just one file as macroscripts.

If you want to add some icons, you can create 8 bit bitmap files with a mask file. Maxscript reference has a really good entry on what to do and how to accomplish creating icons.

This post's short url is: http://emrg.me/5l

Auto Mirror Selected Using a Specific/Picked Object

Auto Mirror Selected Using a Specific/Picked Object

One of the missing parts of 3ds max is, you can’t find any APIs related to most of the functions. Mirroring is one of them. It has no functions that you can use from maxscript. Just “max mirror” which actually opens the mirror dialog toolbox.

Yet, there is another way for controlling max: dialog monitoring. If you are so tired of selecting objects that needs to be mirrored to a specific object, and selecting or picking that object, plus changing the axis to “use transform center”, this is the script for you.

Download Auto Mirror Script

macroScript AUTO_MIRROR category:"emrahgunduz.com" tooltip:"Auto mirror using MIRROROBJ" buttontext:"Auto Mirror" (   fn XMirror =   (     local Xhwnd=dialogMonitorOps.getWindowHandle()     local Xstring=UIAccessor.GetWindowText Xhwnd     --//--     if Xhwnd != undefined then       (       if Xstring != undefined and (findString Xstring "Mirror") != undefined then         (         UIAccessor.PressButtonByName Xhwnd "X"         UIAccessor.PressButtonByName Xhwnd "Instance"         UIAccessor.PressDefaultButton()         )       )     true   )   undo on (     MirrorOBJ = $MIRROROBJ     SelectedOBJ = $     toolMode.coordsys MirrorOBJ     toolMode.transformCenter()     dialogMonitorOps.registerNotification XMirror id:#findmirror     dialogMonitorOps.enabled=true     --//--     max mirror     --//--     dialogMonitorOps.unregisterNotification id:#findmirror     dialogMonitorOps.enabled=false     toolMode.coordsys #view     toolMode.selectionCenter()   ) )
This script assumes that you’ve an object named MIRROROBJ in the scene, which will be used as the base. The axis of this object will be our transform center. So keep in mind that and before using this script, add your mirror object and move it to anywhere you like.

Here are a few screenshots of how this script works:

  • Drag drop script to 3dsmax
  • Configure your user panel and add script to a quad menu
  • Rename your object as MIRROROBJ
  • Use quad menu option for mirroring
  • Mirroring accomplished
  • You can use any object, any angle, any location for mirroring

This post's short url is: http://emrg.me/4g

3dsmax : Name An Object From Material Name

This question came a few days ago via a comment. Is it possible to name an object by simply checking the material, and assign that name to the object? Answer is yes, and here is a script that will accomplish this easy task.

A selected object’s material name can be accessed with :
$.material.name

Assigning a name to an object goes like this :
$.name = “MyNewName”

And for a unique name you can use this one :
$.name = uniqueName “MyNewName”

If you’ve got more than one object selected, you can do something like this :

sel = selection as array count = 1 undo on   (     if sel.count > 0 then     (       while count <= sel.count do       (         select sel[count]         count += 1         $.name = uniqueName ($.material.name as String)       )     ) )
This will get the material name, and assign it to the object. Plus, it adds an auto incremented number at the end of each name. You can simply delete “uniqueName”, if you do not want this number. Objects can have same names, 3dsmax will not mind.

There is no error caching in this script. If you select an object that is not a member of the mesh class (like lights, cameras, helpers, etc), you might encounter errors.

This post's short url is: http://emrg.me/52

Calendar

May 2012
M T W T F S S
« Feb    
 123456
78910111213
14151617181920
21222324252627
28293031  
Web Analytics
Author: Emrah Gunduz