MoI discussion forum
MoI discussion forum

Full Version: Script to save MoI screen shot w/ transparent BG to clipboard

Show messages: All  1-8  9-10

From: Michael Gibson
12 Aug 2021   [#9] In reply to [#8]
Hi pior,

re:
> If I could somehow feed up the coordinates of the 4 corner points (0 0, 0 10, 20 0, 20,10) and instruct
> the renderer to render the content within these corners at a set pixel width/height, that would
> work too.

Well the renderer just renders the view, there isn't any way to tell it to render something different. So you would need to manipulate the view to do what you need.

For a first step if you trigger a Reset on the view, that will center it on the bounding rectangle of the selected objects but leave a little bit of border space around it. Then for an ortho view the size of the viewplane can be set to the size of the geometry to frame it without any border space.

That would go something like this:

script: var objs = moi.geometryDatabase.getSelectedObjects(); var vp = moi.ui.getActiveViewport(); if ( vp.projection == 'Parallel' && objs.length > 0 ) { vp.reset( 'selected' ); var bbox = objs.getHighAccuracyBoundingBox(); vp.fieldOfViewAngle = bbox.yLength; }

I think the on screen display may not show the top and bottom of the objects because they will be running right over the border decorations of the viewport but on a scripted render call the border decorations won't be shown.

- Michael
From: pior (PIOR_O)
12 Aug 2021   [#10] In reply to [#9]
Well, this is *exactly* it ! All I had to do was to feed it square values (in this present case, 4096*4096), otherwise I somehow end up with a smaller rendered "page" inside the full render - and then all I have to do is to crop the result down to 4096*2048 in PS. This basically saves me about 10 minutes of exporting/importing back and forth to other vector applications just to get my precise lineart render out of MOI. And with the ability to render to clipboard I don't even have to worry with intermediate files anymore either. And of course everything lines up perfectly with the original layout, this is brilliant. Thank you so much !

FWIW the full code turns out to be :

script: var objs = moi.geometryDatabase.getSelectedObjects(); var vp = moi.ui.getActiveViewport(); if ( vp.projection == 'Parallel' && objs.length > 0 ) { vp.reset( 'selected' ); var bbox = objs.getHighAccuracyBoundingBox(); vp.fieldOfViewAngle = bbox.yLength; }; var prev_background = moi.view.viewportBackgroundColor; moi.view.viewportBackgroundColor = 0xFFFFFF; moi.view.lineWidth = 2; moi.grid.display = false; moi.grid.showXYAxes = false; moi.view.showAxisIcon = false; moi.view.showViewTitles = false; var img = null; try { img = moi.ui.getActiveViewport().renderToClipboard( 4096, 4096 ); } catch(e){} moi.view.lineWidth = 1; moi.grid.display = true; moi.grid.showXYAxes = true; moi.view.showAxisIcon = true; moi.view.showViewTitles = true; moi.view.viewportBackgroundColor = prev_background;

Show messages: All  1-8  9-10