XSI Viewport Capture with Python
Had to create a function to capture the viewport today and thought it’d be useful to post it here for others to find.
NOTE: You may need to do the procedure on this page to get this to work properly: http://www.xsi-blog.com/archives/24
See below:
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 | # Python import os xsi = Application log = xsi.LogMessage def ET_ViewportCapture( inWidth, inHeight, inPath, inFileName): # Get current frame oPlayControl = xsi.ActiveProject.Properties.Find("PlayControl") Fc = oPlayControl.Parameters("Current").Value # Get Viewport Object oViewportCapture = xsi.Dictionary.GetObject("ViewportCapture") # Start End Frame set to current frame oViewportCapture.NestedObjects("Start Frame").Value = Fc oViewportCapture.NestedObjects("End Frame").Value = Fc oViewportCapture.NestedObjects("OpenGL Anti-Aliasing").Value = 4 # Set image size oViewportCapture.NestedObjects("Width").Value = inWidth oViewportCapture.NestedObjects("Height").Value = inHeight # Set the output file name oSlash = XSIUtils.Slash oPath = str(xsi.ActiveProject2.Path) + str(inPath) # if os.path.isdir(oPath) == False: os.mkdir(oPath) # Set output file location oViewportCapture.NestedObjects("File Name").Value = inPath + str(inFileName) + ".pic" oViewportCapture.NestedObjects("Padding").Value = "(fn)(ext)" # Set viewport options oConstructionLevel = xsi.Dictionary.GetObject("Views.ViewB.UserCamera.camvis.constructionlevel") oGridAxis = xsi.Dictionary.GetObject("Views.ViewB.UserCamera.camvis.gridaxisvis") oConstructionLevel.Value = 0 oGridAxis.Value = 0 xsi.CaptureViewport(2, 0) ET_ViewportCapture(75,75,"\\Render_Pictures\\","FileName") |