4.4.1 Export Graphs/Data/Videos

Export Graphs

Export graphs using Project Explorer folder hierarchy as export path

In this example, we will show how to create the same sub-folder hierarchy according to project folder structure, and export graphs into their own folders named after graph window long name.

Solution for Origin 2016 and later:

doc -e P
	if(page.IsEmbedded==0&&exist(%H)!=11) {//Skip over any embedded graphs or Layout windows
		expGraph type:=jpg filename:="<long name>" path:="<Project Folder><PE Path>" theme:=<Original> tr.Margin:=2;

Solution for Origin 2015 and earlier:

doc -e P //loop over all graph-like objects
	if(page.IsEmbedded==0&&exist(%H)!=11)  //Skip over any embedded graphs or Layout windows
		string proj_path$=%X; //Get windows path of saved project;
		//type "the project path is:"+proj_path$;
		window -a %H;	
		string graph_fullPath$;
		pe_path path:=graph_fullPath$; //Get graph project explorer path;
		string graph_path$=%[%A,>2]; //remove the root folder name from path
		//type "the graph path is:"+graph_path$;
		//type "graph title is:"+%H;
		string path$=proj_path$+graph_Path$; //Concatenate above strings to create export folder;
		expGraph type:=jpg filename:="<long name>" path:=path$ theme:=<Original> tr.Margin:=2;

Export Data

Export all worksheets in all workbooks in all folders as text files

This example is to export all sheets in all workbooks within the project to a specified navigated path and name those data files as "WorkbookName_WorksheetName".

fdlog.openpath(B); // choose directory to store files

doc -e W{   // loop over all workbooks in project
       doc -e LW // loop over all worksheets in workbook
              string temp$ = wks.name$; // Get worksheet short name
           // string temp$ = wks.longname$; // Run this line to get worksheet long name
              expASC type:=text path:=%B%H_%(temp$) shortname:=1; // Export files as .txt files with column short names exported

To loop over current active folder, you can replace doc -e W with doc -ef W. More examples of looping over different objects in Origin can be found here.

Export Videos

Minimum Origin Version Required: 9.0 SR0

This example creates a new matrix book, set its values, and plots the matrix as a contour graph. This process will then loop 50 times and each time the matrix values will be adjusted and the graph updated. Each generated graph will be added to the video as a frame. When finished, a video with 50 frames will have been created.

This example will show you how to change graphs in real-time and use the vw_(object) in Labtalk script to create a video. Change the value "d:\test.avi" to work on your system.

// Create a matrix window
string matbk$;
newbook mat:=1 result:=matbk$;
// Point to matrix object in the sheet
range rmat = [matbk$]1!1;
// Set dimensions values and create a contour plot 
mdim c:=100 r:=100;
double a=1; 
string formula$; formula$="i*sin(a*x)-j*cos(y/a)"; 
msetvalue im:=rmat formula:=formula$; 
wo -p 226 contour; 
// Customize contour plot 
// Choose a codec. Any Four Character Code can be used but
// not all codecs are available on all computers.
// Here are a few examples:
int codec = vw.FourCC(0, 0, 0, 0); // uncompressed
//int codec = vw.FourCC(1, 0, 0, 0); // Microsoft Run Length Encoded
//int codec = vw.FourCC('c', 'v', 'i', 'd'); // Cinepak
//int codec = vw.FourCC('F', 'M', 'P', '4'); // MPEG4
// Create video writer. (fileName, codec, framesPerSec, width, height)
int err = vw.Create(d:\test.avi, codec, 15, 1024, 768);
if( 0 == err )
	for( a=1; a<=1.5; a+=0.01 )
		%C -= 1;
		msetvalue im:=rmat formula:=formula$;
		// Wait for graph window to redraw.
		// This allows watching the animation while creating the video file.
		sec -pw %h;
		// Write graph to video as a single frame.
		err = vw.WriteGraph();
		if( err )
	// Release the video writer.
	if( err )
		type "WriteGraph error $(err)";
	type "VideoWriter Create error $(err).";

Note: For more details about codecs, please refer to FourCC Table.