API capture view of active window

API capture view of active window

jmmarin
Advocate Advocate
1,234 Views
8 Replies
Message 1 of 9

API capture view of active window

jmmarin
Advocate
Advocate

Hello,

 

I have found some posts regarding the capture views directly to the clip board. What I need to do is to capture the active view (I will have show in the active view what I need: maps, geometry, ...). The code I am trying is the following, but it only captures the general view of the structure, not the active window. 

 

I would appreciate some help. 

 

Regards.

 

 

Sub capturaimagenRobot()
' définition d'une vue

Set RobApp = New RobotApplication

RobApp.Interactive = True
RobApp.Visible = True
RobApp.Window.Activate

Dim mavueRobot As IRobotView3 ' this is important to set IRobotView3 if you want to make screen capture of this view
Set mavueRobot = RobApp.Project.ViewMngr.GetView(1) ' it seems CreateView makes this strange affect, use GetView instead

Dim ScPar As RobotViewScreenCaptureParams
Set ScPar = RobApp.CmpntFactory.Create(I_CT_VIEW_SCREEN_CAPTURE_PARAMS)

'ScPar.Name = "Screen capture"
ScPar.UpdateType = I_SCUT_COPY_TO_CLIPBOARD
ScPar.Resolution = I_VSCR_2048
mavueRobot.MakeScreenCapture ScPar

 

ActiveCell.Select
ActiveSheet.Paste
election.ShapeRange.ScaleWidth 0.36, msoFalse, msoScaleFromTopLeft

 

End Sub

0 Likes
Accepted solutions (2)
1,235 Views
8 Replies
Replies (8)
Message 2 of 9

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @jmmarin

 

It is like that because you need to change view number in this \ such line:

 

RobApp.Project.ViewMngr.GetView(1) 



Rafal Gaweda
Message 3 of 9

jmmarin
Advocate
Advocate
Hi Rafal,

Thank you for your reply.

If I put 1 as index, it is always captured the first view in the program, i.e. the “View” sheet of the model.

I think that I need to obtain the “index” of the active window but I do not know how to do it. I know it because if I try 1, I obtain the capture of the main view. Number 2, captures the second view. Number 3, the third one... and so on.
0 Likes
Message 4 of 9

jmmarin
Advocate
Advocate

Hi again,

 

I apologise for the misunderstanding in my previous post. I'm going to explain what I am trying to do. It seems simple, but I am beginner in the API of Robot and it is being impossible for me...

 

I want to generate the captions of certain results all from a Excel spreadsheet

 

In the above VBA code I get the capture of the view number 3 and for the selected cases. I need to do the same but for the active window in the model and for the cases that I specify in the spread sheet

 

For example: I specify in a cell of the spreadsheet that the cases I want to show are "1to10" and execute the macro. This macro must assume "1to10" as cases and capture (to the clipboard) the results which have been selected in the result dialog box the Robot.  

 

I hope to have explain my problem. Thank you.

0 Likes
Message 5 of 9

Rafal.Gaweda
Autodesk Support
Autodesk Support

Hi @jmmarin

 

So you need to check first mavueRobot.Window.IsActive to get actvive window number, then get active view , 

then apply case selection to this view by mavueRobot.Selection.Set(I_OT_CASE).....



Rafal Gaweda
0 Likes
Message 6 of 9

Rafal.Gaweda
Autodesk Support
Autodesk Support
Accepted solution

Hi @jmmarin

 

Sample code to get active view number:

 

Dim ActiveViewNumber As Integer
For i = 1 To Robapp.Project.ViewMngr.ViewCount
    If (Robapp.Project.ViewMngr.GetView(i).Window.IsActive <> 0) Then
        ActiveViewNumber = i
        Exit For
    End If
Next i

Set mavueRobot = Robapp.Project.ViewMngr.GetView(ActiveViewNumber)


Rafal Gaweda
0 Likes
Message 7 of 9

jmmarin
Advocate
Advocate

Thank you again for your patience, Rafal.

 

That portion solves to select the active view.

 

However, what I do not get is to set the group of combinations that I want to show in the graphic. I try the following code, but the graphic always shows the combination that I have selected in the program. I have defined "100to149" but it will be whatever. 

 

I am sure I am missing something due to my lack of practice, so I apologise...

 

 

Set rselection = RobApp.Project.Structure.Selections.Create(I_OT_CASE)
rselection.AddText "100to149" 'For instance

 

Dim RCaseCol As RobotCaseCollection
Set RCaseCol = RobApp.Project.Structure.cases.GetMany(rselection)

 

Dim mavueRobot As IRobotView3
Set mavueRobot = RobApp.Project.ViewMngr.GetView(<<here the variant with the active view>>)

 

mavueRobot.ParamsFeMap.CurrentResult = I_VFMRT_COMPLEX_REINFORCE_BOTTOM_MYY
mavueRobot.ParamsFeMap.Direction = I_VFMLST_AUTOMATIC
mavueRobot.ParamsFeMap.WithDescription = True

 

mavueRobot.Redraw (0)
RobApp.Project.ViewMngr.Refresh

 

 

0 Likes
Message 8 of 9

Rafal.Gaweda
Autodesk Support
Autodesk Support
Accepted solution

Hi @jmmarin

 

As I wrote before ...Selection.Set....

 

Dim ActiveViewNumber As Integer
For i = 1 To Robapp.Project.ViewMngr.ViewCount
    If (Robapp.Project.ViewMngr.GetView(i).Window.IsActive <> 0) Then
        ActiveViewNumber = i
        Exit For
    End If
Next i

Set mavueRobot = Robapp.Project.ViewMngr.GetView(ActiveViewNumber)

Dim CaseSel As RobotSelection
Set CaseSel = Robapp.Project.Structure.Selections.Create(I_OT_CASE)
CaseSel.FromText "100to149"

mavueRobot.Selection.Set I_OT_CASE, CaseSel
mavueRobot.Redraw (0)
Robapp.Project.ViewMngr.Refresh


Rafal Gaweda
Message 9 of 9

jmmarin
Advocate
Advocate

Thank you Rafal.

That is exactly what I needed, and now I have understood which my problem was...

 

 

0 Likes