1.113 FAQ-663 How to specify the graph size by using LabTalk Script?

Last Update: 10/18/2016

This page will introduce what can be used to control the physical dimensions of a plot.

There are four Page properties that Origin gets from the current printer that relate to the physical size of Graph window (when printed):

• PAGE.WIDTH - The physical width of the page in printer dots
• PAGE.HEIGHT - The physical height of the page in printer dots
• PAGE.RESX - The horizontal dots-per-inch resolution of the printer
• PAGE.RESY - The vertical dots-per-inch resolution of the printer

Using the above properties, we can determine the physical size of a page:

• WidthInInches = PAGE.WIDTH/PAGE.RESX;
• HeightInInches = PAGE.HEIGHT/PAGE.RESY;

The Layer can be set to use units of:

• % of Page
• Inch
• cm
• mm
• Pixel
• Point
• Windows (inch)

so we can read or write the dimensions of a layer as we wish:

layer.unit = 3; // Set a layer to units of cm
WidthInCM = layer.width; // Read the width in cm
layer.unit = 2; // Set a layer to units of Inches
layer.height = 6.5; // Set a layer to 6.5 inches tall
//Combining this information, we can set a graph to unit aspect ratio with this script:
layer.unit = 2;
dwidth = x2 - x1;
dheight = y2 - y1;
if(dwidth/dheight > 1)
{
layer.height = layer.width * dheight / dwidth;
}
else
{
layer.width = layer.height * dwidth / dheight;
}

//Here is code which 'centers' a layer:
layer.top = (page.height / page.resy - layer.height)/2;
layer.left = (page.width / page.resx - layer.width) / 2;

With a little work, you should be able to produce graphs with true dimensions and/or accurate scales.

Keywords:Graph Size