Try this. 

1) paste script into script editor (JScript)
2) Select parent polygon meshes
3) run script


main();
function main()
{
    var oObjects = SIFilter( null, siPolyMeshFilter, true, siQuickSearch );
    
    for ( var i = 0; i < oObjects.Count; i++ )
    {
        var oObject = oObjects(i);

        var oItems    = XSIFactory.CreateActiveXObject( "XSI.Collection" );
        oItems.Unique = true;
        
        oItems.Add( oObject );
        
        var oChildren = oObject.FindChildren2( "", siPolyMeshType );
        
        for ( var j = 0; j < oChildren.Count; j++ )
        {
            oItems.Add( oChildren(j) );
        }
        
        if ( oItems.Count > 1 )
        {
            // merge
            var oOperators     = ApplyGenOp( "MeshMerge", "", 
oItems.GetAsText(), siUnspecified, siPersistentOperation, siKeepGenOpInputs, 
null );
            var oMergeOperator = oOperators(0);
            
            oMergeOperator.Parameters( "tolerance" ).value = 1.00;
            oMergeOperator.Parameters( "blend"     ).value = false;
            
            // 
            var oMergedObject = oMergeOperator.Parent3DObject;
            
            TransferallPropertiesAcrossGenOp( oMergeOperator.FullName, 
oMergedObject.FullName, null, true, true );

            FreezeObj( oMergedObject );

            // match the center            
            var oTransform = oObject.Kinematics.Global.Transform;
            oMergedObject.Kinematics.Global.Transform = oTransform;          
            
            try {
                DeleteObj( oItems );
            } catch(e) {
                LogMessage( "Cannot delete objects: " + e.description, siError 
);
            }
        }
    }
    
    return(0);
}




Matt




Date: Tue, 10 Feb 2015 01:35:28 +0000
From: Jeff McFall <jeff.mcf...@sas.com>
Subject: merge parent and children through scripting?
To: softimage@listproc.autodesk.com

I have a large set of extruded poly objects which have their detached caps as 
children.
I need to merge these caps into the parent geometry.  There are several hundred 
of these and manually doing each is pretty daunting.  This is beyond my 
scripting abilities.

Anyone have any suggestions or know of a script they could point me to as 
reference to get started?


Many thanks
Jeff

Reply via email to