__all__ = ['SidedCustom', 'instantiate']
from awSupportApi import ApplicationMode
from MessageInterpreter import MessageInterpreter
from MessageRegistry import theMessageRegistry
from ParameterConstant import ParameterConstant
from RTFapi import Appearance, Parameter
from UserCustomization import UserCustomBase, CustomInfo
from Application import theApplication
SET_SIDED_Doc = \
[(
"""
Set single or double sided when display the model.
"""
),
[[("objects"),("The model which to be displayed in single or doubel sided.")],
[("sided"),("Single or double.")]
]
]
theMessageRegistry.register("SET_SIDED",
(tuple,unicode), 0, SET_SIDED_Doc)
class SidedCustom (UserCustomBase):
def __init__(self):
self.__mySingleId = None
self.__myDoubleId = None
self.__myInterpreter = LocalInterpreter()
def getInterpreter(self,isInteractive):
if isInteractive:
return self.__myInterpreter
return None
def appendMenuItems(self,id,menu):
if "Appearance" == id:
self.__mySingleId = menu.appendItem(_( 'Set Single Sided' ),
self.__onSingle )
self.__myDoubleId = menu.appendItem(_( 'Set Double Sided' ),
self.__onDouble )
def enableMenuStates(self,id,enableStates):
if "Appearance" == id:
if self.__myInterpreter:
enabled = self.__myInterpreter.Enabled()
else:
enabled = False
enableStates[self.__mySingleId] = enabled
enableStates[self.__myDoubleId] = enabled
def __onSingle( self, event ):
if self.__myInterpreter:
self.__myInterpreter.Single()
def __onDouble( self, event ):
if self.__myInterpreter:
self.__myInterpreter.Double()
class LocalInterpreter( MessageInterpreter ):
def __init__( self ):
MessageInterpreter.__init__( self )
def Single( self ):
if (theApplication.getCurrentDocument() is not None and
theApplication.getCurrentDocument().getModels() is not None):
self.Sided( theApplication.getCurrentDocument().getModels().selected, ParameterConstant.kSingle )
def Double( self ):
if (theApplication.getCurrentDocument() is not None and
theApplication.getCurrentDocument().getModels() is not None):
self.Sided( theApplication.getCurrentDocument().getModels().selected, "double" )
def Enabled( self ):
return ApplicationMode.instance().isAuthoringMode() \
and theApplication.getCurrentDocument() is not None \
and theApplication.getCurrentDocument().getModels() is not None \
and not theApplication.getCurrentDocument().getModels().selected.empty()
def Sided( self, objects, sided ):
print "%s on %s" % (sided,objects)
self.sendMessage( "APPEARANCE_PARAMETER_CHANGE",
(tuple(objects), Appearance.kParameterCategoryObject, ParameterConstant.kSided, sided, True, Parameter.kString) )
def SET_SIDED( self, message ):
( objects, sided ) = message.data
self.Sided( objects, sided )
def instantiate():
return SidedCustom()
def info():
customInfo = CustomInfo()
customInfo.vendor = 'Autodesk'
customInfo.version = '3.0'
customInfo.api = '2013'
customInfo.shortInfo = "Make objects single/double sided."
customInfo.longInfo = \
"""Add "Set Single Sided" and "Set Double Sided" menu items under "Apperance" menu to make objects \
single/double sided.
"""
return customInfo