Refactor DCCsi to work better with O3DE changes (#4226)

* moving files in refactor/re-org

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* dev env refactor/re-org

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* moving/re-org so we can deprate the SDK nomiclature

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* moving/re-org so we can deprate the SDK nomiclature

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Refactoring env so I can replace SDK with Tools folder

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* re-org and prune, from SKD to Tools

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Removing old .bat files from SDK

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* updated how to retreive PYTHONHOME

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Can't use/set PYTHONHOME with DCC Tools

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* small refactor

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* repaired a missed typo (causes error)

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Added missing EntityId.h include to FocusModeInterface.h

Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>

* refactor additional LY to O3DE tags

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Some design scaffold file stubs

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* stubbing in scaffold file pattern

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Removal of corrupted prefabs

Signed-off-by: Benjamin Black <benblac@amazon.com>

* refactored config_utils to maintain py2.7 support for maya 2020

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* refactored config_utils to maintain py2.7 support for maya 2020

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* pruning and cleanup

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* .env is for local dev overrides

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* .env is for local dev overrides

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* clean up init and logging patterns

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* Core refactoring, config.py functional standalone

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* cleaned up some bad logging, fixed up boostrap

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* fixed validation errors

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* fix logging issue, tiddy up

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* tiddy up maya for .bat bootstraping and launch

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

* name stub, fix validation

Signed-off-by: Jonny Gallowy <gallowj@amazon.com>

Co-authored-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
Co-authored-by: Benjamin Black <benblac@amazon.com>
This commit is contained in:
Jonny Galloway
2021-10-21 19:03:49 -05:00
committed by GitHub
parent 50068bcae7
commit b779f358d0
197 changed files with 3779 additions and 3636 deletions
@@ -0,0 +1,73 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.3dsmax.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.3dsmax'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the 3dsmax api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
import pymxs
import MaxPlus
# extend all with submodules
#__all__.append('foo', 'bar')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,53 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
"""azpy.shared.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,71 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.blender.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.blender'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the blender bpy api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
import bpy
# extend all with submodules
#__all__.append('foo', 'bar')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,71 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.houdini.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.houdini'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the houdini api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
import hou
# extend all with submodules
#__all__.append('foo', 'bar')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,71 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.houdini.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.marmoset'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the marmoset api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
import mset
# extend all with submodules
#__all__.append('foo', 'bar')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,68 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.dcc.maya.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
__all__ = []
# -------------------------------------------------------------------------
def init():
"""If the maya api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
import maya.cmds as mc
import maya.api.OpenMaya as om
__all__.append('callbacks')
__all__.append('helpers')
__all__.append('toolbits')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,41 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.maya.callbacks.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.maya.callbacks'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
__all__ = ['event_callback_handler',
'node_message_callback_handler',
'on_shader_rename']
del _LOGGER
#--------------------------------------------------------------------------
@@ -0,0 +1,221 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# <DCCsi>\\azpy\\maya\\\callbacks\\event_callback_handler.py
# Maya event callback handler
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
"""
Module Documentation:
<DCCsi>:: azpy//maya//callbacks//event_callback_handler.py
.. module:: event_callback_handler
:synopsis: Simple event based callback_event handler
using maya.api.OpenMaya (api2)
.. :note: nothing mundane to declare
.. :attention: callbacks should be uninstalled on exit
.. :warning: maya may crash on exit if callbacks are not uninstalled
.. Usage:
def test_func(*arg):
_logging.debug("~ test_func ccallbackEvent fired! arg={0}"
"".format(arg))
#register an event based based callback event
cb = EventCallbackHandler('NameChanged', test_func)
.. Reference:
The following call will return all the available events that can be
passed into the EventCallbackHandler.
import maya.api.OpenMaya as openmaya
openmaya.MEventMessage.getEventNames()
Important ones for quick reference are:
quitApplication
SelectionChanged
NameChanged
SceneSaved
NewSceneOpened
SceneOpened
PostSceneRead
workspaceChanged
.. moduleauthor:: Amazon Lumberyard
"""
#--------------------------------------------------------------------------
# -- Standard Python modules
import os
# -- External Python modules
# -- Lumberyard Extension Modules
import azpy
from azpy.env_bool import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# -- Maya Modules
import maya.api.OpenMaya as openmaya
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# -- Misc Global Space Definitions
_DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.callbacks.event_callback_handler'
_LOGGER = azpy.initialize_logger(_PACKAGENAME, default_log_level=int(20))
_LOGGER.debug('Invoking:: {0}.'.format({_PACKAGENAME}))
# --------------------------------------------------------------------------
# =========================================================================
# First Class
# =========================================================================
class EventCallbackHandler(object):
"""
A simple Maya event based callback_event handler class
:ivar callback_event: stores event type trigger for a maya callback_event
:vartype event: for example, 'NameChanged'
:ivar this_function: stores this_function to call when callback_event is triggered
:vartype this_function: for example,
cb = EventCallbackHandler(callback_event='NameChanged',
this_function=test_func)
"""
# --BASE-METHODS-------------------------------------------------------
# --constructor-
def __init__(self, callback_event, this_function, install=True):
"""
initializes a callback_event object
"""
# callback_event id storage
self._callback_id = None
# state tracker
self._message_id_set = None
# the callback_event event trigger
self._callback_event = callback_event
# the thing to do on callback_event
self._function = this_function
if install:
self.install()
# --properties---------------------------------------------------------
@property
def callback_id(self):
return self._callback_id
@property
def callback_event(self):
return self._callback_event
@property
def this_function(self):
return self._this_function
# --method-------------------------------------------------------------
def install(self):
"""
installs this callback_event for event, which makes it active
"""
add_event_method = openmaya.MEventMessage.addEventCallback
# when called, check if it's already installed
if self._callback_id:
_LOGGER.warning("EventCallback::{0}:{1}, is already installed"
"".format(self._callback_event,
self._function.__name__))
return False
# else try to install it
try:
self._callback_id = add_event_method(self._callback_event,
self._function)
except Exception as e:
_LOGGER.error("Failed to install EventCallback::'{0}:{1}'"
"".format(self._callback_event,
self._function.__name__))
self._message_id_set = False
else:
_LOGGER.debug("Installing EventCallback::{0}:{1}"
"".format(self._callback_event,
self._function.__name__))
self._message_id_set = True
return self._callback_id
# --method-------------------------------------------------------------
def uninstall(self):
"""
uninstalls this callback_event for the event, deactivates
"""
remove_event_callback = openmaya.MEventMessage.removeCallback
if self._callback_id:
try:
remove_event_callback(self._callback_id)
except Exception as e:
_LOGGER.error("Couldn't remove EventCallback::{0}:{1}"
"".format(self._callback_event,
self._function.__name__))
self._callback_id = None
self._message_id_set = None
_LOGGER.debug("Uninstalled the EventCallback::{0}:{1}"
"".format(self._callback_event,
self._function.__name__))
return True
else:
_LOGGER.warning("EventCallback::{0}:{1}, not currently installed"
"".format(self._callback_event,
self._function.__name__))
return False
# --method-------------------------------------------------------------
def __del__(self):
"""
if object is deleted, the callback_event is uninstalled
"""
self.uninstall()
# -------------------------------------------------------------------------
#==========================================================================
# Class Test
#==========================================================================
if __name__ == "__main__":
def test_func(*arg):
print("~ test_func callback_event fired! arg={0}"
"".format(arg))
cb = EventCallbackHandler('NameChanged', test_func)
cb.install()
# callback_event is active
#cb.uninstall()
## callback_event not active
@@ -0,0 +1,286 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# <DCCsi>\\azpy\\maya\\\callbacks\\node_message_callback_handler.py
# Maya node message callback handler
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
"""
.. module:: node_message_callback_handler
:synopsis: this module contains code related to mNodeName message based callbacks in Maya
.. moduleauthor:: Amazon Lumberyard
.. :note: nothing mundane to declare
.. :attention: callbacks should be uninstalled on exit
.. :warning: maya may crash on exit if callbacks are not uninstalled
.. Usage:
< To Do >
.. Version:
0.1.0 | prototype
.. History:
< To Do >
.. Reference:
MNodeMessage
This class is used to register callbacks for dependency mNodeName messages of specific dependency nodes.
http://download.autodesk.com/us/maya/2011help/API/class_m_node_message.html
There are 4 add thisCallback methods which will add callbacks for the following types of messages:
- Attribute Changed
- Attribute Added or Removed
- Node Dirty
- Name Changed
If we import OpenMaya,
import maya.api.OpenMaya as om
from maya.api.OpenMaya import MNodeMessage as mNM
The valid callbacks for usage are:
mNM.addAttributeChangedCallback
mNM.addAttributeAddedOrRemovedCallback
mNM.addNodeDirtyCallback
mNM.addNodeDirtyPlugCallback
mNM.addNameChangedCallback
mNM.addNodeAboutToDeleteCallback
mNM.addNodePreRemovalCallback
mNM.addNodeDestroyedCallback
mNM.addKeyableChangeOverride
"""
# --------------------------------------------------------------------------
# -- Standard Python modules
import os
# -- External Python modules
# -- Lumberyard Extension Modules
import azpy
from azpy.env_bool import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# -- Maya Modules --
import maya.api.OpenMaya as om
import maya.cmds as mc
#--------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -- Misc Global Space Definitions
_DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.callbacks.event_callback_handler'
_LOGGER = azpy.initialize_logger(_PACKAGENAME, default_log_level=int(20))
_LOGGER.debug('Invoking:: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# =========================================================================
# First Class
# =========================================================================
class NodeMessageCallbackHandler(object):
"""
< To Do: document Class >
"""
# --BASE-METHODS-------------------------------------------------------
# --constructor-
def __init__(self,
this_function,
this_callback,
mNodeName=None, # keep maya camel case formatting?
install=True,
*args, **kwargs):
"""
initializes a this_callback object
"""
# this_callback id storage
self._callback_type_id = None
# state tracker
self._message_id_set = None
# the this_callback event trigger
self._this_callback = this_callback
# the thing to do on this_callback
self._function = this_function
# this handlers object mNodeName
# passing in a null MObject (ie, without a name as an argument)
# registers the this_callback to get all name changes in the scene
# if you wanted to monitor a specific object's name changes
# you could pass a name to the MObject
if mNodeName is None:
self._m_object = om.MObject()
else:
self._m_object = om.MObject(mNodeName)
# install / activate this callback
if install:
self.install()
#----------------------------------------------------------------------
#--properties----------------------------------------------------------
@property
def callback_id(self):
return self._callback_type_id
@property
def this_callback(self):
return self._this_callback
@property
def this_function(self):
return self._this_function
#--properties----------------------------------------------------------
# --method-------------------------------------------------------------
def install(self):
"""
installs this this_callback for event, which makes it active
"""
# when called, check if it's already installed
if self._callback_type_id:
_LOGGER.warning("NodeMessageCallback::{0}:{1}, is already installed"
"".format(self._this_callback,
self._function.__name__))
return False
# else try to install it
try:
self._callback_type_id = self._this_callback(self._m_object,
self._function)
except Exception as e:
_LOGGER.error("Failed to install NodeMessageCallback::'{0}:{1}'"
"".format(self._this_callback,
self._function.__name__))
self._message_id_set = False
else:
_LOGGER.debug("Installing NodeMessageCallback::{0}:{1}"
"".format(self._this_callback,
self._function.__name__))
self._message_id_set = True
return self._callback_type_id
#----------------------------------------------------------------------
# --method-------------------------------------------------------------
def uninstall(self):
"""
uninstalls this thisCallback for the event, deactivates
"""
if self._callback_type_id:
try:
om.MMessage.removeCallback(self._callback_type_id)
except Exception as e:
_LOGGER.error("Couldn't remove NodeMessageCallback::{0}:{1}"
"".format(self._this_callback,
self._function.__name__))
self._callback_type_id = None
self._message_id_set = None
_LOGGER.debug("Uninstalled the NodeMessageCallback::{0}:{1}"
"".format(self._this_callback,
self._function.__name__))
return True
else:
_LOGGER.warning("NodeMessageCallback::{0}:{1}, not currently installed"
"".format(self._this_callback,
self._function.__name__))
return False
#----------------------------------------------------------------------
# --method-------------------------------------------------------------
def __del__(self):
"""
if object is deleted, the thisCallback is uninstalled
"""
self.uninstall()
#----------------------------------------------------------------------
# -------------------------------------------------------------------------
# =========================================================================
# Public Functions
# =========================================================================
# --First Function---------------------------------------------------------
def testNameChanged(*args):
# get node
try:
mNode = args[0]
except Exception as e:
mNode = None
_LOGGER.debug('\t~ no node')
_LOGGER.debug('\t~ warning: {0}'.format(e))
# get old name
try:
oldName = args[1]
except Exception as e:
oldName = None
_LOGGER.debug('\t~ no oldName')
_LOGGER.debug('\t~ warning: {0}'.format(e))
# convert the MObject to a dep mNode
try:
depNode = om.MFnDependencyNode(mNode)
except Exception as e:
depNode = None
_LOGGER.debug('\t~ no depNode')
_LOGGER.debug('\t~ warning: {0}'.format(e))
if oldName == (u""): oldName = 'null'
# get node type
try:
nodeType = depNode.typeName()
except Exception as e:
nodeType = None
_LOGGER.debug('\t~ no nodeType')
_LOGGER.debug('\t~ warning: {0}'.format(e))
# get node name
try:
nodeName = depNode.name()
except Exception as e:
nodeName = None
_LOGGER.debug('\t~ no nodeType')
_LOGGER.debug('\t~ warning: {0}'.format(e))
_LOGGER.debug('----\ntestNameChangedCallback')
_LOGGER.debug('newName: {0}'.format(nodeName))
_LOGGER.debug('oldName: {0}'.format(oldName))
_LOGGER.debug('nodeType: {0}'.format(nodeType))
return depNode
# -------------------------------------------------------------------------
#==========================================================================
# Run as LICENSE
#==========================================================================
if __name__ == '__main__':
name_changed_callback = om.MNodeMessage.addNameChangedCallback
ncbh = NodeMessageCallbackHandler(name_changed_callback,
testNameChanged)
@@ -0,0 +1,217 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# <DCCsi>\\azpy\\maya\\\callbacks\\on_shader_rename.py
# Maya node message callback handler
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
"""
.. module:: on_shader_rename
:synopsis: when a node name change fires off a callback, if that callback
is registered to this function the node will be passed in. If the node
is a shader node, we will find that shaders shadingGroup and give it a
similar name.
.. moduleauthor:: Amazon Lumberyard
.. :note: nothing mundane to declare
.. :attention: callbacks should be uninstalled on exit
.. :warning: maya may crash on exit if callbacks are not uninstalled
.. Usage:
when a rename node callback is fired, the node information is passed
to the function on_shader_rename(*args) as a tuple
args[0] is OpenMaya.MObject, which is the object
args[1] is the node previous name
args[2] None (not sure what else could get passed in here)
We get the dependancy node
depNode = om.MFnDependencyNode(arg[0])
We can check the node type
nodeType = mc.nodeType( depNode.name(), api=True )
If it's shader type the we are looking for, we can then find it's
shading engine (shadingGroup), we are looking for u"kPluginHardwareShader"
which is a dx11Shader (and possibly related hardware shader types)
if nodeType == "kPluginHardwareShader":
sG = findShadingGroup(depNode)
The function findShadingGroup(materialDepNode), will search the shaders
plugs for a om.MFn.kShadingEngine, if found it will return that node
Then we rename that node: sG.setName('{0}SG'.format(depNode.name()))
.. Version:
0.1.0 | prototype
.. History:
< To Do >
.. Reference:
< To Do >
"""
# --------------------------------------------------------------------------
# -- Standard Python modules
import os
# -- External Python modules
# -- Lumberyard Extension Modules
import azpy
from azpy.env_bool import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# -- Maya Modules
import maya.api.OpenMaya as om
import maya.cmds as mc
# -------------------------------------------------------------------------
# --------------------------------------------------------------------------
# -- Misc Global Space Definitions
_DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.callbacks.on_shader_rename'
_LOGGER = azpy.initialize_logger(_PACKAGENAME, default_log_level=int(20))
_LOGGER.debug('Invoking:: {0}.'.format({_PACKAGENAME}))
# --------------------------------------------------------------------------
# =========================================================================
# Public Functions
# =========================================================================
# --First Function---------------------------------------------------------
def find_shading_group(materialDepNode):
""" To Do: Document"""
# before moving on, let's see if we can figure out if this is a material
# since we KNOW currently we are working with a specific type (dx11)
# we can already know what we are looking for: u"kPluginHardwareShader"
node_type = mc.nodeType(materialDepNode.name(), api=True) # ==> "kPluginObjectSet"
# if it's the right type, let;s move on
if node_type == "kPluginHardwareShader":
#plugs = om.MPlugArray()
#otherside = om.MPlugArray()
#the_shading_grp = om.MFnDependencyNode()
# gather the nodes connections
plugs = materialDepNode.getConnections()
the_shading_grp = None
# loop through connections to look for shadingGroup
for j in range(0, len(plugs)):
if plugs[j].isConnected:
otherside = plugs[j].connectedTo(False, True)
for i in range(0, len(otherside)):
if otherside[i].node().hasFn(om.MFn.kShadingEngine):
the_shading_grp = om.MFnDependencyNode(otherside[i].node())
# if we want this guys name, it's: theShadingGroup.name()
return the_shading_grp
else:
return None
# -------------------------------------------------------------------------
# --Second Function--------------------------------------------------------
def on_shader_rename_rename_shading_group(*args):
"""
When NameChangedCallback fires,
If the node being renamed is a dx11Shader (kPluginHardwareShader),
Find the shagingGroup and rename it to match
"""
# get node
try:
mNode = args[0] # matched maya camelCase
except Exception as e:
mNode = None
# convert the MObject to a dep mNode
if mNode:
depNode = om.MFnDependencyNode(mNode)
else:
depNode = None
# get node name
if depNode:
nodeName = depNode.name()
else:
nodeName = None
# this seems to return nothing in this situation
# https://tinyurl.com/y2uf66sh
# I would expect this to return: "shader/surface"
if nodeName:
classifications = mc.getClassification(nodeName)
# To Do: figure this out ^
# before moving on, let's see if we can figure out if this is a material
# since we KNOW currently we are working with a specific type (dx11)
# we can already know what we are looking for: u"kPluginHardwareShader"
if nodeName:
try:
nodeType = mc.nodeType(nodeName, api=True) # ==> "kPluginObjectSet"
except:
nodeType = None
# storage container
sG = None
# if it's the right type, let;s move on
if nodeType == "kPluginHardwareShader":
# get old name
try:
oldName = args[1]
except Exception as e:
oldName = None
_LOGGER.warning('no oldName: {0}'.format(e))
if oldName == (u""):
oldName = 'null'
# get the shadingGroup
sG = find_shading_group(depNode)
# now rename that node, to match <nodeName>SG
if sG:
try:
sG.setName('{0}SG'.format(nodeName))
except Exception as e:
sG = None
_LOGGER.warning('could not renameNode: {0}'.format(e))
else:
return None
# -------------------------------------------------------------------------
#==========================================================================
# Module Tests
#==========================================================================
if __name__ == '__main__':
name_change_cb = om.MNodeMessage.addNameChangedCallback
from .node_message_callback_handler import NodeMessageCallbackHandler
ncbh = NodeMessageCallbackHandler(name_change_cb,
on_shader_rename_rename_shading_group)
@@ -0,0 +1,39 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.dcc.maya.helpers.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.callbacks'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
__all__ = ['undo_context', 'utils']
del _LOGGER
# --------------------------------------------------------------------------
@@ -0,0 +1,116 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# <DCCsi>\\azpy\\maya\\\callbacks\\node_message_callback_handler.py
# Maya node message callback handler
# Reference: Rob Galanakis, Tech-artists.org
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
"""
This module creates a simple Class object for managing Maya Undo Chunking.
"""
# -------------------------------------------------------------------------
# -- Standard Python modules
import os
from functools import wraps
# -- External Python modules
# -- Lumberyard Extension Modules
from azpy import initialize_logger
from azpy.env_bool import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# -- Maya Modules --
import maya.cmds as mc
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -- Misc Global Space Definitions
_DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.helpers.undo_context'
_LOGGER = initialize_logger(_PACKAGENAME, default_log_level=int(20))
_LOGGER.debug('Invoking:: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# =========================================================================
# First Class
# =========================================================================
class UndoContext(object):
"""
This Class creates a undo context chunk
"""
def __enter__(self):
mc.undoInfo(openChunk=True)
def __exit__(self, *exc_info):
mc.undoInfo(closeChunk=True)
# -------------------------------------------------------------------------
# =========================================================================
# Undo Decorator ... makes a whole function call undoable
# =========================================================================
def undo(func, autoUndo=False):
"""
Puts the wrapped `func` into a single Maya Undo action,
then undoes it when the function enters the finally: block
"""
@wraps(func)
def _undofunc(*args, **kwargs):
try:
# start an undo chunk
mc.undoInfo( openChunk = True )
return func( *args, **kwargs )
finally:
# after calling the func, end the undo chunk and undo
mc.undoInfo( closeChunk = True )
if autoUndo:
mc.undo()
return _undofunc
# -------------------------------------------------------------------------
# =========================================================================
# Public Functions
# =========================================================================
# --First Function---------------------------------------------------------
def test():
"""test() example undo context """
## This is how you call to the UndoContext()
with UndoContext():
# Do a couple things, in a block
# undo should step backwards clearing all of them at once
mc.polySphere(sx=10, sy=15, r=20)
mc.move( 1, 1, 1 )
mc.move( 5, y=True )
# -------------------------------------------------------------------------
#==========================================================================
# Module Tests
#==========================================================================
if __name__ == "__main__" :
test()
@@ -0,0 +1,391 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
"""
azpy.dcc.maya utility module
"""
# -------------------------------------------------------------------------
# built in's
# none
# 3rd Party
# none
# Lumberyard extensions
from azpy import initialize_logger
from azpy.env_bool import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# maya imports
import maya.cmds as cmds
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -- Misc Global Space Definitions
_DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.helpers.undo_context'
_LOGGER = initialize_logger(_PACKAGENAME, default_log_level=int(20))
_LOGGER.debug('Invoking:: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# Initiate the Wing IDE debug connection.
if _DCCSI_GDEBUG:
#import azpy.dev.connectDebugger as lyDevConnnect
# lyDevConnnect()
pass
# -------------------------------------------------------------------------
# =========================================================================
# First Class
# =========================================================================
class Selection(object):
'''
Custom Class to handle selection data as well as helper commands
to use/parse the selection data
'''
component_prefixes = {0: 'vtx', 1: 'e', 2: 'f', 3: 'map', 4: 'vtxFace'}
#----------------------------------------------------------------------
def __init__(self):
self.selection = dict()
self._populate_selection_data()
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def _populate_cpv_data(self):
'''
Color per-vertex data
Populates a dictionary:
color/alpha key -> vtxFace list
'''
for obj in self.selection.keys():
rgba_dict = dict()
if not cmds.listRelatives( obj, shapes = True ) :
self.selection[obj].append( rgba_dict )
continue
selection_list = []
selection_list = self.get_vtx_face_list( obj )
if len(selection_list) == 0:
# build attribute fetch
attrTag = '{0}.{1}'.format( obj, "vtxFace[*][*]")
# objects vtxFaceList
obj_vtx_faces = cmds.polyListComponentConversion(attrTag,
toVertexFace=True)
selection_list = cmds.ls( obj_vtx_faces,
long = True,
flatten = True )
for vtx_face in selection_list:
# get color RGB values
try:
# query the color
color_list = cmds.polyColorPerVertex( vtx_face,
query = True,
colorRGB = True)
except:
# if no color, assign balck
cmds.polyColorPerVertex( obj,
colorRGB = [0,0,0],
alpha = True)
color_list = cmds.polyColorPerVertex(vtx_face,
query=True,
colorRGB=True)
# and get alpha values
alpha = cmds.polyColorPerVertex(vtx_face,
query = True,
alpha = True)
# tuple up color and alpha
rgba = ( color_list[0], color_list[1], color_list[2], alpha[0] )
if rgba not in rgba_dict :
rgba_dict[rgba] = []
rgba_dict[rgba].append( vtx_face )
self.selection[obj].append( rgba_dict )
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def _make_component_dict(self, component_list):
'''Populates a dictionary of selected components of the given type'''
component = dict()
if not component_list:
return component
for comp in component_list :
# parent of this dag node
par = cmds.listRelatives( comp, parent = True, fullPath = True)[0]
# get transform
transform = cmds.listRelatives( par, parent = True, fullPath = True)[0]
# To Do: explain what this does
comp_num = comp.split('[')[-1].split(']')[0]
if transform not in component:
component[transform] = []
component[transform].append(comp)
return component
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def _fill_with_component_dict(self, component_type):
'''
Wrapper class for making a component dictionary
Takes in a component type:
http://download.autodesk.com/us/maya/2011help/CommandsPython/filterExpand.html
'''
sel_objs = []
component_dict = dict()
components_from_type = cmds.filterExpand(expand=True,
fullPath=True,
selectionMask=component_type)
# pack component dict
component_dict = self._make_component_dict( components_from_type )
try:
sel_objs += self.selection.keys()
except:
pass
try:
sel_objs += component_dict.keys()
except:
pass
sel_objs = set(sel_objs)
for obj in sel_objs:
if obj not in self.selection.keys() :
self.selection[obj] = []
if obj in component_dict:
self.selection[obj].append( component_dict[obj] )
else:
self.selection[obj].append( None )
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def _populate_selection_data(self):
'''Main population method for filling the class with all the selection data'''
#Vertices - Edges - Faces - UVs - VtxFace - Color To VtxFace
#Final Selection Dictionary Map
sel_objs = []
try:
sel_objs += cmds.ls( selection = True, transforms = True, long = True )
except:
pass
try:
sel_objs += cmds.ls( hilite = True, long = True )
except:
pass
sel_objs = set( sel_objs )
for obj in sel_objs :
self.selection[obj] = []
self._fill_with_component_dict(31) # Polygon Vertices
self._fill_with_component_dict(32) # Polygon Edges
self._fill_with_component_dict(34) # Polygon Face
self._fill_with_component_dict(35) # Polygon UVs
self._fill_with_component_dict(70) # Polygon Vertex Face
self._populate_cpv_data()
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def store_selection(self):
'''Takes current selection and populates the class with the selection data'''
self.selection = dict()
self._populate_selection_data()
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def prettyprint(self):
'''Pretty Print method to inspect the selection data'''
crossbar_str = '{0}'.format('*' * 75)
print ( crossbar_str )
print ( '~ Begin Selection Data Output...' )
for key, value in self.selection.items() :
print key
#This is less explict but allows for expansion easier, lets test it out for a while
for itemSet in value:
print ' ', itemSet
#print ' vtx - ', value[0]
#print ' edg - ', value[1]
#print ' face - ', value[2]
#print ' UV - ', value[3]
#print ' vtx-face - ', value[4]
#print ' colorDict - ', value[5]
print ( crossbar_str )
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def select(self, obj, component_type, clear_selection=True, add_value=False):
'''Allow easy reselection of specific selection data'''
cmds.select( clear = clear_selection )
if self.selection[obj][component_type] != None :
cmds.hilite( obj )
cmds.select(self.selection[obj][component_type], add=add_value)
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def restore_selection(self):
'''Restores the selection back to how it was when the class populated its selection data'''
cmds.select( clear = True)
for obj in self.selection.keys() :
cmds.select( obj, add = True )
self.select( obj, 0, 0, add_value = True )
self.select( obj, 1, 0, add_value = True )
self.select( obj, 2, 0, add_value = True )
self.select( obj, 3, 0, add_value = True )
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def get_vtx_face_list(self, obj):
'''Turns all current selection data into a vtxFace selection list'''
selection_list = set()
# To Do: explain what this does
for index in xrange(0, 2) :
sel_part = self.selection[obj][index]
try:
sel = cmds.polyListComponentConversion( sel_part, toVertexFace = True)
selection_list.update( cmds.ls( sel, long = True, flatten = True) )
except:
pass
# To Do: explain what this does
try:
selection_list.update( self.selection[obj][4] )
except:
pass
return list(selection_list)
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def get_first_mesh(self):
'''Returns the first mesh it finds in the selection list'''
for item in self.selection.keys() :
if cmds.listRelatives( item, shanpes = True ) :
return item
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def get_component_list(self, obj, component_index=0):
if self.selection[obj][component_index] == None : # Return all
component_tag = '{0}.{1}[*]'.format(obj, self.component_prefixes[component_index])
return cmds.ls( component_tag, long = True, flatten = True )
else:
return self.selection[obj][component_index]
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def get_component_index(self, obj, component_index=0):
index_list = []
if self.selection[obj][component_index] :
for comp in self.selection[obj][component_index] :
component_number = comp.split('[')[-1].split(']')[0]
index_list.append(component_number)
return index_list
#----------------------------------------------------------------------
#----------------------------------------------------------------------
def get_inverse_component_index(self, obj, component_index=0):
''''''
index_list = []
full_component_list = []
if self.selection[obj][component_index] :
working = self.selection[obj][component_index]
sel_component_list = cmds.ls(working, long=True, flatten=True)
component_tag = '{0}.{1}[*]'.format(obj, self.component_prefixes[component_index])
full_component_list = cmds.ls( component_tag, long = True, flatten = True)
for comp in [comp for comp in full_component_list if comp not in sel_component_list ] :
component_number = comp.split('[')[-1].split(']')[0]
index_list.append(component_number)
return index_list
#----------------------------------------------------------------------
# -------------------------------------------------------------------------
#==========================================================================
# Class Test
#==========================================================================
if __name__ == '__main__':
# get a selection object
sel = Selection()
# to do: this needs some tests?
@@ -0,0 +1,38 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# --------------------------------------------------------------------------
"""azpy.dcc.maya.toolbits.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.toolbits'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
__all__ = ['detach']
del _LOGGER
#--------------------------------------------------------------------------
@@ -0,0 +1,121 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# <DCCsi>\\azpy\\maya\\\toolbits\\detach.py
# Maya event callback handler
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
'''
Module Documentation:
DccScriptingInterface\\azpy\\maya\\\toolbits\\detach.py
Implements a clean detach in maya
'''
# -------------------------------------------------------------------------
# built in's
# none
# 3rd Party
# none
# Lumberyard extensions
import azpy
import azpy.helpers.decorators.wrapper
#from azpy.helpers.decorators.wrapper import wrapper
# Maya Imports
import maya.mc as mc
# -------------------------------------------------------------------------
# global space debug flag
from azpy import env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
# global space
_DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.maya.toolbits.detatch'
import azpy
_LOGGER = azpy.initialize_logger(_PACKAGENAME)
_LOGGER.debug('Invoking __init__.py for {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
#@wrapper
def clean_detach(detachType=0, args=None, name=None,
deletHistoyIn=False, deleteHistoryOut=True):
'''
Helper Function to aid in detaching faces from any obj
or duplicating those faces without harming the orignal
'''
sel = azpy.dcc.maya.helpers.utils.Selection()
for obj in sel.selection.keys():
print("~ cleanDetach:: Working on: {0}".format(obj))
# set up / open the maya undo context
with azpy.dcc.maya.helpers.UndoContext():
if deletHistoyIn:
mc.delete( obj, constructionHistory = True)
obShortName = mc.ls( obj, shortNames = True)[0]
fubName = '{0}_detWrk0'.format(obShortName)
#newObj = mc.duplicate( obj, renameChildren = True, name = fubName)[0]
newObj = mc.duplicate( obj, name = fubName)[0]
mc.makeIdentity( newObj, apply = True, translate = True,
rotate = True, scale = True)
mc.delete( newObj, constructionHistory = True)
newObj = mc.parent(newObj, obj)
newObj = mc.ls( newObj, long = True)[0]
if sel.selection[obj][2] == None:
continue
# Continue detachin
faceList = []
for faceNum in sel.get_inverse_component_index(obj,2):
faceList.append( '{0}.f[{1}]'.format( newObj, str(faceNum) ) )
mc.delete(faceList)
if detachType == 0 :
mc.delete( sel.selection[obj][2] )
if name:
newObj = mc.rename( newObj, name )
#mc.delete(obj, constructionHistory = True)
if deleteHistoryOut:
mc.delete(newObj, constructionHistory = True)
mc.select( clear = True )
mc.select( newObj, toggle = True )
obj = mc.ls( obj, long = True)[0]
newObj = mc.ls( newObj, long = True)[0]
return obj, newObj
# -------------------------------------------------------------------------
@@ -0,0 +1,13 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# define api package for each IDE supported
__all__ = ['simple_command_port', 'execute_wing_code', 'wing_to_maya']
@@ -0,0 +1,116 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
import os
import socket
import logging as _logging
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def get_stub_check_path(in_path=__file__, check_stub='engineroot.txt'):
'''
Returns the branch root directory of the dev\\'engineroot.txt'
(... or you can pass it another known stub)
so we can safely build relative filepaths within that branch.
If the stub is not found, it returns None
'''
path = os.path.abspath(os.path.join(os.path.dirname(in_path), ".."))
_LOGGER.info('parent dir: {}'.format(path))
while 1:
test_path = os.path.join(path, check_stub)
if os.path.isfile(test_path):
return os.path.abspath(os.path.join(os.path.dirname(test_path)))
else:
path, tail = (os.path.abspath(os.path.join(os.path.dirname(test_path), "..")),
os.path.basename(test_path))
if (len(tail) == 0):
return None
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
# -- Global Definitions --
_MODULENAME = 'azpy.dcc.maya.utils.execute_wing_code'
_LOGGER = _logging.getLogger(_MODULENAME)
_O3DE_DEV = get_stub_check_path()
_LOGGER.info('_O3DE_DEV: {}'.format(_O3DE_DEV))
_PROJ_CACHE = os.path.join(_O3DE_DEV, 'cache', 'DCCsi', 'wing')
_LOGGER.info('_PROJ_CACHE: {}'.format(_PROJ_CACHE))
_LOCAL_HOST = socket.gethostbyname(socket.gethostname())
_LOGGER.info('local_host: {}'.format(_LOCAL_HOST))
# -------------------------------------------------------------------------
###########################################################################
# --main code block--------------------------------------------------------
def main(code_type='python'):
"""
Evaluate the temp file on disk, made by Wing, in Maya.
code_type : string : Supports either 'python' or 'mel'
"""
temp_file_name = 'tmp_wing_data.txt'
temp_file_path = os.path.join(_PROJ_CACHE, temp_file_name)
temp_file_path = os.path.abspath(temp_file_path)
temp_file = temp_file_path.replace("\\", "/") # maya is linux paths?
_LOGGER.debug('temp_file_path is: {}'.format(temp_file_path))
if os.access(temp_file, os.F_OK):
# open and print the file in Maya:
f = open(temp_file, "r")
lines = f.readlines()
for line in lines:
print(line.rstrip())
f.close()
if code_type == "python":
# execute the file contents in Maya:
f = open(temp_file, "r")
# (1) doesn't work?
#exec(f, __main__.__dict__, __main__.__dict__)
# (2) works is series of single expressions
#for line in lines:
#exec(line.rstrip())
# f.close()
# (3) this seems to work much better
temp_code_file_name = 'temp_code.py'
temp_code_file = os.path.join(_PROJ_CACHE, temp_code_file_name)
temp_code_file = os.path.abspath(temp_code_file)
temp_code = temp_file_path.replace("\\", "/") # maya is linux paths?
code = compile(f.read(), temp_code, 'exec')
_LOGGER.debug(type(code))
exec(code)
elif code_type == "mel":
mel_cmd = "source '{}'".format(temp_file)
# This causes the "// Result: " line to show up in the Script Editor:
om.MGlobal.executeCommand(mel_cmd, True, True)
else:
_LOGGER.warning("No temp file exists: {}".format(temp_file))
file=open(temp_file, "w")
file.write("test file write")
if os.path.isfile(temp_file):
_LOGGER.info('Created the temp file, please try again!')
else:
_LOGGER.error('File not created: {}'.format(temp_file))
return
# -------------------------------------------------------------------------
@@ -0,0 +1,239 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# -- Standard Python modules --
import sys
import os
import socket
import site
import time
import logging as _logging
# -- External Python modules --
# none
# -- Extension Modules --
# none (yet)
# --------------------------------------------------------------------------
# -- Global Definitions --
_MODULENAME = 'azpy.dcc.maya.utils.simple_command_port'
_LOGGER = _logging.getLogger(_MODULENAME)
_LOCAL_HOST = socket.gethostbyname(socket.gethostname())
_LOGGER.info('local_host: {}'.format(_LOCAL_HOST))
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
class SimpleCommandPort:
"""
Simple maya command port Object Class.
"""
#----------------------------------------------------------------------
#def __new__(self):
#try:
#self.port_name
#return self
#except NameError as e:
#self.port_name = None
#self.logger.error("Specify a port like: '127.0.0.1:6000'")
#return
#return
# -- Constructor ------------------------------------------------------
def __init__(self,
local_host=_LOCAL_HOST,
comman_port=6000,
logger=_LOGGER,
source_type='python',
echo_output=True,
noreturn=False,
*args, **kwargs):
'''
SimpleCommandPort Class Initialization
< To Do: Need to document >
Input Attributes:
-----------------
self. SCALAR: Description.
Default =
Keyword Arguments:
------------------
self. STRING: Description.
Default =
self. OBJECT: Description.
Default =
Additional Attributes:
----------------------
self. BOOLEAN: Description.
Default =
Documentation last updated: Month. Day, Year - Author
'''
# -- Default Values --
self._port_name = '0.0.0.0:0000'
self._port = None
self._logger = None
self._echo_output = echo_output
self._noreturn = noreturn
self._source_type = source_type
if logger != None:
self._logger = logger
# -- Input Checks --
if local_host != None and local_host != '0.0.0.0':
self._port_name = str('{0}:{1}'.format(local_host, comman_port))
else:
self.logger.error("Specify a port: SimpleCommandPort('127.0.0.1','6000')")
## -- init --
#try:
#self.port = self.cmdPortOpen()
#except Exception as e:
#self.port = None
#if self.logger:
#self.logger.autolog(e, level='error')
#else:
#self.logIt(e, level='error')
#----------------------------------------------------------------------
#--properties----------------------------------------------------------
@property
def port_name(self):
return self._port_name
@port_name.setter
def port_name(self, value):
self._port_name = value
return self._port_name
@port_name.getter
def port_name(self):
return self._port_name
@property
def port(self):
return self._port
@port.setter
def port(self, value):
self._port = value
return self._port
@property
def logger(self):
return self._logger
@logger.setter
def logger(self, value):
self._logger = value
return self._logger
#----------------------------------------------------------------------
# --method-------------------------------------------------------------
def open(self):
from azpy.dev.utils.check.maya_app import validate_state
if validate_state():
if self.port_name != None and self.port_name != '0.0.0.0:0000':
import maya.cmds as cmds
try:
self.logger.info('Opening the cmd port: {0}'
''.format(self.port_name))
except Exception as e:
self.logger.error('{0}'.format(e))
try:
# to do: get mel working
self.port = cmds.commandPort(name=self.port_name,
echoOutput=self._echo_output,
sourceType =self._source_type,
noreturn=self._noreturn)
self.logger.info('{0}:: Open!'.format(self.port_name))
time.sleep(0.25)
return True, self.port_name
except Exception as e:
self.logger.error('{0}'.format(e))
_LOGGER.info(cmds.commandPort(self.port_name, q=True))
self.port_name='ERROR'
return False, self.port_name
else:
self.logger.warning('Can not use a port: {}'.format(self.port_name))
else:
self.logger.warning('Did not perform port open, Not running Maya!')
return False
#----------------------------------------------------------------------
# --method-------------------------------------------------------------
def close(self):
self.logger.info('Closing the port: {0}'.format(self.port_name))
try:
import maya.cmds as cmds
cmds.commandPort(name=self.port_name, close=True, echoOutput=self._echo_output)
self.port = None
self.logger.info('{0}:: Port Closed!'.format(self.port_name))
except Exception as e:
self.logger.error('{0}'.format(e))
self.port_name = 'ERROR'
return False
time.sleep(1)
return True
#----------------------------------------------------------------------
# -------------------------------------------------------------------------
###########################################################################
# Main Code Block, runs this script as main (testing)
# -------------------------------------------------------------------------
if __name__ == '__main__':
_DCCSI_GDEBUG = True
_DCCSI_DEV_MODE = True
_LOGGER.setLevel(_logging.DEBUG) # force debugging
# -- Extend Logger
#_handler = _logging.StreamHandler(sys.stdout)
# _handler.setLevel(_logging.DEBUG)
#FRMT_LOG_LONG = "[%(name)s][%(levelname)s] >> %(message)s (%(asctime)s; %(filename)s:%(lineno)d)"
#_formatter = _logging.Formatter(FRMT_LOG_LONG)
# _handler.setFormatter(_formatter)
# _LOGGER.addHandler(_handler)
#_LOGGER.debug('Loading: {0}.'.format({_MODULENAME}))
# happy print
from azpy.constants import STR_CROSSBAR
_LOGGER.info(STR_CROSSBAR)
_LOGGER.info('{} ... Running script as __main__'.format(_MODULENAME))
_LOGGER.info(STR_CROSSBAR)
# should throw an error message
foo_port = SimpleCommandPort()
# should attemp to open the port, should warn as defualt port is '0.0.0.0:0000'
foo_port.open()
# should return a port object
foo_port = SimpleCommandPort('127.0.0.1:6000')
# should attemp to open the port, which should warn because only works in Maya
foo_port.open()
_LOGGER.info('Port Name: {}'.format(foo_port.port_name))
@@ -0,0 +1,151 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# -- Standard Python modules --
import sys
import os
import site
import socket
import time
import logging as _logging
# -- External Python modules --
# none
# -- Extension Modules --
from simple_command_port import SimpleCommandPort
# --------------------------------------------------------------------------
# -- Global Definitions --
_MODULENAME = 'azpy.dcc.maya.utils.wing_to_maya'
_LOGGER = _logging.getLogger(_MODULENAME)
_LOCAL_HOST = socket.gethostbyname(socket.gethostname())
_LOGGER.info('local_host: {}'.format(_LOCAL_HOST))
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def start_wing_to_maya(local_host=_LOCAL_HOST,
command_port=6000,
logger=_LOGGER,
*args, **kwargs):
"""
imports the module
opens a port to run python code from wingIDE directly
"""
if logger != None:
_LOGGER = _LOGGER
try:
import maya.cmds as cmds
except ImportError as e:
_LOGGER.error('Could not perform: {}'.format(e))
raise e
try:
port
except NameError:
port = None
port_name = str('{0}:{1}'.format(local_host, command_port))
# should only be getting the port passed in
_LOGGER.info('Attempting to open port:: {0}'.format(port_name))
port_object = SimpleCommandPort(port_name)
try:
port = port_object.open()
except Exception as e:
_LOGGER.error('Could not open port: {e}'.format(e))
raise e
if not port:
return port
else:
try:
import execute_wing_code
except Exception as e:
_LOGGER.error('Could not execute code: {}'.format(e))
return 'Error'
time.sleep(0.25)
_LOGGER.info('WingIDE: Python >> to >> Maya, is started.')
try:
test_port = cmds.commandPort(port_name, q=True)
except Exception as e:
_LOGGER.autolog(e, level='error')
return 'Error'
if test_port:
message = 'That port is already open. '
message += 'Attempting to close old port, so I can re-establish it...'
_LOGGER.info(message)
try:
cmds.commandPort(name=port_name, close=True, echoOutput=True)
except Exception as e:
_LOGGER.error(''.format(e))
time.sleep(0.25)
try:
test_port = cmds.commandPort(port_name, q=True)
except Exception as e:
_LOGGER.error('Could not query port: {}'.format(e))
if test_port == False:
_LOGGER.info('Port closed! Re-opening ...')
try:
port = SimpleCommandPort(port_name)
except Exception as e:
_LOGGER.error('Could not create port object: {}'.format(e))
time.sleep(0.25)
try:
test_port = cmds.commandPort(port_name, q=True)
_LOGGER.info('The posrt is: {}'.format(test_port))
except Exception as e:
_LOGGER.error('Could not query port: {}'.format(e))
elif test_port == False:
_LOGGER.info('The port does not exist ... attempting to open it again now')
try:
port = SimpleCommandPort(port_name)
except Exception as e:
_LOGGER.error('Could not create port: {}'.format(e))
time.sleep(0.25)
try:
test_port = cmds.commandPort(port_name, q=True)
_LOGGER.info('Port is: {}'.format(test_port))
except Exception as e:
_LOGGER.error('Could not create port: {}'.format(e))
return port
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def start_wing_to_maya_menu():
"""
Simple hook to call the function from a menu item,
using the default port name defined
"""
port = object() # init a dummy object
# default name ... name is first arg, or a kwarg
portName, kwargs = set_synth_arg_kwarg(port, arg_pos_index=0, arg_tag='portName',
in_args=args, in_kwargs=kwargs,
default_value="127.0.0.1:6000")
port = start_wing_to_maya(local_host=_LOCAL_HOST, command_port=6000)
return
# -------------------------------------------------------------------------
@@ -0,0 +1,72 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.lumberyard.__init__
All O3DE related extension packages/modules should live here."""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.o3de'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the lumberyard azlmbr api is required for a package/module to
import, then it should be initialized and added here so general imports
don't fail"""
import azlmbr
# extend all with submodules
__all__.append('atom')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,74 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.render.__init__
This package generically uses 'render' to refer to Atom (which is a code name.)
All Atom render related packages/modules should live here."""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.o3de.atom'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the atom render api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
# import <some atom api>
# extend all with submodules
#__all__.append('foo', 'bar')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
del _LOGGER
@@ -0,0 +1,71 @@
# coding:utf-8
#!/usr/bin/python
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
# -- This line is 75 characters -------------------------------------------
# The __init__.py files help guide import statements without automatically
# importing all of the modules
"""azpy.substance.__init__"""
import logging as _logging
import azpy.env_bool as env_bool
from azpy.constants import ENVAR_DCCSI_GDEBUG
from azpy.constants import ENVAR_DCCSI_DEV_MODE
from azpy.constants import FRMT_LOG_LONG
# global space
_DCCSI_GDEBUG = env_bool.env_bool(ENVAR_DCCSI_GDEBUG, False)
_DCCSI_DEV_MODE = env_bool.env_bool(ENVAR_DCCSI_DEV_MODE, False)
_PACKAGENAME = __name__
if _PACKAGENAME is '__main__':
_PACKAGENAME = 'azpy.dcc.substance'
# set up module logging
for handler in _logging.root.handlers[:]:
_logging.root.removeHandler(handler)
_LOGGER = _logging.getLogger(_PACKAGENAME)
_logging.basicConfig(format=FRMT_LOG_LONG)
_LOGGER.debug('Initializing: {0}.'.format({_PACKAGENAME}))
# -------------------------------------------------------------------------
# These are explicit imports for now
__all__ = []
# To Do: procedurally discover dcc access and extend __all__
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def init():
"""If the substance api is required for a package/module to import,
then it should be initialized and added here so general imports
don't fail"""
# Make sure we can import the native apis
# import <some substance api>
# extend all with submodules
#__all__.append('foo', 'bar')
# Importing local packages/modules
pass
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
if _DCCSI_DEV_MODE:
# If in dev mode this will test imports of __all__
from azpy import test_imports
_LOGGER.debug('Testing Imports from {0}'.format(_PACKAGENAME))
test_imports(__all__,
_pkg=_PACKAGENAME,
_logger=_LOGGER)
# -------------------------------------------------------------------------
del _LOGGER