Pages

Thursday, March 5, 2009

Simple Utility

It's a easy job to make scripted utility in Max.

utility UName "UTitle" ()

But it's empty right now. Lets make some box with it. If we open MaxScript Listener (F11) end type box() and execute (hit Enter), Max will create a box in position [0,0,0] with size [25,25,25]. To have access to box properties we need a variable like this: b=box() . But if we put this simple line directly into our utility, will appear only error. This will work on exit:

utility makeBox "Make Box"
(
-- then close utility
on makeBox close do
(
b = box()
)
) -- ie need action to create a box

Lets make a button to create a box:


utility makeBox "Make Box"
(
local b
button myBtn "Create"
on myBtn pressed do
(
b = box width:20 length:20 height:20
)
)

This code make the same thing but now have button "Create" and some parameters assigned to the box, so this one more like an utility :) and may say you done your first scripted utility, and it makes somthing :)


There is one example. Some materials not support open faces and if you use plane primitive will run out strange render result. For that case you could cap the hole on the plane or make a box with zero height. And if you often use square plane, why need to set every time all three dimensions? Then lets speed up our work with one simple utility who will make flatten box for us by entering only one params:


utility FlatBox "FlatBox"
(
local b

group "Parameters"
(
spinner dim "Face Size" range:[10,10000,100] \
type:#integer fieldwidth:30 across:2 align:#left
button fbox "Create" align:#right
)

on fbox pressed do
(
b=box()
b.width = dim.value
b.length = b.width
b.height = 0
b.name = uniquename "FlatBox"
)

group "About"
(
label lab1 "FlatBox Creator"
label lab2 "Test version 0.1"
label lab3 "by 3DMyths(c)2009"
hyperLink website "(my web site)" \
address:"http://3dmyths.blogspot.com/" align:#center
)
)


Figure 1 show utility panel and result (Figure 2) in Modify panel.
You can download script here (570 bytes).

No comments:

Post a Comment

Thanks for your comment