MoI discussion forum
MoI discussion forum

Full Version: Script request

From: shayno
25 May   [#1]
Hi Michael
I am using ver 4 (which is brilliant thanks)

Can you please write me a script that
saves an output file as my current file name
to a specified output folder ( it will always be the same )
as an stl angle 3

king regards
shayne
From: Michael Gibson
25 May   [#2] In reply to [#1]
Hi shayne, are you on Mac or Windows?

- Michael
From: shayno
25 May   [#3]
Windows Thanks Michael
From: Michael Gibson
25 May   [#4] In reply to [#1]
Hi shayne, here you go:

script: var folder = 'c:\\scripts\\'; var filename = moi.geometryDatabase.currentFileName; if ( filename ) { var index = filename.lastIndexOf( '.' ); if ( index != -1 ) { filename = filename.substr( 0, index ) + '.stl'; filename = folder + moi.filesystem.getFileNameFromPath( filename ); moi.geometryDatabase.saveAs( filename, 'NoUI=true;Angle=3' ); } }

Edit this part:
var folder = 'c:\\scripts\\';

to put in your output folder.

Note that to make a backslash character (\) there you will need to put in two backslashes because it's used as an escape character.

- Michael
From: shayno
25 May   [#5]
Hi Michael
That is brilliant thank you so much .
It will save me countless time every day
cheers
shayne
From: shayno
8 Jun   [#6] In reply to [#4]
Hi Michal
is it possible at the end of the script to have it copy the 3dm filename into the clipboard also ?
cheers
shayne
From: Michael Gibson
8 Jun   [#7] In reply to [#6]
Hi shayne,

re:
> is it possible at the end of the script to have it copy the 3dm filename into the clipboard also ?

Yes, try this one:

script: var folder = 'c:\\scripts\\'; var filename = moi.geometryDatabase.currentFileName; if ( filename ) { var index = filename.lastIndexOf( '.' ); if ( index != -1 ) { filename = filename.substr( 0, index ) + '.stl'; filename = folder + moi.filesystem.getFileNameFromPath( filename ); moi.geometryDatabase.saveAs( filename, 'NoUI=true;Angle=3' ); } moi.copyTextToClipboard( filename ); }

- Michael
From: shayno
9 Jun   [#8]
Hi Michael
It copied the full path c:\to print\filename.stl

I just need the filename only if that is possible without any .stl or .3dm
Thanks
shayne
From: Michael Gibson
9 Jun   [#9] In reply to [#8]
Hi shayne, try this one:

script: var folder = 'c:\\scripts\\'; var filename = moi.geometryDatabase.currentFileName; if ( filename ) { var index = filename.lastIndexOf( '.' ); if ( index != -1 ) { var basename = filename.substr( 0, index ); filename = basename + '.stl'; filename = folder + moi.filesystem.getFileNameFromPath( filename ); moi.geometryDatabase.saveAs( filename, 'NoUI=true;Angle=3' ); moi.copyTextToClipboard( moi.filesystem.getFileNameFromPath(basename) ); } }

- Michael
From: shayno
9 Jun   [#10] In reply to [#9]
Thanks Michael

it errors

ReferenceError: Can't find variable: basename

line 1

1: >> var folder = 'D:\\To Print Morris and Watson\\'; var filename = moi.geometryDatabase.currentFileName; if ( filename ) { var index = filename.lastIndexOf( '.' ); if ( index != -1 ) { filename = filename.substr( 0, index ) + '.stl'; filename = folder + moi.filesystem.getFileNameFromPath( filename ); moi.geometryDatabase.saveAs( filename, 'NoUI=true;Angle=3' ); moi.copyTextToClipboard( moi.filesystem.getFileNameFromPath(basename) ); } }

If its too hard to do don't spend any time on it
cheers
shayne
From: Michael Gibson
10 Jun   [#11] In reply to [#10]
Hi shayne,

re:
> it errors
>
> ReferenceError: Can't find variable: basename

It looks like you only copied the last piece of the above script?

You are missing this part in the new version above:

script: var folder = 'c:\\scripts\\'; var filename = moi.geometryDatabase.currentFileName; if ( filename ) { var index = filename.lastIndexOf( '.' ); if ( index != -1 ) { var basename = filename.substr( 0, index ); filename = basename + '.stl'; filename = folder + moi.filesystem.getFileNameFromPath( filename ); moi.geometryDatabase.saveAs( filename, 'NoUI=true;Angle=3' ); moi.copyTextToClipboard( moi.filesystem.getFileNameFromPath(basename) ); } }

Try copying the entire script from above not just the ending part.

- Michael
From: shayno
10 Jun   [#12]
Works perfect thanks shayne