ICE kinematics


Sticking an ICE tree on a mesh and then getting the kine.global, updating it, and setting the kine.global doesn’t really work. And I’m not sure it should. Between ICE optimizations and the way the XSI evaluation model works, I don’t think you’ll get consistent updates. SCOPs are similar, but they have that Always Evaluate flag to force evaluations.

Second attempt. I also have an ICE Tree in the Modeling region that initializes self.tmp.

Switching material libraries


Here’s how to switch from one material library to another. This script could be useful when you have a corrupted material library (eg missing render tree connections), but you have a backup copy of the material library. For example, you could export a good version of the material library from a backup copy of the scene, and then import the matlib into the current version of the scene.


// Material Library with bad render trees (missing connections)
var oMatLib = Dictionary.GetObject( "Sources.Materials.DefaultLib" );

// Material Library with good render trees
var oMatLib1 = Dictionary.GetObject( "Sources.Materials.DefaultLib1" );


oEnum = new Enumerator( oMatLib.Items ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
        var oMat = oEnum.item() ;
        if ( oMat.UsedBy.Count > 0 )
        {
                var oMat1 = oMatLib1.Items(oMat.Name);
                if ( oMat1 == null )
                {
                        LogMessage( "Cannot find " + oMat.Name + " in " + oMatLib1.Name );
                }
                else
                {
                        LogMessage( "Repacing " + oMat.FullName + " with " + oMat1.FullName );
                        
                        // Groups
                        var g = oMat.Owners.Filter( "#Group" );
                        SIAssignMaterial( g.GetAsText(), oMat1 );

                        // Objects
                        SIAssignMaterial( oMat.UsedBy.GetAsText(), oMat1 );
                }
        }

}

Looping through all materials and material libraries


Here’s a snippet that shows how to loop through all material libraries and materials and delete unconnected shaders:

var oMatLibs = ActiveProject.ActiveScene.MaterialLibraries;
oEnum = new Enumerator( oMatLibs ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
{
	var oMatLib = oEnum.item() ;
	oEnum1 = new Enumerator( oMatLib.Items ) ;
	for (;!oEnum1.atEnd();oEnum1.moveNext() )
	{
		var oMat = oEnum1.item() ;
		DeleteUnusedShaders( oMat );
	}

}

The same thing but in Python.

oMatLibs = Application.ActiveProject.ActiveScene.MaterialLibraries
for lib in oMatLibs:
	for mat in lib.Items:
		Application.DeleteUnusedShaders( mat )

Putting the history log on top of the script editor


Commenter mindFreeArtists asks

Is there is a possibility to swap script editor window and history log window so that i have history log at the top of script editor like in previous versions?

Sure, but you can’t do it all through the UI. The Script History view is not listed by the relational view editor, so you have to create a view and then hand edit the .xsivw file. Here’s the .xsivw that goes with the screenshot in this post. Note the <frame name="log" type="Script History" part: that’s what adds the script history log.

<?xml version="1.0" encoding="iso-8859-1"?>
<xsi_file type="RelationalView" xsi_version="9.5.172.0" syntax_version="1.1">
	<relationalview clsid="{E968166E-F924-46F4-AD4D-452EEB963F84}" name="My View" height="521" width="479">
		<definition maxinstances="10000" acceptfocus="true" private="false" defaultsize="100,100,500,500" cmdmap="{00000000-0000-0000-0000-000000000000}" supportedtypes="6" category=""> </definition>
		<relations>
		</relations>
		<frameset orientation="vertical" name="Frameset1" buttonsize="80,30" splitter="movable" sizechild="200,*">
			<frame name="log" type="Script History" primary="true" toolbar="own"> </frame>
			<frame name="pane2" type="Text Editor" primary="false" toolbar="own"> </frame>
		</frameset>
	</relationalview>
</xsi_file>