Monday, February 16, 2009

Create you own Rename Tools with MAXScript

Are you tired of renaming object in your scene? Based on Maxscript reference > How To ... Quickly Rename Selected Objects, I've created here a little tutorial that help novice user to create a personalized rename tool.


The Interface
  1. First of everything we will create an interface for our rename tool using Menu > MAXScript > Visual MAXScript Editor.
  2. Complete the interface as shown below, remember each elements in the interface must have unique name so that we can assigned each of them with their own controller/action and prevent them from conflicting each others.
  3. When you're done, save it as Interface.vms as a backup, in case we need to edit the interface we still have the option.
  4. Afterwards, save as QuickRename.ms (don't forget the extension is now .ms)
Note:
  • We will be using on entered event on the editBox (i.e. pressing Enter will excute the rename). Since clicking mouse button outside the editBox will triggered the on entered event, so to prevent the rename to be excuted twice, we will first set this button as enabled:false.
  • editBox default to leave blank. If you want to have a preset message, simply key in something for yourself.
  • Height of editBox must be lower than 18pixel to enable on entered event. So here we give it a height of 16px.


The Maxscript
  1. Go to Menu > MAXScript > Maxscript Editor and open your saved QuickRename.ms. You will see the same maxscript as below. We will be adding our own maxscript to complete this tool.
  2. Let's complete the script as below:
rollout quickRename "Quick Rename" width:250 height:120
(
editText txt_name "" pos:[24,56] width:200 height:16
button btn_rename "RENAME!" pos:[48,80] width:75 height:25 enabled:false
button btn_cancel "CANCEL" pos:[136,80] width:75 height:25
button btn_head "Head" pos:[8,16] width:75 height:25
button btn_body "Body" pos:[88,16] width:75 height:25
button btn_leg "Leg" pos:[168,16] width:75 height:25


-- DEFINE 'RENAME' FUNCTION
---------------------------------------------------
fn renameIt objName = ( -- function "rename"
global objName
for i in selection do i.name = uniquename objName
)-- end


-- ACTION
---------------------------------------------------
on btn_head pressed do renameIt "Head_"
on btn_body pressed do renameIt "Body_"
on btn_leg pressed do renameIt "Leg_"
on txt_name entered txt do (renameIt (txt + "_"; btn_rename.enabled=true)
on btn_cancel pressed do destroyDialog quickRename

)

createDialog quickRename
setFocus quickRename.txt_name


Explanation
fn renameIt objName = ( -- function "rename"
for i in selection do i.name = uniquename objName
)-- end

  • define a function renameIt() with variable objName
  • for...i enable rename to be excuted onto every selected objects. uniquename is used to assigned unique suffix on every object e.g. Head_01, Head_02, etc.

on btn_head pressed do renameIt "Head_"
Excute renameIt() and assigned string "Head_" into objName variable when btn_head is pressed.

on txt_name entered txt do (renameIt (txt + "_"; btn_rename.enabled=true)
Press "Enter" upon completion of name in txt_name will excute renameIt(). In the mean time also activate btn_rename

on btn_cancel pressed do destroyDialog quickRename
When btn_cancel is pressed, close the rename tool.

createDialog quickRename
Create a floating dialog to hold our rename tool, to be same name as "rollout".

setFocus quickRename.txt_name
Focus on the editBox(txt_name) when the dialog being created and opened.



Macroscript

In this section we will convert our script into macroscript, which will be loaded into Customize User Interface (CUI) , so that we can put it onto Toolbar or assigned Shortcut Key.
macroScript QuickRename category:"Tutorial" tooltip:"Quick Rename" Icon:#("AtmosApp",1)
(
-- "rollout" is to be put in here
)

  • QuickRename = name of macroscript
  • category = which category our tool is belong to under CUI
  • tooltip = name that appear when mouse over, also the name in CUI
  • Icon = see section below.


Creating Icon

We can make our own icon as well by adding the tag below onto the same line as our macroscript():

Icon:#("AtmosApp",1)
  • AtmosApp = icon file name (.bmp as standard), file to be placed in"3dsmax root\ui\Icons"
  • In this tutorial, we used "ui\Icons\AtmosApp*.bmp" as sample.
  • For more information, please read the maxscript reference.


Run Script...
  1. We're almost done here, now go to "MAXScript > Run Script..." and run your QuickRename.ms. Afterward, go to "Customize User Interface > Toolbar > Category > Tutorial" and you will spot our lovely tool。
  2. Drag it onto your toolbar (if you don't have one, it's time for you do make your own one) and Voila! You can also assigned a shortcut key to it if you love to do so.
Note:
When you run the script, it will automatically create a ".mcr" into your 3dsmax "usermacro" folder, which located at "DRIVE:\Documents and Settings\Username\Local Settings\Application Data\Autodesk\3dsmax\2009 - 32bit\enu\UI\usermacros".

That mean if you do not like to run it as maxscript, you can actually save the script as .mcr, and put it under the mentioned folder, then restart your 3dsmax.


Conclusion
Technique apply here could be further more developed into assigning renderer preset, controlling material so on and so forth. So I hope you enjoy this tutorial. Feel free to let me know what you think about this tutorial, and thing that I can improve here.

Lastly, here is my version, Cheer~

3 comments:

Jackie said...

hi tecsun, thank you for your sharing,is this script support 64bits version?

Tecsun Yeep said...

yes, it works under 32/64bits.

D Entertainment said...

đồng tâm
game mu
cho thuê nhà trọ
cho thuê phòng trọ
nhac san cuc manh
số điện thoại tư vấn pháp luật miễn phí
văn phòng luật
tổng đài tư vấn pháp luật
thành lập công ty trọn gói
http://we-cooking.com/
chém gió
trung tâm tiếng anhma thú, giá trị không phải dùng kim tiền là có thể so sánh được.

Bởi vì cái chết của tuyết long báo, trên đường quay trở về, tâm tình Diệp Âm Trúc có chút trầm uất, cho đến khi trở lại băng cốc vẫn chưa khôi phục được.

Tô Lạp chờ bên trong băng cốc đã sớm vô cùng sốt ruột, băng sâm nguy hiểm như thế, Diệp Âm Trúc bọn họ đi đã lâu mà không trở về, Tô Lạp đã không thể giữ được bình tĩnh rồi. Mắt thấy Diệp Âm Trúc dưới tác dụng ma pháp của vợ chồng u minh tuyết phách từ trên trời hạ xuống, Tô Lạp vội vàng tiến lên đón tiếp, sau khi phát hiện Diệp Âm Trúc hoàn hảo không tổn hao gì, trên mặt mới lộ ra vẻ tươi cười. Nhưng vẻ tươi cười trên mặt Tô Lạp rất nhanh đã tiêu thất, bởi vì Hải Dương cũng đã lên đón, ánh mắt ôn nhu của nàng đang ân cần nhìn Diệp Âm Trúc.

-Âm Trúc, ngươi làm sao vậy?

Hải Dương hỏi, Diệp Âm Trúc đối với tâm tình của mình cũng không giỏi che dấu, nàng tự nhiên nhìn ra được hắn đang thương cảm.

Miễn cưỡng cười, Diệp Âm Trúc nói:
-Không có việc gì. vừa rồi chúng ta gặp một ít ma thú