I’ve noted the nature and location of each failure. Any ideas?
private void button3_Click(object sender, EventArgs e)
{
bButton3 = true;
string strLayerName = "";
Rhino.RhinoDoc doc = Rhino.RhinoDoc.ActiveDoc;
foreach (Rhino.DocObjects.Layer lyr in doc.Layers) <--This works - turns off all layers, except Walls and Text
{
if (lyr.Name != "Walls" && lyr.Name != "Text")
{
lyr.IsVisible = false;
lyr.CommitChanges();
}
else
{
lyr.IsVisible = true;
lyr.CommitChanges();
}
}
doc.Views.Redraw();
foreach (DataGridViewRow dgvr in DataGridView1.Rows)
{
strLayerName = dgvr.Cells[0].Value.ToString();
int layer_index = doc.Layers.Find(strLayerName, true);
if (layer_index >= 0)
{
try
{
var file_name = "";
doc.Layers[layer_index].IsVisible = true;
doc.Layers[layer_index].CommitChanges();
var bitmap = doc.Views.ActiveView.CaptureToBitmap(true, true, true); <--- doc.Layers[layer_index] is not visible
// copy bitmap to clipboard
Clipboard.SetImage(bitmap); <-- I don't think I need this, but kept it just in case.
// save bitmap to file
file_name = doc.Path + "\\Cabinet Labels\\" + strLayerName + ".BMP";
bitmap.Save(file_name); <-- "A generic error occurred in GDI+."
doc.Layers[layer_index].IsVisible = false;
doc.Layers[layer_index].CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}