scripted/modules/pyJsonAttrPatternInfo.py

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