OriginLab Corporation - Data Analysis and Graphing Software - 2D graphs, 3D graphs, Contour Plots, Statistical Charts, Data Exploration, Statistics, Curve Fitting, Signal Processing, and Peak Analysis                     
 
Skip Navigation Links
All BooksExpand All Books
Quick HelpExpand Quick Help
ProgrammingExpand Programming

4.10 FAQ-369 How do I loop over various objects in my script?

Last Update: 2/3/2015

The document command can be used for looping over objects. The -e switch allows for the user to specify the object to loop over. The -ef switch restricts the loop to the current folder.

This example loops over all Workbooks and then all Worksheets (Layers) and then picks up a particular row of a column with a particular long name:

// Loop over all books
doc -e W {
   // Put book name into a string variable - could just use %h
   book$ = %h;
   type "Book is: %(book$)";
   // loop over all sheets
   doc -e LW {
      // Put sheet name into variable
      sheet$ = layer.name$;
      type "Sheet is: %(sheet$)";
      // (Re)Define a range to point to the column with long name
      // "system pressure"
      range r = [%(book$)]%(sheet$)!col(system pressure);
      // Get row 5 of col "system pressure" of current sheet of
      // current book
      double d = r[5];
      // check if missing value
      if( d != 0/0 )
         type "system pressure row 5 = $(d)";
   }
}

Keywords:page, layer, column, row, folder, worksheet, workbook, matrix

 

© OriginLab Corporation. All rights reserved.