Modifying this script to save screenshot to file?

Next
 From:  chippwalters
7655.1 
code:
script: /* Custom screenshot */ var prev_background = moi.view.viewportBackgroundColor; 
moi.view.viewportBackgroundColor = 0xFFFFFF; 
moi.view.lineWidth = 3; 
moi.grid.display = false; 
moi.grid.showXYAxes = false; 
moi.view.showAxisIcon = false; 
moi.view.meshAngle = 3; 
moi.ui.getActiveViewport().renderToClipboard( 4000, 2500 ); 
moi.view.lineWidth = 1; 
moi.grid.display = true; 
moi.grid.showXYAxes = true; 
moi.view.showAxisIcon = true; 
moi.view.meshAngle = 8; 
moi.view.viewportBackgroundColor = prev_background;


How best to modify above script to save same image as a PNG (preferably a transparent PNG)? Thanks anyone for the 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:  Max Smirnov (SMIRNOV)
7655.2 In reply to 7655.1 
Hi Chipp,
you need to replace this line:
moi.ui.getActiveViewport().renderToClipboard( 4000, 2500 );
with this:
moi.ui.getActiveViewport().render( 4000, 2500 ).save("filename.png");
  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:  Frenchy Pilou (PILOU)
7655.3 
Magic of simplicity! ;)
---
Pilou
Is beautiful that please without concept!
My Gallery
  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
7655.4 In reply to 7655.1 
Hi Chipp, also check out here for a version that will pop up a dialog box to ask you for the file name for the image file, if you want that:
http://moi3d.com/forum/index.php?webtag=MOI&msg=7542.2

These won't save as a transparent PNG though, the viewport background will be in there.

But if you export to AI or PDF format, the shaded image in those will have a transparent background. For PDF format the image is embedded in the PDF file, for AI format the image will be a separate .png file alongside the .ai file, the png file will have a "_bkgnd" appended to the file name like: filename_bkgnd.png

- 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

Message 7655.5 deleted 5 Oct 2015 by CHIPPWALTERS

Previous
Next
 From:  Max Smirnov (SMIRNOV)
7655.6 In reply to 7655.5 
Try this one:
code:
script: /* Save to PNG */
var vp = moi.ui.getLastClickedViewport();
if (!vp) { vp = moi.ui.mainWindow.viewpanel.getViewport('3D'); }
var filename = moi.filesystem.GetSaveFileName( 'Save', ' (*.png)|*.png' );
var st = [], settings  = ["view.viewportBackgroundColor", "view.lineWidth", "grid.display", "grid.showXYAxes", "view.showAxisIcon", "view.meshAngle"];
for (var sv in settings) { st.push(moi[settings[sv].split('.')[0]][settings[sv].split('.')[1]] ); } 
moi.view.viewportBackgroundColor = 0xFFFFFF; 
moi.view.lineWidth = 3; 
moi.grid.display = false; 
moi.grid.showXYAxes = false; 
moi.view.showAxisIcon = false; 
moi.view.meshAngle = 3; 
vp.render( 4000, 2500 ).save(filename);
for (var sv in settings) { moi[settings[sv].split('.')[0]][settings[sv].split('.')[1]] = st.shift(); }
  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:  chippwalters
7655.7 In reply to 7655.6 
YAY Max!

Works PERFECTLY! :-)

For those who don't want to remove the CRs:

code:
script: /* Save to PNG */ var vp = moi.ui.getLastClickedViewport(); if (!vp) { vp = moi.ui.mainWindow.viewpanel.getViewport('3D'); } var filename = moi.filesystem.GetSaveFileName( 'Save', ' (*.png)|*.png' ); var st = [], settings  = ["view.viewportBackgroundColor", "view.lineWidth", "grid.display", "grid.showXYAxes", "view.showAxisIcon", "view.meshAngle"]; for (var sv in settings) { st.push(moi[settings[sv].split('.')[0]][settings[sv].split('.')[1]] ); }  moi.view.viewportBackgroundColor = 0xFFFFFF;  moi.view.lineWidth = 3;  moi.grid.display = false;  moi.grid.showXYAxes = false;  moi.view.showAxisIcon = false;  moi.view.meshAngle = 3;  vp.render( 4000, 2500 ).save(filename); for (var sv in settings) { moi[settings[sv].split('.')[0]][settings[sv].split('.')[1]] = st.shift(); }

EDITED: 6 Oct 2015 by CHIPPWALTERS

  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