Sunday, May 12, 2013

Assigning a seperate material to a selection of objects

Sometimes when I import .obj files, they consist of separate meshes with no materials assigned.  I wrote a super simple script to assign a new material to each mesh selected, and then it merges them all together, filter points (0 tolerance), quadralates it, and then matches the transforms to a different mesh.

VB Script:
set oSelection = Application.Selection 
for i = 0 to (oSelection.Count - 1) 
 ApplyShader "$XSI_DSPRESETS\Shaders\Material\Lambert.Preset", , , , siLetLocalMaterialsOverlap
 next
ApplyGenOp "MeshMerge", , oSelection , 3, siPersistentOperation, siKeepGenOpInputs
SetValue "polymsh.polymsh.mergemesh.tolerance", 0
TransferAllPropertiesAcrossGenOp "polymsh.polymsh.mergemesh", "polymsh", , True, True
TransferAllPropertiesAcrossGenOp "polymsh.polymsh.mergemesh", "polymsh", , True
CopyAnimationAcrossGenerator "polymsh.polymsh.mergemesh", 0
SetValue "polymsh.polymsh.mergemesh.inputreadregion", 0
DeleteGeneratorInputs "polymsh.polymsh.mergemesh"
MatchTransform "polymsh", "DrugCartel1", siSRT
SelectAllUsingFilter "Vertex", siCheckComponentVisibility
ApplyTopoOp "FilterPoints", "polymsh.pnt[*]", siUnspecified, siPersistentOperation
SetValue "polymsh.polymsh.filterpointsbydistancesop.distance", 0
SetValue "polymsh.polymsh.filterpointsbydistancesop.deletedoublepolygons", False
SetValue "polymsh.polymsh.filterpointsbydistancesop.collapsedoubleedges", False
ApplyTopoOp "Quadrangulate", "polymsh", siUnspecified, siPersistentOperation