Python API 2.0 Reference
python/api2/modules/py2JsonAttrPatternInfo.py
1 """
2 Simple class to hold common information used by the JSON attribute pattern
3 reader and writer. To use, make sure that pyJsonAttrPatternInfo.py is in
4 your Python path then do the following:
5 
6 from pyJsonAttrPatternInfo import PyJsonAttrPatternInfo as JsonKeys
7 ...
8 flagKeyword = JsonKeys.kKeyFlags
9 ...
10 """
11 from builtins import object
12 import sys
13 import maya.api.OpenMaya as omAPI
14 
15 #======================================================================
16 def jsonDebug(dbgString):
17  """
18  Print out some debugging messages if the flag is turned on.
19  Lazily I'm making the location to turn it on be right here as well.
20  """
21  debuggingJson = True
22  if debuggingJson:
23  print('JSON: %s' % dbgString)
24  # Ensure the output gets seen immediately
25  sys.stdout.flush()
26 
27 #======================================================================
28 class PyJsonAttrPatternInfo(object):
29  kPluginPatternFactoryName = 'json'
30 
31  # Keywords representing attribute data
32  kKeyAcceptedTypes = 'acceptedTypes'
33  kKeyAcceptedNumericTypes = 'acceptedNumericTypes'
34  kKeyAcceptedPluginTypes = 'acceptedPluginTypes'
35  kKeyAttrType = 'attributeType'
36  kKeyFlags = 'flags'
37  kKeyName = 'name'
38  kKeyNiceName = 'niceName'
39  kKeyShortName = 'shortName'
40  kKeyCategories = 'categories'
41  kKeyEnumNames = 'enumNames'
42  kKeyDefault = 'defaultValue'
43  kKeyDisconnect = 'disconnectBehavior'
44  kKeyChildren = 'children'
45  kKeyMin = 'min'
46  kKeyMax = 'max'
47  kKeySoftMin = 'softMin'
48  kKeySoftMax = 'softMax'
49  #
50  # Key = Keyword saying what type of number the numerical attribute is
51  # Value = [Constant which defines that type in MFnNumericAttribute,
52  # Default value for that number type]
53  # Note that the clever juxtaposition of numeric and unit types allows
54  # the same code to be used for creating both.
55  #
56  kNumericTypes = { 'bool' : omAPI.MFnNumericData.kBoolean,
57  'byte' : omAPI.MFnNumericData.kByte,
58  'char' : omAPI.MFnNumericData.kChar,
59  'short' : omAPI.MFnNumericData.kShort,
60  'short2' : omAPI.MFnNumericData.k2Short,
61  'short3' : omAPI.MFnNumericData.k3Short,
62  'long' : omAPI.MFnNumericData.kLong,
63  'int' : omAPI.MFnNumericData.kInt,
64  'long2' : omAPI.MFnNumericData.k2Long,
65  'int2' : omAPI.MFnNumericData.k2Int,
66  'long3' : omAPI.MFnNumericData.k3Long,
67  'int3' : omAPI.MFnNumericData.k3Int,
68  'float' : omAPI.MFnNumericData.kFloat,
69  'float2' : omAPI.MFnNumericData.k2Float,
70  'float3' : omAPI.MFnNumericData.k3Float,
71  'double' : omAPI.MFnNumericData.kDouble,
72  'double2' : omAPI.MFnNumericData.k2Double,
73  'double3' : omAPI.MFnNumericData.k3Double,
74  'double4' : omAPI.MFnNumericData.k4Double,
75  'addr' : omAPI.MFnNumericData.kAddr,
76  'angle' : omAPI.MFnUnitAttribute.kAngle,
77  'distance': omAPI.MFnUnitAttribute.kDistance,
78  'time' : omAPI.MFnUnitAttribute.kTime }
79  #
80  # Non-numeric attribute types
81  #
82  kTypeCompound = 'compound'
83  kTypeEnum = 'enum'
84  kTypeString = 'string'
85  kTypeTyped = 'typed'
86  kTypeMatrix = ['floatMatrix', 'doubleMatrix']
87  kTypeMatrixTypes = { kTypeMatrix[0] : omAPI.MFnMatrixAttribute.kFloat,
88  kTypeMatrix[1] : omAPI.MFnMatrixAttribute.kDouble }
89  kTypeLightData = 'lightData'
90  kTypeMessage = 'message'
91  # MFnData.kPlugin is deliberately ignored in the API so skip it
92  kGenericTypes = { 'numeric' : omAPI.MFnData.kNumeric,
93  'pluginGeometry' : omAPI.MFnData.kPluginGeometry,
94  'string' : omAPI.MFnData.kString,
95  'matrix' : omAPI.MFnData.kMatrix,
96  'stringArray' : omAPI.MFnData.kStringArray,
97  'doubleArray' : omAPI.MFnData.kDoubleArray,
98  'intArray' : omAPI.MFnData.kIntArray,
99  'pointArray' : omAPI.MFnData.kPointArray,
100  'vectorArray' : omAPI.MFnData.kVectorArray,
101  'componentList' : omAPI.MFnData.kComponentList,
102  'mesh' : omAPI.MFnData.kMesh,
103  'lattice' : omAPI.MFnData.kLattice,
104  'nurbsCurve' : omAPI.MFnData.kNurbsCurve,
105  'nurbsSurface' : omAPI.MFnData.kNurbsSurface,
106  'sphere' : omAPI.MFnData.kSphere,
107  'dynArrayAttrs' : omAPI.MFnData.kDynArrayAttrs,
108  'dynSweptGeometry': omAPI.MFnData.kDynSweptGeometry,
109  'subdSurface' : omAPI.MFnData.kSubdSurface,
110  'nObject' : omAPI.MFnData.kNObject,
111  'nId' : omAPI.MFnData.kNId }
112 
113  # List of keywords defining the flag to be set (preceded with "!" to unset
114  # it). The values correspond to the attribute names in the MPy object.
115  #
116  kFlagFunctions = { 'readable' : 'readable',
117  'writable' : 'writable',
118  'canconnectassrc' : 'readable',
119  'canconnectasdst' : 'writable',
120  'connectable' : 'connectable',
121  'storable' : 'storable',
122  'cached' : 'cached',
123  'array' : 'array',
124  'indexmatters' : 'indexMatters',
125  'keyable' : 'keyable',
126  'channelbox' : 'channelBox',
127  'hidden' : 'hidden',
128  'usedascolor' : 'usedAsColor',
129  'indeterminant' : 'indeterminant',
130  'rendersource' : 'renderSource',
131  'worldspace' : 'worldSpace',
132  'affectsworldspace' : 'affectsWorldSpace',
133  'usedasfilename' : 'usedAsFilename',
134  'affectsappearance' : 'affectsAppearance',
135  'usesarraydatabuilder' : 'usesArrayDataBuilder',
136  'internal' : 'internal' }
137 
138  # The list of legal disconnect behavior types (see MFnAttribute
139  # documentation for what they mean.
140  #
141  kDisconnectBehaviors = { 'delete' : omAPI.MFnAttribute.kDelete,
142  'reset' : omAPI.MFnAttribute.kReset,
143  'nothing' : omAPI.MFnAttribute.kNothing }
144 
145 #-
146 # ==========================================================================
147 # Copyright (C) 2011 Autodesk, Inc. and/or its licensors. All
148 # rights reserved.
149 #
150 # The coded instructions, statements, computer programs, and/or related
151 # material (collectively the "Data") in these files contain unpublished
152 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
153 # licensors, which is protected by U.S. and Canadian federal copyright
154 # law and by international treaties.
155 #
156 # The Data is provided for use exclusively by You. You have the right
157 # to use, modify, and incorporate this Data into other products for
158 # purposes authorized by the Autodesk software license agreement,
159 # without fee.
160 #
161 # The copyright notices in the Software and this entire statement,
162 # including the above license grant, this restriction and the
163 # following disclaimer, must be included in all copies of the
164 # Software, in whole or in part, and all derivative works of
165 # the Software, unless such copies or derivative works are solely
166 # in the form of machine-executable object code generated by a
167 # source language processor.
168 #
169 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
170 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
171 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
172 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
173 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
174 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
175 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
176 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
177 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
178 # OR PROBABILITY OF SUCH DAMAGES.
179 #
180 # ==========================================================================
181 #+
182