Python: First Baby Steps

There's growing interest from those who are technically minded to learn Python and use it for scripting in Softimage. In the interest of helping others considering the switch, here are a few basic examples.

Start with the Basics of a Simple Loop

   
a = Application
for i in range(1,10):
		a.logmessage(i) 

Next Log an Array

b = [1,34,5,546,43,3]

a = Application

for i in b:
		a.logmessage(i)

Next a simple file UI


a = Application
from win32com.client import constants




fb = XSIUIToolkit.FileBrowser
fb.Filter = "Maya Ascii (*.ma)|*.ma||"
fb.ShowOpen()
a.logmessage(fb.FilePathName);
a.logmessage(fb.FileName);
a.logmessage(fb.FileExtension);
a.logmessage(fb.FilePath);



def getUI():

	sliders = a.ActiveSceneRoot.AddProperty( "CustomProperty", 0, "MA XSI Import" )
	File = sliders.AddParameter3("File", constants.siString, "c:\\",0,1)
	
	layout = sliders.PPGLayout
	layout.Clear()
	
	layout.AddGroup("Path")
	item1 = layout.AddItem ("File", "File", constants.siControlFilePath)
	layout.EndGroup()

	try:
		a.inspectobj( sliders, "", "Maxsi", constants.siModal )
	except:
		a.logmessage("hit cancel")
		a.deleteobj(sliders)
		return
		
		
	fileValue = File.Value
	a.deleteobj(sliders)
	
	return fileValue
	
'''
ui = getUI()

if ui:
	a.logmessage(ui)
	
'''

This page was last modified 17:18, 9 Dec 2010.
This page has been accessed 9349 times.

© Copyright 2009 Autodesk Inc. All Rights Reserved. Privacy Policy | Legal Notices and Trademarks | Report Piracy