Tips related to script or C++ API control of the XSI FxTree


You can use FxTree commands to draw lines with VectorPaint.

VectorPaint is a state machine. That means you select your brush attributes first, and then add shape points. The lines between points are drawn with the specified brush attributes. You can always change the brush attributes and add more shape points.

The final shape is an object you can see in the scene explorer and can set values on.

The origin of the image coordinate system is the lover-left corner, which is the point (0,0).

The script below draws a line from 10,10 to 100,100 with a smaller brush:

NewScene(null, null);

SetPaintBrush ("Color");

AddFxOp("FxTree", "Vector Paint", null);

// setup to draw lines
SetValue("PaintTool.NewShapeStyle", 0, null);
SetValue("PaintTool.NewShapeClosed", 0, null);
SetValue("PaintTool.Brush.Radius", 5, null);

// add the shape
// AddPaintShapePoint( <shape>, <insert position or -1 for end>, <x>, <y>,
//					<lefthandlex>, <left handley>,
//					<righthandlex>, <righthandley>);

var oColorShape =  AddColorPaintShape("FxTree.VectorPaint.ShapeList", null);
AddPaintShapePoint( oColorShape, -1, 10, 10 );
AddPaintShapePoint( oColorShape, -1, 100, 100 );


Scripting Invert All

The Invert All button inverts the color of all the shapes in the shape list. The shape colors are not exposed in the UI, but you can access them through scripting. For example, this inverts the color. Calling the script again will invert it again

// First, invert the ShapeList color
var ColorValue = GetValue( "FxTree.Tint.sl.GarbageShapes.BackgroundColor.Red" );
SetValue ("FxTree.Tint.sl.GarbageShapes.BackgroundColor.Red", 1 - ColorValue );
SetValue ("FxTree.Tint.sl.GarbageShapes.BackgroundColor.Green ", 1 - ColorValue );
SetValue ("FxTree.Tint.sl.GarbageShapes.BackgroundColor.Blue", 1 - ColorValue );

// Then invert the shape colors
var ColorValue = GetValue( "FxTree.Tint.sl.GarbageShapes.Polygon.Color.Red" );
SetValue ("FxTree.Tint.sl.GarbageShapes.Polygon.Color.Red", 1 - ColorValue );
SetValue ("FxTree.Tint.sl.GarbageShapes.Polygon.Color.Green ", 1 - ColorValue );
SetValue ("FxTree.Tint.sl.GarbageShapes.Polygon.Color.Blue", 1 - ColorValue );

Here's an OM script that loops through the shapes and inverts all the colors:

// Get an FxTree
// See Scripting Tips and Tricks (XSISDK)#FxTrees for more info on getting FxTrees
SelectObj("FxTree", null, null);
var oFxTree = Application.Selection(0);

// Create a collection to hold the shape Color objects
var oColors = new ActiveXObject('XSI.Collection');

// Get the ShapeList color and the shape colors
var sGarbageShapes = oFxTree.FullName + ".Tint.sl.GarbageShapes";
			sGarbageShapes + ".BackgroundColor" + 
			", " +
			sGarbageShapes + ".Shapes.*.Color" 

// Invert the colors
oEnum = new Enumerator( oColors ) ;
for (;!oEnum.atEnd();oEnum.moveNext() )
	var oColor = oEnum.item() ;

	// RGB parameters are hidden, so use NestedObjects
	var nColorValue = oColor.NestedObjects.Item("Red").Value;
	oColor.NestedObjects.Item("Red").Value = 1 - nColorValue;
	oColor.NestedObjects.Item("Green").Value = 1 - nColorValue;
	oColor.NestedObjects.Item("Blue").Value = 1 - nColorValue;

This page was last modified 18:47, 30 Aug 2007.
This page has been accessed 11534 times.

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