Grasshopper

algorithmic modeling for Rhino

Hi,

i am looking for a possibility to save grasshopper canvas as picture from python. Is there grasshopper API method or external module has to be used?

there are "Export hi-res image" or " Export quick image" of which eqiuvale i am lookin for in python.

Views: 1289

Replies to This Discussion

Hi Vladimir,

I am not sure if David provides those function in the SDK. I will ask.

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

I think he does, didn't test any further though (away from Rhino).

That's a good way.

If you just want the current canvas, you can do it like this:

This was created with the script itself, and the definition is attached.

I hope this helps,

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

Attachments:

Uh that's a neat solution, going in the ol' bag of tricks. Cheers Giulio!

Hi,

thanks a lot, this works.

i check gh.GUI.Canvas.GH_Canvas.GenerateHiResImage() method anders found, but it does not want to merge generated tiles to specified folder. It exports all tiles to C:\Temp

this is my c# code from metahopper to capture the GH canvas to a specified filepath (borrowing liberally from David's own code I'll confess)

private void Capture(double scaleFactor, string filePath, Color background)
{
if (scaleFactor > 5)
{
var result = MessageBox.Show("Are you sure you want to capture an image at this scale? It might take a long time or fail unexpectedly.", "", MessageBoxButtons.YesNo);
if (result == DialogResult.No) return;
}

var canvas = Grasshopper.Instances.ActiveCanvas;


var rec = GH_Convert.ToRectangle(canvas.Document.BoundingBox(false));
var settings =
new GH_Canvas.GH_ImageSettings(filePath)
{
BackColour = background,
Zoom = (float)scaleFactor
};

Size size;
var tiles = canvas.GenerateHiResImage(rec, settings, out size);
if (tiles == null || tiles.Count <= 0) return;
var args = $"{settings.Folder}\\{settings.FileName}{settings.Extension}";
args +=
$"|{size.Width}|{size.Height}|{GH_Canvas.GH_ImageSettings.TileSize.Width}|{GH_Canvas.GH_ImageSettings.TileSize.Height}";
args += $"|{System.IO.Path.GetDirectoryName(tiles[0])}";
var stitcherApplication = Grasshopper.Folders.ImageStitcherApplication;
try
{
Process.Start(stitcherApplication, args);
}
catch (Exception e)
{
AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
}
}

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service