Batch Convert STP to FBX

Next
 From:  ironsightdesign
9695.1 
I've been trying to piece together code for a script to batch convert over 200 .stp files to .fbx, but cant seem to get it working.

These are my scripts (inside a "scripts" folder in the MOI program files directory, called with a shorthcut:

------
BatchConvert.js
// This is the script file that you would generate, put one line in
// for each file you want to convert.

#include "Convert.js"

function ConvertFolder( FolderName, FileExtensionToLoad )
{
// Convert all files within a given folder, that have the given file extension.
// For example, convert all .3dm files inside of the folder c:\test :
// ConvertFolder( 'c:\\test', '3dm' );

ConvertFolder( 'd:\\_convert', 'stp' );

var Files = moi.filesystem.getFiles( FolderName, '*.' + FileExtensionToLoad );

for ( var i = 0; i < Files.length; ++i )
Convert( Files.item(i) );
}


------
Convert.js
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 );

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

FBXFileName = FileName.substr( 0, FileName.lastIndexOf('.') + 1 ) + 'fbx';

// 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=12.0
// Output=ngons | quads | triangles
// MaxLength=0.0
// MaxLengthApplyTo=curved | planes | all
// MinLength=0.0
// AspectRatio=0.0
// Weld=true
// Display=shadedwithedges | shadednoedges | wireframe
// ExpandedDialog=false

gd.saveAs( FBXFileName, 'NoUI=true;Angle=8.0;Weld=true;MaxLength=4;Output=quads' );

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

}


-----

Thanks for any help!
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
9695.2 In reply to 9695.1 
Hi ironsightdesign, I think the problem is in your BatchConvert.js file, you've got to move this: ConvertFolder( 'd:\\_convert', 'stp' ); to the bottom, right now it's located inside the ConvertFolder function itself so that's going to be an infinite loop.

So like this:

BatchConvert.js

code:
// This is the script file that you would generate, put one line in
// for each file you want to convert.

#include "Convert.js"

function ConvertFolder( FolderName, FileExtensionToLoad )
{
    // Convert all files within a given folder, that have the given file extension.
    // For example, convert all .3dm files inside of the folder c:\test :
    // ConvertFolder( 'c:\\test', '3dm' );

    // Not right here though!
    //ConvertFolder( 'd:\\_convert', 'stp' );

    var Files = moi.filesystem.getFiles( FolderName, '*.' + FileExtensionToLoad );

    for ( var i = 0; i < Files.length; ++i )
        Convert( Files.item(i) );
}

// Put it here:
ConvertFolder( 'd:\\_convert', 'stp' );




Let me know if you're still stuck. If so maybe post your .js files as a file attachment.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  ironsightdesign
9695.3 In reply to 9695.2 

Awesome, that worked great. Thanks Michael.

Now the batch export is working, but still writing objs. Any way to get fbxs instead?

EDIT: Nevermind...working now, exporting to fbx. Thanks again for the help.

EDITED: 21 Feb 2020 by IRONSIGHTDESIGN

Attachments:

  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  Michael Gibson
9695.4 In reply to 9695.3 
You're welcome, I'm glad you are working now!

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All