File Scripts
All  1-8  9-13

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-8  9-13