(API) screen capture of results and save in .jpeg

(API) screen capture of results and save in .jpeg

Anonymous
Not applicable
3,313 Views
13 Replies
Message 1 of 14

(API) screen capture of results and save in .jpeg

Anonymous
Not applicable

Hi everyone,

 

I want screen captures for MXX,MYY and so on (sectional forces and moments) for the structure that I have. I want to just save these screen captures in jpeg format in a folder so that I can use them later.

 

I have written the following code:

 

IRobotView3 mavuerobot = Robapp.Project.ViewMngr.GetView(1) as IRobotView3;
mavuerobot.Selection.Get(IRobotObjectType.I_OT_CASE).FromText("1");
mavuerobot.Redraw(1);
mavuerobot.Projection = IRobotViewProjection.I_VP_3DXYZ;


mavuerobot.ParamsFeMap.CurrentResult = IRobotViewFeMapResultType.I_VFMRT_DETAILED_MOMENT_XX;
mavuerobot.Visible = 1;
mavuerobot.Redraw(1);
Robapp.Project.ViewMngr.Refresh();

 

RobotViewScreenCaptureParams ScPar = Robapp.CmpntFactory.Create(IRobotComponentType.I_CT_VIEW_SCREEN_CAPTURE_PARAMS);
ScPar.Name = "First capture";
ScPar.UpdateType =IRobotViewScreenCaptureUpdateType.I_SCUT_CURRENT_VIEW;
ScPar.Resolution =IRobotViewScreenCaptureResolution.I_VSCR_4096;
mavuerobot.MakeScreenCapture(ScPar);

 

 

Could you please help me as to how I should save the screen capture in .jpeg now? And I am correctly capturing the screen capture for panel MXX through the above code?

0 Likes
Accepted solutions (1)
3,314 Views
13 Replies
Replies (13)
Message 2 of 14

Anonymous
Not applicable

Hi @Rafal.Gaweda,

 

I did the same. I copied the screen capture on to the clipboard and tried to paste it in Excel. It doesn't work. The screen capture is in what format? I am unable to get that. 

 

