PyMaxExplorer/maxDataModels.py

PyMaxExplorer/maxDataModels.py
1 '''
2  Data model for 3ds Max node.
3 '''
4 from pymxs import runtime as rt
5 
6 class mxTreeNode(object):
7  def __init__(self, name ,parent=None):
8  self._name = name
9  self._children = []
10  self._parent = parent
11  if self._parent and self not in self._parent._children :
12  self._parent._children.append(self)
13 
14  def getName(self):
15  return self._name
16 
17  def setName(self, nm):
18  self._name = nm
19 
20  name = property(getName, setName)
21 
22  def mxNode(self):
23  obj = rt.getNodeByName(self._name)
24  return obj
25 
26  def mxType(self):
27  return str(rt.classOf(self._node))
28 
29  def row(self):
30  if self._parent:
31  return self._parent._children.index(self)
32  return 0
33 
34  def parent(self):
35  return self._parent
36 
37  def child(self, indx):
38  if self._children and indx >= 0 and indx < self.numChildren():
39  return self._children[indx]
40  return None
41 
42  def numChildren(self):
43  return len(self._children)
44 
45  def addChild(self, child):
46  self._children.append(child)
47 
48  def insertChild(self, node, pos):
49  if pos >= 0 and pos < self.numChildren():
50  self._children.insert(pos, node)
51  node._parent = self
52  return True
53  return False
54 
55  def popChild(self, pos):
56  if pos >= 0 and pos < self.numChildren():
57  child = self._children.pop(pos)
58  child._parent = None
59  return True
60  return False