How To ... Develop A Face Area XView Checker - Part 4

How To > Develop A Face Area xView Checker - Part 4

The following tutorial extends the scripted xView Check created in Part 1, Part 2, and Part 3 with a MacroScript that can be added to the Viewport Menus for easier access.

The xView Checker is available in 3ds Max 2010 and higher.

Related topics:

xViewChecker Access

Interface:xViewChecker

NATURAL LANGUAGE

Create a MacroScript to toggle the Face Area Checker on and off.

Create an 'on Checked do()' handler to show when the Checker is enabled.

Create an 'on Execute do()' handler to turn the Checker on and off depending on the current state of the system.

SCRIPT:

MacroScript xView_Face_Area_Checker
enabledIn:#("max")
buttonText:"Face Area"
category:"xView"
internalCategory:"xView"
tooltip:"Face Area Checker Display Mode"
(
on isChecked return
  xViewChecker.getCheckerName xViewChecker.activeIndex == "Face Area Checker" and xViewChecker.on == true
on execute do
  if (xViewChecker.getCheckerName xViewChecker.activeIndex == "Face Area Checker" and xViewChecker.on == true) then
    xViewChecker.on = false
  else
  ( 
    local theIndex = 0
    for i = 1 to xViewChecker.getNumCheckers() do
      if xViewChecker.getCheckerName i == "Face Area Checker" do theIndex = i
    if theIndex > 0 do  
    (
      xViewChecker.setActiveCheckerID(xViewChecker.getCheckerID theIndex)
      xViewChecker.on =true
    )
  )
)--end MacroScript
MacroScript xView_Face_Area_Checker
enabledIn:#("max")
buttonText:"Face Area"
category:"xView"
internalCategory:"xView"
tooltip:"Face Area Checker Display Mode"
(

Based on the existing xView MacroScripts already shipping with 3ds Max 2010 and higher, we can create a new MacroScript header for our Face Area Checker.

on isChecked return
xViewChecker.getCheckerName xViewChecker.activeIndex == "Face Area Checker" and xViewChecker.on

When 3ds Max wants to see whether an ActionItem in the UI has to be checked (when displayed as a button, a menu item, or a Quad menu item), it calls the isChecked handler. Here, we return true if the name of the currently active checker matches our checker's name and checking is generally enabled.

on execute do
(

When the MacroScript is actually invoked, the execute handler will be called.

if (xViewChecker.getCheckerName xViewChecker.activeIndex == "Face Area Checker" and xViewChecker.on) then

We perform the same check as in the isChecked handler.

xViewChecker.on = false

If our checker is the active one and checking is enabled, we simply disable the xView checking.

else
( 

Otherwise, we will have to enable the checking, but first we have to find out the ID of our checker to set it as the active one.

local theIndex = 0

We initialize a user variable to zero,

for i = 1 to xViewChecker.getNumCheckers() do
if xViewChecker.getCheckerName i == "Face Area Checker" do theIndex = i

and loop from one to the number of existing checkers, comparing their names with our checker's name. If we find a match, we record its index in the variable theIndex.

if theIndex > 0 do   
(
xViewChecker.setActiveCheckerID(xViewChecker.getCheckerIDtheIndex)
xViewChecker.on = true

If after looping through all checkers registered with the xView system, the variable theIndex contains a value higher than zero, our checker is actually available and we can access it.

We set theactive checker ID to the ID of the checker with the index we detected.

Then, we enable the xView system.

)
)
)
)--end MacroScript

Using the Script

Now, that we have an xView checked and a MacroScript to control it, we can customize the Viewport Menus to add our checker to the list of available xView Checkers.

Evaluate the script by pressing Ctrl+E to create an ActionItem. A copy of the MacroScript code will be saved automatically in the \usermacros folder of 3ds Max and will be available in future 3ds Max sessions. It is NOT necessary to put the MacroScript source code in a \Startup or \Plugins folder.

At this point you can go to Main Menu > Customize > Customize User Interface and select the Menus tab in the Customize User Interface dialog.

Color Action
Red

Select the xView Category in the left drop-down list.

Greeen

Select Views - xView Menu in the right drop-down list.

Purple

Drag two Separator lines to the menu.

Yellow

Drag the Face Area Checker Display Mode ActionItem between the two lines.

Blue

Save the Custom Interface to disk to make the changes permanent. Confirm the overwriting of the CUI file.

Previous

How To ... Develop A Face Area XView Checker - Part3

See Also