OBJ material names by style

 From:  Micha
5790.1 
Hello Michael,

could you please modify the attached MoI script so that the exported obj material definition contain material names with a defines sign for spaces in the material name? At the moment the materials are names like "Layer_01", but I would like to use a more exotic sign like "§". For the object names it was implemented in this script, but the material names are not part of the script. Or is there an ini command to set the sign for the spaces in materials? I would like to get it run with MoI 2.

Best-
Micha


function AssignObjectNamesFromStyles()
{
// Set object names to be their Style name + unique number.

var objs = moi.geometryDatabase.getObjects();
var styles = moi.geometryDatabase.getObjectStyles();

for ( var i = 0; i < objs.length; ++i )
{
var obj = objs.item(i);
var name = styles.item(obj.styleIndex).name + '§' + i;

// Replace all spaces with underscore characters, since spaces don't work as
// object names in OBJ files.
obj.name = name.replace( /\s/g, '§' );
}
}

function Convert(FileName)
{
var gd = moi.geometryDatabase;

// Open the file, set 2nd param to true to suppress any save changes prompt.
gd.open( FileName, true );

AssignObjectNamesFromStyles();

moi.view.resetAll();

// Create the output file name by breaking off the file extension and adding 'obj'.

OBJFileName = FileName.substr( 0, FileName.lastIndexOf('.') + 1 ) + 'obj';

// Save out to the output file, passing the option to suppress the UI. You
// add other options separated by semi-colons with no spaces. These
// options are available for controlling the meshing:
// NoUI=true
// Angle=6.0
// Output=ngons | quads | triangles
// MaxLength=
// MaxLengthApplyTo=curved | planes | all
// MinLength=4
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false

gd.saveAs( OBJFileName, 'Angle=;MinLength=;MaxLength=;AspectRatio=;Weld=true;Output=quads');

// Let's clear out and suppress any save changes prompt again.
gd.fileNew( true );
}

Convert('d:\\Temp\\#moi.3dm');

moi.exit( true ); // Pass true to suppress save changes prompt.

Visualisation for Designer and Architects | http://www.simulacrum.de