Max_Python_Help DOC 通讀005

max2016不能直接運行py文件(也可能我操作的不對)

python.ExecuteFile fname

簡單粗暴的上馬吧

from PySide import QtGui
import MaxPlus

#這個類有點意(meng)思(bi),據目前看是爲了給下面的窗口做一個引用,防止創建之後直接被垃圾回收。
#窗口都已經show了,爲啥還會被回收。
class _GCProtector(object):
	widgets = []

#這裏也就是個創建一個cylinder的方法
def make_cylinder():
	obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cylinder)
	obj.ParameterBlock.Radius.Value = 10.0
	obj.ParameterBlock.Height.Value = 30.0
 	node = MaxPlus.Factory.CreateNode(obj)
	time = MaxPlus.Core.GetCurrentTime()
	MaxPlus.ViewportManager.RedrawViews(time)

	return

#這裏就是跟在Python裏寫PySide一樣的一個類
class CylinderWin(QtGui.QWidget):
	def __init__(self):
		super(CylinderWin,self).__init__()
		self.initUI()
	
	def initUI(self):
		vb = QtGui.QVBoxLayout()
		label = QtGui.QLabel("Click button to create a cylinder in the scene")
		vb.addWidget(label)
		
		btn = QtGui.QPushButton("Cylinder")
		btn.clicked.connect(make_cylinder)
		vb.addWidget(btn)
		
		self.setLayout(vb)
		
		
		self.setGeometry(500, 500, 250, 150)
		self.setWindowTitle("Cylinder Window")
	
	def closeEvent(self,event):
		print "AAAAAAAAA"
	
	def showEvent(self, event):
		print "show Event"


def main():	
	app = QtGui.QApplication.instance()
	if not app:
		app = QtGui.QApplication([])
	
	MaxPlus.FileManager.Reset(True)

	w = CylinderWin()
	print CylinderWin.__dict__
	_GCProtector.widgets.append(w)
	
	#爲了讓這個窗口一直浮於max主窗口之上,Max2016
	MaxPlus.AttachQWidgetToMax(w)
	w.show()
	
	
if __name__ == '__main__':
	main()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章