if (Clipboard.GetDataObject() != null)
{
IDataObject data = Clipboard.GetDataObject();

if (data.GetDataPresent(DataFormats.Bitmap))
{
Image image = (Image)data.GetData(DataFormats.Bitmap, true);

image.Save("image.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
image.Save("image.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
image.Save("image.gif", System.Drawing.Imaging.ImageFormat.Gif);
}
else
{
MessageBox.Show("The Data In Clipboard is not as image format");
}
}
else
{
MessageBox.Show("The Clipboard was empty");
}

 

When I try the above snippet of code, it shows that the data in clipboard is not in image format.

 

I am trying to paste the contents of clipboard like this:

xlWorkbook.Sheets["Results"].Range("B" + D * 45).Paste();

 

But this doesn't work. It throws an error. I somehow feel it is due to the format of the clipboard contents.

 

I have been able to do it in VBA though.

Call InsPicFromClipbrd("B" & M * 45, TitleName)

 

This works great. 

 

Could you please help me resolve this for my C# code?

0 Likes
Message 3 of 14

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

My example VBA code works:

 

Sub screen_capture()

Set robapp = New RobotApplication

Dim mavueRobot As IRobotView3
Set mavueRobot = robapp.Project.ViewMngr.GetView(1)
Dim ScPar As RobotViewScreenCaptureParams
Set ScPar = robapp.CmpntFactory.Create(I_CT_VIEW_SCREEN_CAPTURE_PARAMS)

ScPar.Name = "capture"
ScPar.UpdateType = I_SCUT_CURRENT_VIEW
ScPar.Resolution = I_VSCR_4096
ScPar.UpdateType = I_SCUT_COPY_TO_CLIPBOARD
mavueRobot.MakeScreenCapture ScPar

ActiveSheet.Range("A1").Select
ActiveSheet.Paste

End Sub


Rafal Gaweda
0 Likes
Message 4 of 14

Rafal.Gaweda
Autodesk Support
Autodesk Support

HI @Anonymous

 

BTW, there is no way to save screen capture to jpeg, only to rtf

 



Rafal Gaweda
0 Likes
Message 5 of 14

Anonymous
Not applicable
Hi,

Thank you for your response. But this doesn't seem to work, unfortunately
0 Likes
Message 6 of 14

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @Anonymous

 

 



Rafal Gaweda
0 Likes
Message 7 of 14

Rafal.Gaweda
Autodesk Support
Autodesk Support
Accepted solution

Hi @Anonymous

 

C# example:

 

using System.Runtime.InteropServices;
using Excel = Microsoft.Office.Interop.Excel;
......
        private void button1_Click(object sender, EventArgs e)
        {
            RobotOM.IRobotApplication RobApp = new RobotOM.RobotApplication();

            IRobotView3 myviewRobot ;
            myviewRobot = (IRobotView3) RobApp.Project.ViewMngr.GetView(1);
            RobotViewScreenCaptureParams ScPar;
            ScPar = RobApp.CmpntFactory.Create(IRobotComponentType.I_CT_VIEW_SCREEN_CAPTURE_PARAMS);
            ScPar.UpdateType = IRobotViewScreenCaptureUpdateType.I_SCUT_COPY_TO_CLIPBOARD;
ScPar.Resolution = IRobotViewScreenCaptureResolution.I_VSCR_4096; myviewRobot.MakeScreenCapture(ScPar); Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlApp.Visible = true; xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets["Sheet1"]; xlWorkSheet.Name = "Screen Capture"; xlWorkSheet.Range["A1"].Select(); xlWorkSheet.Paste(); }


Rafal Gaweda
0 Likes
Message 8 of 14

Anonymous
Not applicable

Hi @Rafal.Gaweda,

 

Thank you for your response. This works great. 

 

I have one more question for you. How do I get a decent zoomed in screenshot? Right now what I am getting is a horribly out of scale picture. I have tried to use this:

 

 

double V_left = 0; double V_top = 0; double V_bottom = 0; double V_right = 0;
RView.GetZoom(out V_left, out V_top, out V_right, out V_bottom);
RView.SetZoom(V_left, V_top, V_right, V_bottom);

robotApplication.Project.ViewMngr.Refresh();

 

 

RobotViewScreenCaptureParams SSParams = robotApplication.CmpntFactory.Create(IRobotComponentType.I_CT_VIEW_SCREEN_CAPTURE_PARAMS);

string TitleName = "";

SSParams.Name = Options[n, 2].ToString() + "-" + Options[n, envelope];
SSParams.ScaleAutomatic = true;

TitleName = SSParams.Name;

SSParams.UpdateType = IRobotViewScreenCaptureUpdateType.I_SCUT_CURRENT_VIEW;
SSParams.Resolution = IRobotViewScreenCaptureResolution.I_VSCR_4096;
SSParams.UpdateType = IRobotViewScreenCaptureUpdateType.I_SCUT_COPY_TO_CLIPBOARD;
RobotMapView.MakeScreenCapture(SSParams);

Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;

object misValue = System.Reflection.Missing.Value;

xlApp = new Excel.Application();
xlApp.Visible = true;
xlWorkBook = xlApp.Workbooks.Add(misValue);

xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets["Sheet1"];
xlWorkSheet.Name = "Screen Capture";

xlWorkSheet.Range["A1"].Select();
xlWorkSheet.Paste();

0 Likes
Message 9 of 14

Anonymous
Not applicable

This is the image I am getting. I have attached the Excel file containing the screenshot as obtained by the API

0 Likes
Message 11 of 14

Anonymous
Not applicable

Hi @Rafal.Gaweda,

I tried the code in Post 25. No luck there. Badly distorted images. Only part of the panel available in images. Over-zoomed, etc. Could you please help? Any more suggestions?

 

Thanks

0 Likes
Message 12 of 14

Anonymous
Not applicable

hi @Rafal.Gaweda,

 

And the screenshot picture is huge too. I meant the dimensions. Any way to resolve that?

0 Likes
Message 14 of 14

Anonymous
Not applicable

Hi @Rafal.Gaweda,

Thank you for your reply.

 

I reduced the zooming factor to 1. Some images are of okay resolution and clarity (the ones at the bottom the Results sheet), whereas some are of partial panels and bad quality (stretched; the ones at the top of the same sheet). Could you please take a look?

0 Likes