File Scripts
All  1-5  6-13

Previous
Next
 From:  RobertH
7119.6 
Thanks Michael!

I was just over-thinking the file open command, that will work fine, thanks! However for the SaveAs, I wanted a shortcut to create an object file, because I'm using the same settings again and again for many different files, then pulling them over to Marmoset. So is there a way to pre-populate the mesh settings and save out the current file, in one go, without further user intervention? Thanks?
  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
7119.7 In reply to 7119.6 
Hi Robert, yes it's possible through script to directly specify meshing settings and prevent the mesh dialog from appearing.

You can do that by this script on a shortcut key:


script: /* SaveAs no dialog */ moi.geometryDatabase.saveAs( 'c:\\mydir\\myfile.obj', 'NoUI=true' );


Some notes on that - the saveAs method takes 2 string parameters, the first is the file name, and the second is a set of options.

Strings in JavaScript use the backslash \ character as an escape for making special characters like \r means carriage return.
To make a single backslash inside of a JavaScript string use \\ - that's why those are doubled in the above script.


Then for the second parameter you can put different values seprated by semi-colons, if you put 'NoUI=true' it will not show the mesh dialog and use default values. If you put 'NoUI=true;Angle=6' for example that has 2 parameters - NoUI=true for not showing the dialog and it will use an Angle value of 6 for the export.

The different available parameters are described below:

// 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:
// (note: | denotes mutually exclusive options, for example for Output choose one
// of the given options, like Output=quads)
//
// 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


- 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:  RobertH
7119.8 
Thank you so much Michael! That is really helpful.
  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:  RobertH
7119.9 
Sorry not quite right. For the first parameter where you specify the file name, I would like it to be the current file name, which should be a .3dm but to be saved as an .obj. Not hard coded. So is there a way to grab the current file name, strip the extension and append ".obj" ? Thanks.
  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
7119.10 In reply to 7119.9 
Hi Robert, you can get the current filename in script by moi.geometryDatabase.currentFileName - but be aware that it can be the empty string '' if there is not any current active file name.

To strip off the 3DM extension and add .obj you would do something like:

script: /* SaveAs no dialog */ var name = moi.geometryDatabase.currentFileName; if ( name != '' ) { moi.geometryDatabase.saveAs( name.substr(0, name.length) + 'obj', 'NoUI=true' ); }


I haven't tested that so it may have a typo in it.

- 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:  RobertH
7119.11 
Hi Michael,

Nothing appears to happen when running the script so I created a Javascript file version in order to debug it. Specifically I wanted to check the path of the file being generated. This keeps giving me the error "ReferenceError: Can't find the variable: alert". I've used this hundreds of times so I'm not sure what is causing the problem. Could you look at it and tell me what's wrong? In addition are there any debuggers so that I can inspect variables, execution location, etc, or is this done through alert() dialogues in Moi?


function DoTestBed() {

var name = moi.geometryDatabase.currentFileName;

alert(moi.geometryDatabase.currentFileName);
alert(name.substr(0, name.length) + 'obj');

if ( name != '' ) {
moi.geometryDatabase.saveAs( name.substr(0, name.length) + 'obj', 'NoUI=true' );
}

}

DoTestBed();
  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
7119.12 In reply to 7119.11 
Hi Robert, it looks like I had a bug in that one, it needs to be name.length-3 to strip off the existing extension , I forgot the -3 part.

Try this:

script: /* SaveAs no dialog */ var name = moi.geometryDatabase.currentFileName; if ( name != '' ) { moi.geometryDatabase.saveAs( name.substr(0, name.length-3) + 'obj', 'NoUI=true' ); }


re: alert - instead of using just plain alert() instead use moi.ui.alert(), that should pop up an alert dialog for you.

alert() is not part of the base JavaScript language itself, it's part of the web browser environment that you're used to your scripts normally running in. When you execute a shortcut key script, that is happening in an isolated script context all by itself rather than running inside of the browser environment, that's the difference.

re: In addition are there any debuggers so that I can inspect variables, execution location, etc, or is this done through alert() dialogues in Moi?

Sorry no there isn't currently any debugger for inspection and breakpoints and stuff like that.

- 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
 From:  RobertH
7119.13 
Thanks Michael! that fixed the problem, also for the alert information, that makes sense.
  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

 

 
 
Show messages: All  1-5  6-13