| McNeel Wiki | |||||
| edit · print · help · all topics | |||||
Main Pages
Languages
| C# (Rhino 4)
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
{
MRhinoView view = RhUtil.RhinoApp().ActiveView();
if (view == null)
return IRhinoCommand.result.nothing;
MRhinoGetOption go = new MRhinoGetOption();
go.SetCommandPrompt("Capture Method");
go.SetCommandPromptDefault("ViewCapture");
int viewcap = go.AddCommandOption(new MRhinoCommandOptionName("ViewCapture"));
int screencap = go.AddCommandOption(new MRhinoCommandOptionName("ScreenCapture"));
go.GetOption();
if( go.CommandResult() != IRhinoCommand.result.success )
return go.CommandResult();
System.Drawing.Bitmap bmp = null;
if (go.Option().m_option_index == viewcap)
{
MRhinoDisplayPipeline pipeline = view.DisplayPipeline();
int left = 0, right = 0, bot = 0, top = 0;
view.MainViewport().VP().GetScreenPort(ref left, ref right, ref bot, ref top);
int w = right - left;
int h = bot - top;
bmp = new System.Drawing.Bitmap(w, h);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp);
MDisplayPipelineAttributes attr = new MDisplayPipelineAttributes(pipeline.DisplayAttrs());
bool rc = pipeline.DrawToDC(g, w, h, attr);
g.Dispose();
if (!rc)
bmp = null;
}
else
{
bmp = new System.Drawing.Bitmap(1, 1);
bool rc = view.ScreenCaptureToBitmap(ref bmp, true, false);
if (!rc)
bmp = null;
}
if (bmp != null)
{
string mydir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
string path = System.IO.Path.Combine(mydir, "capture.png");
bmp.Save(path);
return IRhinoCommand.result.success;
}
return IRhinoCommand.result.failure;
}
| ||||
| rename · changes · history · subscriptions · lost and found · references · file upload | |||||