-
Notifications
You must be signed in to change notification settings - Fork 0
/
nurbLibrary.py
74 lines (56 loc) · 2.01 KB
/
nurbLibrary.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
# function to copy the nurb into library
def storeCVInfo():
nurbList = cmds.ls(selection = True)
nurbInfoList = []
for eachNurb in nurbList:
cvPosList = []
dupNurb = cmds.duplicate(eachNurb)[0]
if cmds.listRelatives(eachNurb, parent = True) != None:
cmds.parent(dupNurb, world = True)
# put it back to 0 position
cmds.setAttr(dupNurb + ".translateX", 0)
cmds.setAttr(dupNurb + ".translateY", 0)
cmds.setAttr(dupNurb + ".translateZ", 0)
cmds.setAttr(dupNurb + ".rotateX", 0)
cmds.setAttr(dupNurb + ".rotateY", 0)
cmds.setAttr(dupNurb + ".rotateZ", 0)
cmds.setAttr(dupNurb + ".scaleX", 0)
cmds.setAttr(dupNurb + ".scaleY", 0)
cmds.setAttr(dupNurb + ".scaleZ", 0)
# read cvs
numCV = cmds.getAttr(dupNurb+".spans")+cmds.getAttr(dupNurb+".degree")
for i in xrange(numCV):
cvName = dupNurb + ".cv[" + str(i) + "]"
rawPos = cmds.xform(cvName, query = True,
worldSpace = True, translation = True)
for j in xrange(3):
rawPos[j] = rawPos[j] * 10**12
cvPosList += [tuple(rawPos)]
nurbInfoList += [cvPosList]
cmds.delete(dupNurb)
return nurbInfoList
def printCVInfo(nurbInfoList, nameList = None):
i = 0
for eachCVList in nurbInfoList:
printedString = ""
# if name list is given, then assign them to variables
if nameList != None:
printedString += (nameList[i] + " = ")
# store information as a list of tuples: (float, float, float)
printedString += "["
for eachCV in eachCVList:
# each printed should be a tuple, printed as (tansX, transY, transZ)
printedString += ("(" + str(eachCV[0]) + ", ")
printedString += (str(eachCV[1]) + ", ")
printedString += (str(eachCV[2]) + "), ")
# get rid of the last 2 chars ", " and add the "]"
printedString = printedString[:-2] + "]"
i += 1
print printedString
def createNurb(posList, degree = 1, name = None):
knotList = range(len(posList))
if name == None:
cmds.curve(point = posList, degree = 1, knot = knotList)
nurbInfoList = storeCVInfo()
printCVInfo(posList, ["circleX"])
createNurb(nurbInfoList[0])