set_defaults.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # coding:utf-8
  2. #!/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. # -- This line is 75 characters -------------------------------------------
  11. """
  12. Module Documentation:
  13. DccScriptingInterface:: SDK//maya//scripts//set_pref_defaults.py
  14. This module manages a predefined set of prefs for maya
  15. """
  16. # -------------------------------------------------------------------------
  17. # -- Standard Python modules
  18. import os
  19. import sys
  20. # -- External Python modules
  21. # -- DCCsi Extension Modules
  22. import azpy
  23. from azpy.constants import *
  24. # -- maya imports
  25. import maya.cmds as mc
  26. import maya.mel as mm
  27. # -------------------------------------------------------------------------
  28. # -------------------------------------------------------------------------
  29. from azpy.env_bool import env_bool
  30. from azpy.constants import ENVAR_DCCSI_GDEBUG
  31. from azpy.constants import ENVAR_DCCSI_DEV_MODE
  32. # global space
  33. _DCCSI_GDEBUG = env_bool(ENVAR_DCCSI_GDEBUG, False)
  34. _DCCSI_DEV_MODE = env_bool(ENVAR_DCCSI_DEV_MODE, False)
  35. _MODULENAME = r'DCCsi.SDK.Maya.Scripts.set_defaults'
  36. _LOGGER = azpy.initialize_logger(_MODULENAME, default_log_level=int(20))
  37. _LOGGER.debug('Invoking:: {0}.'.format({_MODULENAME}))
  38. # -------------------------------------------------------------------------
  39. # -------------------------------------------------------------------------
  40. def set_defaults(units='meter'):
  41. """This method will make defined settings changes to Maya prefs,
  42. to better configure maya to work with Lumberyard"""
  43. # To Do: make this data-driven env/settings, game teams should be able
  44. # to opt out and/or set their prefered configuration.
  45. _LOGGER.debug('set_defaults_lumberyard() fired')
  46. # set up default units ... this should be moved to bootstrap config
  47. _LOGGER.info('Default, 1 Linear Game Unit in Lumberyard == 1 Meter'
  48. ' in Maya content. Setting default linear units to Meters'
  49. ' (user can change to other units in the preferences)')
  50. result = mc.currentUnit(linear=units)
  51. # set up grid defaults
  52. _LOGGER.info('Setting Grid defaults, to match default unit scale.'
  53. '(user can change grid config manually')
  54. try:
  55. mc.grid(size=32, spacing=1, divisions=10)
  56. except Exception as e:
  57. _LOGGER.warning('{0}'.format(e))
  58. # viewFit
  59. _LOGGER.info('Changing default mc.viewFit')
  60. try:
  61. mc.viewFit()
  62. except Exception as e:
  63. _LOGGER.warning('{0}'.format(e))
  64. # some mel commands
  65. _LOGGER.info('Changing sersp camera clipping planes')
  66. try:
  67. mm.eval(str(r'setAttr "perspShape.nearClipPlane" 0.01;'))
  68. mm.eval(str(r'setAttr "perspShape.farClipPlane" 1000;'))
  69. except Exception as e:
  70. _LOGGER.warning('{0}'.format(e))
  71. # set up fixPaths
  72. _LOGGER.info('~ Setting up fixPaths in default scene')
  73. return 0
  74. # -------------------------------------------------------------------------