Melscript n00b: marking menu question

hi all, i’m a beginning poly modeler who is trying to learn a little melscript based on this “simple” tutorial posted at http://bit.ly/gps0nd.

i’m wracking my brains and google-fu over this one. i am attempting to alter the behavior of the “right-click in an empty viewport space” marking menu.

the melscript for that is “buildObjectMenuItemsNow.mel”. i want to make the North function a backface culling toggle on/off and the South function a call to the menu “Display>Polygons>Custom Polygons Display Options”.

i’m just getting into poly modeling. i’m a n00b around scripting but spent 8 hours on this yesterday. 8 hours of attempt>execute>fail on syntax… i wasn’t suprised by failure. but i learned a ton.

the error:

buildObjectMenuItemsNow "MayaWindow|formLayout1|viewPanes|modelPanel4|modelPanel4|modelPanel4|modelPanel4ObjectPop";
// Error: displayString identifier "m_buildObjectMenuItemsNow.kCustomPolygonDisplayOptions" does not exist. //

the script with my modification:

global proc buildObjectMenuItemsNow( string $parentName)
{
 global int $gIsMarkingMenuOn;

 if (popupMenu -e -exists $parentName) {
 popupMenu -e -deleteAllItems $parentName; 
 if (popupMenu -q -mm $parentName != $gIsMarkingMenuOn) {
 popupMenu -e -mm $gIsMarkingMenuOn $parentName;
 }
 if (!dagObjectHit -mn $parentName) {
 string $leadObject[] = ls -sl -tail 1 -typ transform -typ shape;
 if (size($leadObject) > 0) {
 dagMenuProc($parentName, $leadObject[0]);
 } else {
 setParent -menu $parentName;

 menuItem
 -label (uiRes("m_buildObjectMenuItemsNow.kSelectAll"))
 -radialPosition "S"
 -command ("SelectAll");

             menuItem
 -label (uiRes("m_buildObjectMenuItemsNow.kCustomPolygonDisplayOptions"))
 -radialPosition "N"
 -command ("CustomPolygonDisplayOptions;");

             setParent ..;
 }
 }
 } else {
 warning (uiRes("m_buildObjectMenuItemsNow.kParentWarn"));
 }
}

I'm not sure about the north, south thing (don't have time to check it out.. it's 05.45 in the morning and I have to go to bed) but as for the error message you quoted (//Error: bla bla does not exist...) the reason is that the UI mel scripts, including buildObjectMenuItemsNow.mel, have a file called buildObjectMenuItemsNow.res.mel which contains the definitions of the menuitems (kSomeFunction), and buildObjectMenuitemsNow doesn't contain kCustomPolygonDisplayOptions... it only contains kCompleteTool, kParentWarn and kSelectAll.

So you need to refer to buildDisplayMenu.mel and its call to "m_buildDisplayMenu.kBackfaceCulling".

This gives me a single backface culling entry when right clicking in an empty space:

global proc buildObjectMenuItemsNow( string $parentName)
{
	global int $gIsMarkingMenuOn;
 
	if (`popupMenu -e -exists $parentName`) {
		popupMenu -e -deleteAllItems $parentName;	
		if (`popupMenu -q -mm $parentName` != $gIsMarkingMenuOn) {
			popupMenu -e -mm $gIsMarkingMenuOn $parentName;
		}
		if (!`dagObjectHit -mn $parentName`) {
			string $leadObject[] = `ls -sl -tail 1 -typ transform -typ shape`;
			if (size($leadObject) > 0) {
				dagMenuProc($parentName, $leadObject[0]);
			} else {
				setParent -menu $parentName;
 
        menuItem
					-label (uiRes("m_buildDisplayMenu.kBackfaceCulling")) 
					-annotation (uiRes("m_buildDisplayMenu.kBackfaceCullingAnnot"))
					-command "ToggleBackfaceGeometry"
					polyBackfaceCullingItem
					;
 
            	setParent ..;
			}
		}
	} else {
		warning (uiRes("m_buildObjectMenuItemsNow.kParentWarn"));
	}
}