Grasshopper

algorithmic modeling for Rhino

HI all,

i want be able to use the CaptureToBitmap method in my list of NamedViews.

Do i need to set a current view out of my NamedViewsList to save it as a bitmap or is it possible in another way?

My code till now is the following:Thanks!

Views: 2109

Attachments:

Replies to This Discussion

See attached!

You can take as a reference!

Attachments:

hey panda, 

thanks! it worked fine, after some adjustements i got no output but neither an error message.

could you maybe have a look ?

Attachments:

Works fine here!

No any error were found!

Sorry for insisting, but i just tried it again and dont know what is going wrong.

i just dont get any output it seems the views were imported well, there is just no image in the specified folder.

Did you get an image saved?

Thanks!

There must have at least one Named Views in Named Views Table!

hi,thanks for responding!

of course, I checked this also in the component, but it is not exporting.I think maybe there is another issue.

Example attached!

You can compare the two sections of the code to see what the difference is!

Attachments:

thanks! i think i got it. i think my confused came from the missing step to restore the view, i thought it already would hapen, so thats t¡why it worked just for the first when and just when it was selected.

Many thanks for all you help!

Hi Chapulin,

Add a variable x as string for the view name and try the following code:

if (!run) return;

Rhino.DocObjects.Tables.NamedViewTable viewTable = doc.NamedViews;
List<Rhino.DocObjects.ViewInfo> viewList = viewTable.ToList();

for (int i = 0; i < viewList.Count; i++)
{

string vn = x;

Rhino.RhinoDoc.ActiveDoc.Views.Redraw();
Rhino.Display.RhinoView view = RhinoDocument.Views.Find(vn, false);

if (view == null)
{
Print("you are not pointing to the right view");
return;
}

string fileName = string.Format("{0}\\{1}." + format, filePath, vn);

Rhino.Display.DisplayModeDescription displaymode = Rhino.Display.DisplayModeDescription.FindByName(displayMode);
Bitmap image = view.CaptureToBitmap(new Size(width, height), displaymode);
if (image == null)
return;
image.Save(fileName);
image.Dispose();


}
A = viewTable;

The view variable returns a null if you don't have this view as current in your rhino document.

Hope this makes sense.

Best

M

hi, thanks Marios!

this helps me to know that vn returns null. But how to fix this? I dont really  understand the problem still.when it says:"you are not pointing to the right view"

you mean i need to set the viewport by hand?As in myprevious post, for example vn is recognized but there is no output.

I thought cause i have in my viewList various items i can iterate over setting it active and saving it.

Maybe you are so kind to help me explaining how do i need to setup the rhino or better how to fix the script?

thanks!

Hi Chapulin,

The following should work

private void RunScript(string folder, int imagecount, string view, bool export, ref object A)
{
if (!export)
{
imageNumber = 0;
return;
}
else
{
if( imageNumber < imagecount)
capture_frame(folder, imageNumber, view);
imageNumber++;
}
}

// <Custom additional code> 
private int imageNumber = 0;
private void capture_frame(string _folder, int imageNumber, string v)
{
//redraw
Rhino.RhinoDoc.ActiveDoc.Views.Redraw();

//get the index of the named view
int view0 = Rhino.RhinoDoc.ActiveDoc.NamedViews.FindByName(v);

//get the active view
Rhino.Display.RhinoView view = Rhino.RhinoDoc.ActiveDoc.Views.ActiveView;
//restore your named view to the active view
Rhino.RhinoDoc.ActiveDoc.NamedViews.Restore(view0, view, false);

//double check that it works properly
if (view == null)
{
Print("You are not pointing to the selected view");
return;
}

//exp[ort the current view
string fileName = string.Format("{0}\\{1}.png", _folder, imageNumber);
imageNumber++;
Bitmap image = view.CaptureToBitmap();
if (image == null)
{
Print("NO Image was created");
return;
}
image.Save(fileName);
image.Dispose();
}

Best,

M

Hey Marios,

thanks a lot costs me an hour more to make it work,your help is really appreciated!

You showed me exactly what i needed, so weekend can begin,hehe!

regards!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service