-
Notifications
You must be signed in to change notification settings - Fork 4
/
QExportSolver.py
604 lines (506 loc) · 24.1 KB
/
QExportSolver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
import xml.etree.ElementTree as ET
import maya.cmds as cmds
import math
import os
from pymel.all import *
import pymel.core.datatypes as dt
#
#
#
# Quaternion to Euler Angle converter. This is mainly used for the importer
#
def QtoE(qx,qy,qz,qw):
x = float(qx)
y = float(qy)
z = float(qz)
w = float(qw)
t0 = +2.0 * (w * x + y * z)
t1 = +1.0 - 2.0 * (x * x + y * y)
X = math.degrees(math.atan2(t0, t1))
t2 = +2.0 * (w * y - z * x)
t2 = +1.0 if t2 > +1.0 else t2
t2 = -1.0 if t2 < -1.0 else t2
Y = math.degrees(math.asin(t2))
t3 = +2.0 * (w * z + x * y)
t4 = +1.0 - 2.0 * (y * y + z * z)
Z = math.degrees(math.atan2(t3, t4))
return X, Y, Z
#
# Euler Angles to Quaternion converter.
#
def EtoQ(yaw, pitch, roll):
qx = math.sin(roll/2) * math.cos(pitch/2) * math.cos(yaw/2) - math.cos(roll/2) * math.sin(pitch/2) * math.sin(yaw/2)
qy = math.cos(roll/2) * math.sin(pitch/2) * math.cos(yaw/2) + math.sin(roll/2) * math.cos(pitch/2) * math.sin(yaw/2)
qz = math.cos(roll/2) * math.cos(pitch/2) * math.sin(yaw/2) - math.sin(roll/2) * math.sin(pitch/2) * math.cos(yaw/2)
qw = math.cos(roll/2) * math.cos(pitch/2) * math.cos(yaw/2) + math.sin(roll/2) * math.sin(pitch/2) * math.sin(yaw/2)
return [qx, qy, qz, qw]
# For indenting to make the printout pretty
# four spaces per level.
#
def Spaces(level):
r = ""
for i in range(0,level):
r = r + " "
return r
################################################################
#
# Class QExportSolver
#
# Handles the traversal of a Maya scene with solver information
# and exports it to an XML file or string.
#
################################################################
class QExportSolver:
def __init__(self):
self._sceneScale = 1.0
self._rootScale = 1.0
self._fd = None
self._sXML = u""
self._NS = u":"
self._MPNS = self._NS+u"ModelPose:"
def _SetNamespace(self, namespace):
self._NS = namespace+u":"
self._MPNS = self._NS+u"ModelPose:"
print ("Namespace = ", self._NS)
print ("Model Pose Namespace = ", self._MPNS)
# SetSceneScale()
#
# Calculate the conversion factor for converting the current scene units into mm, which QTM requires.
# [mm | millimeter | cm | centimeter | m | meter | km | kilometer | in | inch | ft | foot | yd | yard | mi | mile]
# Also grab the skeleton scale from the root node
#
def SetSceneScale(self):
cu = cmds.currentUnit( query=True, linear=True )
if cu == "cm":
self._sceneScale = 10.0
elif cu == "mm":
self._sceneScale = 1.0
elif cu == "m":
self._sceneScale = 1000.0
elif cu == "m":
self._sceneScale = 1000000.0
elif cu == "ft":
self._sceneScale = 304.8
elif cu == "yd":
self._sceneScale = 914.4
elif cu == "mi":
self._sceneScale = 1609300.0
else:
self._sceneScale = 1.0
# Sanity check passed, so this will work
rootNode = cmds.ls(selection=True)
rootNodeName = str(rootNode[0])
self._rootScale = cmds.getAttr("%s.scaleX" % rootNodeName)
print ("Scene Scale before" , self._sceneScale)
print ("Root Scale " , self._rootScale)
self._sceneScale = self._sceneScale * self._rootScale
print ("Scene Scale after" , self._sceneScale)
def _Write(self, s):
if self._fd is not None:
self._fd.write(s)
#self._fd.write(os.linesep)
self._fd.write(u"\n")
else:
self._sXML = self._sXML + s + u"\n"
# Hardcode use of "Markers" for now. This is used to find the list
# of marker names and scan
# the attributes of the joint for one whose name matches the marker.
#
# Note that this has problems if a joint happens to have the same name
# as a marker because then the marker name contains
# the full path name which is not part of the attribute name
#
# Return True if markers were found. False otherwise.
def _ExportMarkers(self, node, level):
bHasMarkers = False
nodeName = str(node)
markersNode = general.PyNode(self._NS+'Markers')
markers = listRelatives(markersNode,c=True)
for m in markers:
#remove namespaces and leave just the marker name
markerName = str(m).split(":")[-1]
a = nodeName+"."+markerName
#print a
if cmds.attributeQuery(markerName,node=nodeName, exists=True):
weight = str(cmds.getAttr(a))
if not bHasMarkers :
bHasMarkers = True
self._Write( Spaces(level)+"<Markers>")
# Get marker position relative to the segment
cn = xform( self._NS+markerName, q=True, matrix=True, ws=True)
pn = xform( nodeName, q=True, matrix=True, ws=True)
cm = dt.Matrix(cn)
pm = dt.Matrix(pn)
om = cm * pm.inverse()
px = str(om[3][0] * self._sceneScale)
py = str(om[3][1] * self._sceneScale)
pz = str(om[3][2] * self._sceneScale)
self._Write( Spaces(level+1)+"<Marker Name=\"" + markerName + "\">")
self._Write( Spaces(level+2)+"<Position X=\"" + px + "\" Y=\"" + py + "\" Z=\"" + pz + "\"/>")
self._Write( Spaces(level+2)+"<Weight>" + str(weight) + "</Weight>")
self._Write( Spaces(level+1)+"</Marker>" )
if bHasMarkers:
self._Write( Spaces(level)+"</Markers>")
return True
else:
return False
#
# ExportTransform
#
# Calculates the transform. Local attributes are used
# so this is relative to the parent.
# The "DefaultTransform" comes from the Maya joint "Preferred Angle"
# definition. In Maya thi is used for IK calculations,
# but we'll use it for the Default Transform which should be the value that puts the joint in a "T Pose".
# Usually this will be a zero rotation, but sometimes not....
#
def _ExportTransform(self, item, level):
# Do the math first, get the local transform
px = str(cmds.getAttr("%s.translateX" % item) * self._sceneScale)
py = str(cmds.getAttr("%s.translateY" % item) * self._sceneScale)
pz = str(cmds.getAttr("%s.translateZ" % item) * self._sceneScale)
rx = math.radians(cmds.getAttr("%s.rotateX" % item))
ry = math.radians(cmds.getAttr("%s.rotateY" % item))
rz = math.radians(cmds.getAttr("%s.rotateZ" % item))
Q = EtoQ(rz,ry,rx)
qx = str(Q[0])
qy = str(Q[1])
qz = str(Q[2])
qw = str(Q[3])
# Get the default transform from the Preferred Angle of the joint
pax = math.radians(getAttr("%s.preferredAngleX" % item))
pay = math.radians(getAttr("%s.preferredAngleY" % item))
paz = math.radians(getAttr("%s.preferredAngleZ" % item))
Q = EtoQ(paz,pay,pax)
paqx = str(Q[0])
paqy = str(Q[1])
paqz = str(Q[2])
paqw = str(Q[3])
#print "T =", rx, ry, rz
#print "DT = ", pax, pay, paz
# Write out both
self._Write( Spaces(level)+"<Transform>")
self._Write( Spaces(level+1)+"<Position X=\"" + px + "\" Y=\""+ py + "\" Z=\"" + pz + "\"/>")
self._Write( Spaces(level+1)+"<Rotation X=\"" + qx + "\" Y=\""+ qy + "\" Z=\"" + qz +"\" W=\"" + qw + "\"/>")
self._Write( Spaces(level)+"</Transform>")
self._Write( Spaces(level)+"<DefaultTransform>")
self._Write( Spaces(level+1)+"<Position X=\"" + px + "\" Y=\""+ py + "\" Z=\"" + pz + "\"/>")
self._Write( Spaces(level+1)+"<Rotation X=\"" + paqx + "\" Y=\""+ paqy + "\" Z=\"" + paqz +"\" W=\"" + paqw + "\"/>")
self._Write( Spaces(level)+"</DefaultTransform>")
# Assume it's a leaf node until a grandchild is found
def _IsLeaf(self, jointNode):
bIs = True
children = cmds.listRelatives(jointNode,c=True)
if children:
for c in children:
grandChildren = cmds.listRelatives(c,c=True)
if grandChildren :
bIs = False
return bIs
# ExportDOFs
#
# Inspect the attributes and if the ones for DOFs are there then use them to write out the dofs
def _ExportDOFs(self, jointNode, level):
nodeName = str(jointNode)
bHasAttributes = cmds.attributeQuery("XRotDoF",node=nodeName, exists=True)
self._Write( Spaces(level+1)+"<DegreesOfFreedom>")
if bHasAttributes:
# Assume one attribute means they're all there.
bRX = cmds.getAttr("%s.XRotDoF" % nodeName)
bRY = cmds.getAttr("%s.YRotDoF" % nodeName)
bRZ = cmds.getAttr("%s.ZRotDoF" % nodeName)
bTX = cmds.getAttr("%s.XTransDoF" % nodeName)
bTY = cmds.getAttr("%s.YTransDoF" % nodeName)
bTZ = cmds.getAttr("%s.ZTransDoF" % nodeName)
if bRX:
lb = math.radians(cmds.getAttr("%s.XRotDoF_LowerBound" % nodeName))
ub = math.radians(cmds.getAttr("%s.XRotDoF_UpperBound" % nodeName))
self._Write( Spaces(level+2)+"<RotationX>")
self._Write( Spaces(level+3)+"<Constraint LowerBound=\""+str(lb)+"\" UpperBound=\""+str(ub)+"\"/>")
# Check for coupling definition
bHasCoupling1 = cmds.attributeQuery("XRot_CP1_Coeff",node=nodeName, exists=True)
bHasCoupling2 = cmds.attributeQuery("XRot_CP2_Coeff",node=nodeName, exists=True)
if bHasCoupling1:
bCP1_coeff = cmds.getAttr("%s.XRot_CP1_Coeff"% nodeName)
bCP1_segment = cmds.getAttr("%s.XRot_CP1_Segment"% nodeName)
if bHasCoupling2:
bCP2_coeff = cmds.getAttr("%s.XRot_CP2_Coeff"% nodeName)
bCP2_segment = cmds.getAttr("%s.XRot_CP2_Segment"% nodeName)
if bHasCoupling1:
self._Write( Spaces(level+3) + "<Couplings>")
self._Write( Spaces(level+4)+ "<Coupling Coefficient=\""+str(bCP1_coeff)+"\" DegreeOfFreedom=\"RotationX\" Segment=\""+ bCP1_segment+"\"/>")
if bHasCoupling2:
self._Write( Spaces(level+4)+ "<Coupling Coefficient=\""+str(bCP2_coeff)+"\" DegreeOfFreedom=\"RotationX\" Segment=\""+ bCP2_segment+"\"/>")
self._Write( Spaces(level+3) + "</Couplings>")
self._Write( Spaces(level+2)+"</RotationX>")
if bRY:
lb = math.radians(cmds.getAttr("%s.YRotDoF_LowerBound" % nodeName))
ub = math.radians(cmds.getAttr("%s.YRotDoF_UpperBound" % nodeName))
self._Write( Spaces(level+2)+"<RotationY>")
self._Write( Spaces(level+3)+"<Constraint LowerBound=\""+str(lb)+"\" UpperBound=\""+str(ub)+"\"/>")
# Check for coupling definition
bHasCoupling1 = cmds.attributeQuery("YRot_CP1_Coeff",node=nodeName, exists=True)
bHasCoupling2 = cmds.attributeQuery("YRot_CP2_Coeff",node=nodeName, exists=True)
if bHasCoupling1:
bCP1_coeff = cmds.getAttr("%s.YRot_CP1_Coeff"% nodeName)
bCP1_segment = cmds.getAttr("%s.YRot_CP1_Segment"% nodeName)
if bHasCoupling2:
bCP2_coeff = cmds.getAttr("%s.YRot_CP2_Coeff"% nodeName)
bCP2_segment = cmds.getAttr("%s.YRot_CP2_Segment"% nodeName)
if bHasCoupling1:
self._Write( Spaces(level+3) + "<Couplings>")
self._Write( Spaces(level+4)+ "<Coupling Coefficient=\""+str(bCP1_coeff)+"\" DegreeOfFreedom=\"RotationY\" Segment=\""+ bCP1_segment+"\"/>")
if bHasCoupling2:
self._Write( Spaces(level+4)+ "<Coupling Coefficient=\""+str(bCP2_coeff)+"\" DegreeOfFreedom=\"RotationY\" Segment=\""+ bCP2_segment+"\"/>")
self._Write( Spaces(level+3) + "</Couplings>")
self._Write( Spaces(level+2)+"</RotationY>")
if bRZ:
lb = math.radians(cmds.getAttr("%s.ZRotDoF_LowerBound" % nodeName))
ub = math.radians(cmds.getAttr("%s.ZRotDoF_UpperBound" % nodeName))
self._Write( Spaces(level+2)+"<RotationZ>")
self._Write( Spaces(level+3)+"<Constraint LowerBound=\""+str(lb)+"\" UpperBound=\""+str(ub)+"\"/>")
# Check for coupling definition
bHasCoupling1 = cmds.attributeQuery("ZRot_CP1_Coeff",node=nodeName, exists=True)
bHasCoupling2 = cmds.attributeQuery("ZRot_CP2_Coeff",node=nodeName, exists=True)
if bHasCoupling1:
bCP1_coeff = cmds.getAttr("%s.ZRot_CP1_Coeff"% nodeName)
bCP1_segment = cmds.getAttr("%s.ZRot_CP1_Segment"% nodeName)
if bHasCoupling2:
bCP2_coeff = cmds.getAttr("%s.ZRot_CP2_Coeff"% nodeName)
bCP2_segment = cmds.getAttr("%s.ZRot_CP2_Segment"% nodeName)
if bHasCoupling1:
self._Write( Spaces(level+3) + "<Couplings>")
self._Write( Spaces(level+4)+ "<Coupling Coefficient=\""+str(bCP1_coeff)+"\" DegreeOfFreedom=\"RotationZ\" Segment=\""+ bCP1_segment+"\"/>")
if bHasCoupling2:
self._Write( Spaces(level+4)+ "<Coupling Coefficient=\""+str(bCP2_coeff)+"\" DegreeOfFreedom=\"RotationZ\" Segment=\""+ bCP2_segment+"\"/>")
self._Write( Spaces(level+3) + "</Couplings>")
self._Write( Spaces(level+2)+"</RotationZ>")
if bTX:
self._Write( Spaces(level+2)+"<TranslationX/>")
if bTY:
self._Write( Spaces(level+2)+"<TranslationY/>")
if bTZ:
self._Write( Spaces(level+2)+"<TranslationZ/>")
self._Write( Spaces(level+1)+"</DegreesOfFreedom>")
# very similar to ExportRootJoint, except no translation DoFs and have to check for end point
def _ExportJoint(self, jointNode, level):
bLeaf = False
segmentName = str(jointNode).split(":")[-1]
self._Write( Spaces(level)+"<Segment Name=\"" + segmentName + "\">")
children = cmds.listRelatives(jointNode,c=True)
if not children:
#print "Shouldn't get here!!", jointNode
bLeaf = True
end_px = str(0)
end_py = str(0)
end_pz = str(1 * self._sceneScale)
elif self._IsLeaf(jointNode):
bLeaf = True
endNode = children[0]
end_px = str(cmds.getAttr("%s.translateX" % endNode) * self._sceneScale)
end_py = str(cmds.getAttr("%s.translateY" % endNode) * self._sceneScale)
end_pz = str(cmds.getAttr("%s.translateZ" % endNode) * self._sceneScale)
# Check for solver root
bHasSolver = cmds.attributeQuery("Solver",node=str(jointNode), exists=True)
if bHasSolver :
self._Write( Spaces(level+1) +"<Solver> Global Optimization </Solver>")
self._ExportTransform(jointNode,level+1)
# Hardcode Dofs for now, root has translation and rotation
self._ExportDOFs(jointNode, level)
if bLeaf:
self._Write( Spaces(level+1)+"<Endpoint X=\"" + end_px + "\" Y=\""+ end_py + "\" Z=\"" + end_pz + "\"/>")
self._ExportMarkers(jointNode,level+1)
self._Write( Spaces(level+1)+"<RigidBodies/>")
if not bLeaf:
# Export children, again assume that children exist
if children :
for c in children:
self._ExportJoint(c, level+1)
self._Write( Spaces(level)+"</Segment>")
# ExportRootJoint
#
# Special joint, assume it's a "Global" joint with 6 DoFs.
#
def _ExportRootJoint(self, rootNode, level):
bIsProp = False
segmentName = str(rootNode).split(":")[-1]
self._Write( Spaces(level)+"<Segment Name=\"" + segmentName + "\">")
self._ExportTransform(rootNode,level+1)
# Hardcode Dofs for now, root has translation and rotation
self._Write( Spaces(level+1)+"<DegreesOfFreedom>")
self._Write( Spaces(level+2)+"<RotationX/>")
self._Write( Spaces(level+2)+"<RotationY/>")
self._Write( Spaces(level+2)+"<RotationZ/>")
self._Write( Spaces(level+2)+"<TranslationX/>")
self._Write( Spaces(level+2)+"<TranslationY/>")
self._Write( Spaces(level+2)+"<TranslationZ/>")
self._Write( Spaces(level+1)+"</DegreesOfFreedom>")
bIsProp = self._IsLeaf(rootNode)
if bIsProp:
children = cmds.listRelatives(rootNode,c=True)
if not children:
end_px = str(0)
end_py = str(0)
end_pz = str(1 * self._sceneScale)
else:
endNode = children[0]
end_px = str(cmds.getAttr("%s.translateX" % endNode) * self._sceneScale)
end_py = str(cmds.getAttr("%s.translateY" % endNode) * self._sceneScale)
end_pz = str(cmds.getAttr("%s.translateZ" % endNode) * self._sceneScale)
self._Write( Spaces(level+1)+"<Endpoint X=\"" + end_px + "\" Y=\""+ end_py + "\" Z=\"" + end_pz + "\"/>")
else:
self._Write( Spaces(level+1)+"<Endpoint/>")
#Markers
self._ExportMarkers(rootNode,level+1)
self._Write( Spaces(level+1)+"<RigidBodies/>")
if not bIsProp:
# Export children, again assume that children exist
children = cmds.listRelatives(rootNode,c=True)
for c in children:
self._ExportJoint(c, level+1)
#close section and return
self._Write( Spaces(level)+"</Segment>")
#
# ExportSkeleton
#
# Use the topmost group node for the name of the skeleton. This name MUST match the markerset prefix for
# trajectory labels in QTM. For example, "MG" to match "MG_FrontLWaist" in QTM. The matching marker name in
# this scene would be "FrontLWaist".
#
# Then export the joint hierarchy
#
def _ExportSkeleton(self):
# Get root joint, it's been previously verified that it is the currently selected node
nodes = cmds.ls(selection=True)
rootNode = nodes[0]
namespace = str(rootNode).rpartition(":")[0]
namespace_base = cmds.namespaceInfo(namespace,baseName=True)
skeletonName = cmds.namespaceInfo(namespace,parent=True)
self._SetNamespace(skeletonName)
# SanityCheck() guarantees this will work
m = cmds.ls(skeletonName+":Markers")
markers = m[0]
self._Write( Spaces(1)+"<Skeleton Name=\"" + skeletonName + "\">")
self._Write( Spaces(2)+"<Solver>Global Optimization</Solver>")
self._Write( Spaces(2)+"<Scale>" + str(self._rootScale)+"</Scale>")
self._Write( Spaces(2)+"<Segments>")
self._ExportRootJoint(rootNode, 3)
self._Write( Spaces(2)+"</Segments>")
self._Write( Spaces(1)+"</Skeleton>")
#
# ExportQTMSkeletonFile
#
# Top most function for exporting a QTM Skeleton XML file.
# This is done recursively to handle the joint hierarchy.
# Each section has its own function call to export the section.
#
# if fd is None then assume we're writing a string for passing
# back to QTM
#
def ExportQTMSkeletonFile(self,fd):
self._fd = fd
self._sXML = u""
if self._fd is None:
self._Write(" <Skeletons>")
else:
self._Write("<QTM_Skeleton_File>")
self._ExportSkeleton()
if self._fd is None:
self._Write(" </Skeletons>")
else:
self._Write("</QTM_Skeleton_File>")
return self._sXML
################################################################
#
# End of QExportSolver class definition
#
################################################################
#
# FindNotJointParent
#
# Finds the first non-joint parent in the hierarchy of the given joint
# This is meant to find the "Name" group node at the top of the hierarchy that must match
# the parent of the "Markers" node that holds all the markers
#
# NO LONGER USED - Not required for use with namespaces
def FindNotJointParent(me):
t = cmds.nodeType(str(me))
#print me, "is", t
if t != "joint":
return me
else:
myParent = listRelatives(me, parent=True)
if len(myParent) > 0 :
mp = myParent[0]
#print "Parent is", mp
return FindNotJointParent(mp)
else:
return me
#
# Series of sanity checks to make sure the user picks one and only one
# root joint
#
# Also need to verify namespace construction
#
def SanityCheck():
bPassedTests = True
namespace = u""
sel = cmds.ls(selection=True)
if len(sel) == 0:
#print "Nothing was selected"
cmds.confirmDialog(title="No Root",message="Please select the root joint to export",button=["OK"], defaultButton="OK")
bPassedTests = False
else:
if len(sel) > 1:
cmds.confirmDialog(title="Only One", message="Please select only one joint",button=["OK"], defaultButton="OK")
bPassedTests = False
else:
# now the number of selections == 1, this is what we require
rootJoint = sel[0]
t = cmds.nodeType(str(rootJoint))
if t != "joint":
cmds.confirmDialog(title="Not a Joint", message="Please select a joint",button=["OK"], defaultButton="OK")
bPassedTests = False
else:
namespace = str(rootJoint).rpartition(":")[0]
namespace_base = cmds.namespaceInfo(namespace,baseName=True)
if namespace_base != "ModelPose":
cmds.confirmDialog(title="Namespace ModelPose Error", message="Selected joint must have ModelPose namespace",button=["OK"], defaultButton="OK")
bPassedTests = False
else:
namespace_parent = cmds.namespaceInfo(namespace,parent=True)
namespace_grandparent = cmds.namespaceInfo(namespace_parent,parent=True)
if namespace_grandparent != ":":
cmds.confirmDialog(title="Namespace Parent Name Error", message="Selected joint must have a parent namespace",button=["OK"], defaultButton="OK")
bPassedTests = False
else:
#print "Markers Node is", namespace_parent+":Markers"
m = cmds.ls(namespace_parent+":Markers")
if len(m) == 0:
cmds.confirmDialog(title="No Markers", message="Markers node was not found in same namespace",button=["OK"], defaultButton="OK")
bPassedTests = False
else:
markers = m[0]
print ("Found", markers, cmds.nodeType(markers))
parents = cmds.listRelatives(markers,parent=True)
return bPassedTests
#
# Drag this function to the tool bar for easy access, it should look like this:
# import QExportSolver
# reload(QExportSolver)
# QExportSolver.ExportQTMSkeleton()
#
def ExportQTMSkeleton():
# make sure the user has selected a joint and that the scene has the right construction
bOK = SanityCheck()
if bOK == True:
fPath = cmds.fileDialog2(fileFilter="QTM Skeleton (*.xml)",caption="Save QTM Skeleton File", fm=0)
if fPath is not None:
fName = fPath[0]
QES = QExportSolver()
QES.SetSceneScale()
#fd = os.open(fName , os.O_RDWR|os.O_CREAT )
fd = open(fName , 'w' )
QES.ExportQTMSkeletonFile(fd)
fd.close()
print ("Wrote", fName)