Skip to content

Instantly share code, notes, and snippets.

@tcrowson
tcrowson / loadUI_example.py
Last active April 12, 2023 17:55
Dynamically Load UI file from QtDesigner
from PySide.QtGui import *
from PySide.QtCore import *
from PySide.QtUiTools import QUiLoader
uiFile = "path\to\my\UI\file.ui"
class UiLoader(QUiLoader):
'''
Convenience class for dynamically loading QtDesigner '.ui' files,
@tcrowson
tcrowson / softimage_GatherFramebuffers.py
Last active April 14, 2021 18:31
For Softimage. Searches for 'Store_Color_In_Channel' nodes and adds their channels to the scene channel list.
# loop through shader nodes in the scene, identify 'store_color_in_channel' nodes,
# and add them to the scene globals. Avoid duplicate channnels.
for x in Application.FindObjects("", "{6495C5C1-FD18-474E-9703-AEA66631F7A7}" ):
if str(x.ProgID) == "Softimage.sib_color_storeinchannel.1.0":
chanName = Application.GetValue(x.Channel)
addChan = Application.CreateRenderChannel("%s"%(chanName), "siRenderChannelColorType", "")
newChan = (addChan[-1])
if newChan.isdigit():
Application.RemoveRenderChannel(addChan)
@tcrowson
tcrowson / softimage_RunAnnotationAsPython.py
Last active April 14, 2021 18:29
For Softimage. A quick snippet for running the text in an Annotation property as Python code. This allows you to store Python code in an Annotation property, as part of a scene or model, and run in later. Running this will drop you into a pick session, asking you to choose an Annotation property. No special error handling for now, it's brute-for…
# Puts the user into a pick-session, asking you to select an Annotation property
# whose text it will then run as Python code.
from win32com.client import constants
annotation = Application.PickElement(constants.siPropertyFilter,'Choose an Annotation Property','Choose an Annotation Property')[2]
exec annotation.Text.Value
@tcrowson
tcrowson / qt_ClearTreeWidget.py
Last active October 17, 2020 18:51
For PyQt/PySide. A simple function for clearing the contents of a QTreeWidget/QTreeView, since these classes lack convenient clear() or clearContents() methods. Takes a QTreeWidget or QTreeView object as an argument.
import PySide
from PySide import QtGui
def clearQTreeWidget(tree):
iterator = QtGui.QTreeWidgetItemIterator(tree, QtGui.QTreeWidgetItemIterator.All)
while iterator.value():
iterator.value().takeChildren()
iterator +=1
i = tree.topLevelItemCount()
while i > -1:
@tcrowson
tcrowson / modo_SaveIncremental.py
Last active November 13, 2018 12:20
Increment the version number of the current Modo scene, respecting existing digit padding.
#python
# tc_SaveIncremental.py
# Tim Crowson, 9/29/2014
# Saves a new version of your current scene. Requires the scene to have been saved previously.
# - Searches for an existing version that follows the pattern 'sceneName_vXXX.lxo'
# - Any number of digits can be used for the version number: the script will respect the existing number padding.
# - If no version is identified (e.g. "sceneName.lxo") the script will append '_v001' to end of the scene name.
# - You can configure the padding for this First Version by setting the FIRST_VERSION_PADDING variable
@tcrowson
tcrowson / morphToMesh.py
Last active April 11, 2018 20:56
Modo 901 command for freezing a morph to a new mesh.
# Command for freezing a morph to a new mesh.
# 1. Select a morph map
# 2. run morph.freezeToMesh
# 3. A new mesh bearing the name of the morph map will be created, with the frozen morph shape in it.
import lx
import lxu
import lxifc
import modo
@tcrowson
tcrowson / pysideDialogExamples.py
Last active October 11, 2017 16:49
Examples of simple PySide dialogs
from PySide.QtGui import *
# create a modal message box with a single 'Ok' button
box = QMessageBox()
box.setWindowTitle('Title')
box.setText('Text')
box.exec_()
# create a modal message box that offers some choices (Yes|No|Cancel)
@tcrowson
tcrowson / softimage_DisableViewportVertColor.py
Last active January 2, 2016 08:09
For Softimage. Set the 'Vertex Color' display option to 'Never Show' for all cameras and 3d viewports (lights excluded). This can be very useful when working with normal maps, due to the crazy performance hit from Tangent properties.
from win32com.client import constants
for camera in [cam for cam in Application.ActiveSceneRoot.FindChildren2("", constants.siCameraPrimType)]:
Application.SetValue("%s.camdisp.vcdisplay" %camera, 0)
for viewport in Application.Desktop.ActiveLayout.Views.Find("View Manager").Views:
Application.SetValue("Views.View%s.UserCamera.camdisp.vcdisplay" %viewport, 0)
Application.SetValue("Views.View%s.TopCamera.camdisp.vcdisplay" %viewport, 0)
Application.SetValue("Views.View%s.FrontCamera.camdisp.vcdisplay" %viewport, 0)
Application.SetValue("Views.View%s.RightCamera.camdisp.vcdisplay" %viewport, 0)
@tcrowson
tcrowson / softimage_GroupMeshesByModel.py
Last active January 2, 2016 07:59
For Softimage. This script gathers all the polymeshes for selected models and places them in model-specific groups.
# Gathers all the polymeshes for selected models and places them in model-specific groups
# (i.e. one group for each model).
from win32com.client import constants
if len(Application.Selection) > 0:
selectedModels = [item for item in Application.Selection if item.Type == '#model']
# Create the groups and populate them
for model in selectedModels:
@tcrowson
tcrowson / GroupMeshesByModel.py
Created November 10, 2015 21:15
Softimage - For selected model nulls, finds renderable items and groups them according to their source models.
# Group Meshes By Model
# DESCRIPTION
# - Adds a new command, GroupMeshesByModel(), which can be called from a key assignment or shelf button.
# - For selected model nulls, finds renderable items and groups them according to their source models.
# - Groups the following: meshes, pointclouds, instances, and hair.
# INSTALLATION
# This is a self-installing plugin, so place it in your user scripts
# or similar folder in the workgroup of your choosing.