Using a Temporary GridData Object

You can create a GridData object to help manage 2-dimensional arrays via the XSIFactory object (the CreateGridData (XSIFactory) method). The XSIFactory object is an intrinsic (global) object that does not need to be instantiated as part of the scene graph, which is convenient for languages such as JScript which does not support 2-dimensional arrays.

Normally it is necessary to convert 2-dimensional arrays to a 1-dimensional array using the VBArray.toArray() method. However, if you transfer the data into a DataGrid object then you can access the data more conveniently; for example, Row by Row or setting values at a precise Row/Column coordinate. This is demonstrated in the following example.

Example: Manipulating ClusterProperties in JScript

ClusterProperties are widely used in scripting and their data is represented as a 2-dimensional array. For example, there is a row for each component and each component has multiple values (such as RGBA or UVW) which are the column values. Even a Weight Map is represented this way, even though there is only 1 value per component.

       /*
           Example of using GridData as a convenient way to deal with
           2D arrays from JScript
       */

       NewScene( null, false );

       // Set up a grid object with only one subdivision in U and V
       var oGrid = ActiveSceneRoot.AddGeometry( "Grid", "MeshSurface" );
       oGrid.subdivu = 1;
       oGrid.subdivv = 1;

       // Add a vertex color support and
       CreateVertexColorSupport( null, null, oGrid );
       SetDisplayMode("Camera", "shaded");

       // Get the new vertex color support as a ClusterProperty object
       var oGeometry = oGrid.ActivePrimitive.Geometry;
       var oClusterProp = oGeometry.Clusters(0).Properties( "Vertex_Color" );

       // Set up a temporary GridData object: this kind of GridData object
       // is created through the instrinsic XSIFactory object (ie., it does
       // not have to be defined via a Parameter on a property set.
       var oGridData = XSIFactory.CreateGridData();

       // Read the vertex color values by transferring them into the GridData.
       // There are 4 Columns - R,G,B, and A and there is 1 Row for each vertex.
       oGridData.Data = oClusterProp.Elements.Array;

       LogMessage( "Blue Component on Vertex 0: " + oGridData.GetCell(2,0) );
       LogMessage( "Red Component on Vertex 2: " + oGridData.GetCell(0,2) );

       // Now we can change the vertex color values
       for ( var i=0; i<oGridData.RowCount; i++ )
       {
           // Set RGBA value on each vertex
           oGridData.SetRowValues( i, Array( i*0.10, 0.50, 0.75, 0.1 ) );
       }

       // We MUST put the changed data back into the cluster property if we
       // want our changes to take effect
       oClusterProp.Elements.Array = oGridData.Data

       // Now we can view the data on a property page by creating a property
       // set and
       var oPSet = ActiveSceneRoot.AddCustomProperty( "ClusterPropContents" );
       var oParam1 = oPSet.AddGridParameter( "ClusterGrid" );

       var oLayout = oPSet.PPGLayout
       var oPPGItem = oLayout.AddItem( "ClusterGrid", "", siControlGrid );
       oPPGItem.SetAttribute( "NoLabel", true );

       //Copy data from our free floating
       //GridData object to the one on the Custom Property
       var oGridDataOnPSet = oParam1.Value;
       oGridDataOnPSet.Data = oGridData.Data;

       // Set up labels so the user knows what the data is
       oGridDataOnPSet.SetColumnLabel( 0, "R" );
       oGridDataOnPSet.SetColumnLabel( 1, "G" );
       oGridDataOnPSet.SetColumnLabel( 2, "B" );
       oGridDataOnPSet.SetColumnLabel( 3, "A" );

       for ( i=0; i<oGridData.RowCount; i++ )
       {
           oGridDataOnPSet.SetRowLAbel( i, "Vertex " + i.toString() );
       }

       // Now you can change the data by using the labels
       // (this doesn't change the copy of the data inside oGridData)
       oGridDataOnPSet.SetCell( "G", "Vertex 2", 0.99 );

       // Change some of the color values and then see the updates
       InspectObj( oPSet, null, null, siModal, false );

       oClusterProp.Elements.Array = oGridDataOnPSet.Data

Autodesk Softimage v7.5