Transferring Multiple Zoomed Sheets From VIEW to REPORT in DIAdem

Updated Jun 12, 2023

Environment

Software

  • DIAdem

This article demonstrates how to transfer a zoomed in graphs and sheets in the DIAdem VIEW Panel to the REPORT Panel.
This approach can be used for VIEW layouts that consist of multiple sheets, or if a report must use the same axis scaling as the zoomed view.

Follow the steps below to develop a Visual Basic Script (VBS) that applies a zoom across multiple VIEW sheets and then transfers it to corresponding REPORT sheets.

1. Launch DIAdem.
2. [Optional] If you have a template VIEW layout, load it from the VIEW Panel.
3. From the NAVIGATOR Panel, load your data file.
4. Navigate to the SCRIPT Panel and select File >> New VBS.
5. Define the following variables that will be used throughout the script:
  • i, j and k: To store loop iterations.
  • ChartScales(3): An array of 4 elements to store the x and y axes lower and upper limits.
  • CurrentArea: To store a VIEW Area object.
Option Explicit  'Forces the explicit declaration of all the variables in a script.
Dim i , j, k, ChartScales(3), CurrentArea

6. Pause the script while displaying the VIEW Panel to the user, so that they can apply a zoom.
  • Note: The InteractionOn command pauses the script and displays a dialog. When the user clicks the dialog button, the script continues.
    '---------- Prompt user to adjust VIEW Panel graphs ----------'
    Call WndShow("VIEW", "NORMAL")
    Call InteractionOn("Click to finish zooming")

7. After the zoom is applied, obtain the lower and upper axes limits of the chart Area in the active VIEW sheet.
  • In the following code snippet, a For Loop is used to iterate through each Area in the active VIEW sheet. For each Area, the lower and upper limits of the X and Y axes are stored inside ChartScales.
  • For a VIEW sheet that consists of 1 Area, ChartScales will consist of [Chart1XBegin, Chart1YBegin, Chart1XEnd, Chart1YEnd].
'---------- Get the current zoom/scale for each of the graphs ----------'
'----------ChartScales is an array with the following elements: Chart1XBegin, Chart1YBegin, Chart1XEnd, Chart1YEnd
 j = 0
    For i = 1 to View.ActiveSheet.Areas.Count
      ChartScales(j) = View.ActiveSheet.Areas(i).DisplayObj.XBegin
      ChartScales(j+1) = View.ActiveSheet.Areas(i).DisplayObj.YBegin
      ChartScales(j+2) = View.ActiveSheet.Areas(i).DisplayObj.XEnd
      ChartScales(j+3) = View.ActiveSheet.Areas(i).DisplayObj.YEnd
      j = j+4
    Next

8. Apply the same zoom to all other VIEW sheets and charts.
  • The code snippet below uses a For Loop to iterate through each Sheet and each Area within the current sheet. The X and Y axes limits are set using the SetZoom method.
'---------- Apply zoom/scale to each of the charts in each sheet ----------'
    k = 0
    For i = 1 to View.Sheets.Count
      For j = 1 to View.Sheets(i).Areas.Count
        Set CurrentArea = View.Sheets(i).Areas(j)
        Call CurrentArea.DisplayObj.SetZoom(ChartScales(k), ChartScales(k+1), ChartScales(k+2), ChartScales(k+3), False)
        k = k+4
      Next
      k = 0
    Next
9. Transfer the sheets to the REPORT Panel.
  • The ScriptStart command programmatically runs the script that transfers the current view to a report. This performs the same action as if you were to click File >> Transfer To Report from the VIEW Panel.
  • This script is called for each VIEW sheet, so that the resulting report has the same number of sheets.
'---------- Transfer sheets to report ----------'
  Call Report.Refresh
  
  For i = 1 to View.Sheets.Count
    Call View.Sheets(i).Activate
    Call ScriptStart(ResourceDrv & "VwLayTrans", "VWTransViewRep", False)
    Report.ActiveSheet.Name = View.Sheets(i).Name
  Next

The final script should resemble the following:
Option Explicit  'Forces the explicit declaration of all the variables in a script.
Dim i , j, k, ChartScales(3), CurrentArea

    '---------- Prompt user to adjust VIEW Panel graphs ----------'
    Call WndShow("VIEW", "NORMAL")
    Call InteractionOn("Click to finish zooming")
    
    '---------- Get the current zoom/scale for each of the graphs ----------'
    '----------ChartScales is an array with the following elements: Chart1XBegin, Chart1YBegin, Chart1XEnd, Chart1YEnd
    j = 0
    For i = 1 to View.ActiveSheet.Areas.Count
      ChartScales(j) = View.ActiveSheet.Areas(i).DisplayObj.XBegin
      ChartScales(j+1) = View.ActiveSheet.Areas(i).DisplayObj.YBegin
      ChartScales(j+2) = View.ActiveSheet.Areas(i).DisplayObj.XEnd
      ChartScales(j+3) = View.ActiveSheet.Areas(i).DisplayObj.YEnd
      j = j+4
    Next
   
    '---------- Apply zoom/scale to each of the charts in each sheet ----------'
    k = 0
    For i = 1 to View.Sheets.Count
      For j = 1 to View.Sheets(i).Areas.Count
        Set CurrentArea = View.Sheets(i).Areas(j)
        Call CurrentArea.DisplayObj.SetZoom(ChartScales(k), ChartScales(k+1), ChartScales(k+2), ChartScales(k+3), False)
        k = k+4
      Next
      k = 0
    Next
   
  '---------- Transfer sheets to report ----------'
  Call Report.Refresh
  
  For i = 1 to View.Sheets.Count
    Call View.Sheets(i).Activate
    Call ScriptStart(ResourceDrv & "VwLayTrans", "VWTransViewRep", False)
    Report.ActiveSheet.Name = View.Sheets(i).Name
  Next