Copying the global transform into a 4×4 Matrix ICE node


I saw–via an email notification–the question “how do I use the Global Transform of an object to create a 4×4 Matrix” posted on xsibase (sorry, I don’t go to xsibase anymore because of the “attack site” and “malware” warnings).

One way to do this is to add a “Copy Global Transform” command to the ICE node context menu. After you install this plugin, right click a 4×4 matrix node in an ICE tree, and it will copy the Global Transform from the first object in the selection list.

Note: error checking and stuff like that is left as an exercise for the reader (or for another blog post).

Here’s the plugin code for 2013. For 2012 or earlier, you have to change the AddCallbackItem2 call to AddCallbackItem.

si = Application
import win32com.client
from win32com.client import constants as C

null = None
false = 0
true = 1

def XSILoadPlugin( in_reg ):
	in_reg.Author = "blairs"
	in_reg.Name = "CopyTransfo2MatrixNodePlugin"
	in_reg.Major = 1
	in_reg.Minor = 0

	in_reg.RegisterMenu(C.siMenuICENodeContextID,"CopyTransfo2MatrixNode_Menu",false,false)

	return true

def XSIUnloadPlugin( in_reg ):
	strPluginName = in_reg.Name
	Application.LogMessage(str(strPluginName) + str(" has been unloaded."),C.siVerbose)
	return true

def CopyTransfo2MatrixNode_Init( in_ctxt ):
	oCmd = in_ctxt.Source
	oCmd.Description = ""
	oCmd.ReturnValue = true

	oArgs = oCmd.Arguments
	oArgs.AddWithHandler("Arg0","Collection")
	return true

def CopyTransfo2MatrixNode_Menu_Init( in_ctxt ):
	oMenu = in_ctxt.Source
	oMenu.AddCallbackItem2("Copy Global Transform","CopyTransfo2MatrixNode")
	return true
	
def CopyTransfo2MatrixNode( in_ctxt ):
	oNodeName = in_ctxt.GetAttribute("Target")

	o = si.Selection(0)
	t = o.Kinematics.Global.GetTransform2( None )
	m = t.Matrix4.Get2()

	# Get a matrix node
	n = si.Dictionary.GetObject( oNodeName )
	
	n.Parameters( "value_00" ).Value = m[0]
	n.Parameters( "value_01" ).Value = m[1]
	n.Parameters( "value_02" ).Value = m[2]
	n.Parameters( "value_03" ).Value = m[3]

	n.Parameters( "value_10" ).Value = m[4]
	n.Parameters( "value_11" ).Value = m[5]
	n.Parameters( "value_12" ).Value = m[6]
	n.Parameters( "value_13" ).Value = m[7]

	n.Parameters( "value_20" ).Value = m[8]
	n.Parameters( "value_21" ).Value = m[9]
	n.Parameters( "value_22" ).Value = m[10]
	n.Parameters( "value_23" ).Value = m[11]

	n.Parameters( "value_30" ).Value = m[12]
	n.Parameters( "value_31" ).Value = m[13]
	n.Parameters( "value_32" ).Value = m[14]
	n.Parameters( "value_33" ).Value = m[15]

7 thoughts on “Copying the global transform into a 4×4 Matrix ICE node

  1. Thank you Stephen for writing this for me (I posted question on xsibase). Unfortunately, I’m not sure what to do with it…. I changed script language to Python and pasted in the code and ran it. Did nothing. Saved it as a plugin (“CopyTransfo2MatrixNode.pys”) and tried to load it into plugin manager but received an error: (line 11, in_reg.RegisterMenu……… NameError: global name ‘constants’ is not defined.”

    Any help would be great.

    I really appreciate that you are still posting stuff! I was really shocked to hear you got laid off. Good luck finding new employment!

    • Hi David

      It is a plugin, so you need to save the plugin file in Application\Plugins.

      I missed that “constants” when I did the blog post…it should be changed to “C”.

      You can download the file here; it works in Softimage 2013
      https://dl.dropbox.com/u/12898205/CopyTransfo2MatrixNodePlugin.py

      If you are using 2012 or earlier, I need to adjust the python imports.

      Let me know if you still have problems. And also if it doesn’t do what you want…I whipped it up real quick, so there is definitely room for improvement.

      Thanks!

  2. Hi again. I did successfully get it to load in plugin manager with no errors. Thanks for the updated script; I’m on 2013. Unfortunately, I can’t figure out how to launch it/ what to do with it. I can’t find it anywhere; even tried customizing a toolbar but couldn’t find anything “CopyTransfo2 MatrixNode under the Available Commands.

    In Plugin Manager, it’s listed under my workgroup/Plugins/CopyTransfo2MatrixNodePlugin/CopyTransfo2MatrixNode_Menu (Menu)

    But I can’t find it in any menus….

    Sorry to be such a pain…

    • Hi David

      In the ICE Tree, right click a node, and you will see a “Copy Global Transform” command on the context menu.
      That command will copy the global transform from the first object in the current selection.

      Normally I would have written a more detailed post, but I kinda blasted this one out. Sorry about that…

      ta

      Steve

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s