Save as with screen shot

Next
 From:  shayno
6249.1 
Hi Michael

I have been using your script in save.js to save a screenshot

I can't work it out so it works in save as , although I often save an stl output in a different folder to where the 3dm drawing is stored.
Could it be saving the jpg in the 3dm folder

my save as file

// config: norepeat

moi.geometryDatabase.saveAs( moi.command.getCommandLineParams() );

script:var img = moi.view.screenshot( 'viewpanel', false ); var filename = moi.geometryDatabase.currentFileName; if ( filename != '' ) { img.save( filename.substring(0,filename.length-3) + 'jpg' ); }

thanks
shayne
  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
6249.2 In reply to 6249.1 
Hi Shayne, so if I understand right what's happening is you're saving to an "external" (meaning other than 3DM) file type during the Save As.

The issue with that, is that when you save to a non-3DM file format, the current file name does not get changed. That's because many things that MoI has in it like background images, etc... are only saved when it's going into a 3DM file, so only 3DM files set the current file name which is then used later on when you do a plain "Save" (instead of "Save As").

So what you'll want to do is not read the file name by doing this: var filename = moi.geometryDatabase.currentFileName;

Instead you'll want your script to pop up the file dialog box itself so that it can get the filename being saved to and work with it directly rather than trying to retrieve it from .currentFileName

Something like this (note this isn't tested, let me know if it does not work):

code:
    // config: norepeat

    var filename = moi.geometryDatabase.getSaveFileName();

    if ( filename != '' )
    {
        moi.geometryDatabase.saveAs( filename );

        var img = moi.view.screenshot( 'viewpanel', false );
        img.save( filename.substring(0,filename.length-3) + 'jpg' );
     }



Anyway the main thing there is that it gets the filename by calling moi.geometryDatabase.getSaveFileName(); - that will pop up the file save dialog and return back the filename that was picked, you can then pass that on to saveAs and also use it for the image save as well.

- 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:  shayno
6249.3 
Thanks very much Michael

That works although it jumps the gun by saving the screenshot while the stl controls are still up



Cheers
shayne
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
Next
 From:  Michael Gibson
6249.4 In reply to 6249.3 
Hi shanye, try putting in a call to moi.ui.redrawViewports(); before the screenshot, does that help any?

- 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:  shayno
6249.5 
Fantastic thanks

// config: norepeat

var filename = moi.geometryDatabase.getSaveFileName();

if ( filename != '' )
{
moi.geometryDatabase.saveAs( filename );
moi.ui.redrawViewports();

var img = moi.view.screenshot( 'viewpanel', false );
img.save( filename.substring(0,filename.length-3) + 'jpg' );
}

shayne
  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:  moritzbock (MORITZ)
6249.6 In reply to 6249.5 
Hello shayne, hello Michael,

this script works perfect so far, it runs the SAVE-dialog correct and produces a .jpg-File - but the screenshot (the .jpg-File) is totally black.

I use Moi V3 beta Aug 1-2013 on a MAC Pro with OS X V10.9 Mavericks.

- Moritz
  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
6249.7 In reply to 6249.6 
Hi Moritz, this type of screenshot does not work on OSX yet, it's something that I will need to fix up.

The other kind of screenshot that generates a viewport image internally and puts it on the clipboard does work on OSX though. If you search here for "renderToClipboard" you can find that one.

The "renderToClipboard" method won't quite work as a drop-in replacement for this particular script though because it generates an image and puts it on the clipboard rather than generating an "image object" which can be saved directly to disk instead as this script is doing.

In the next v3 beta there will be a new .render() method that works similar to .renderToClipboard() in that it generates an image internally instead of just taking a capture of the current display screen and does return an image object that can then be saved to disk in the script, so that one that's coming in the next beta could work as a drop-in replacement instead of the .screenshot() method.

- 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