The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 one question about export_all_graphs_to_BMP()
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

tony_lincoln

USA
Posts

Posted - 09/10/2006 :  11:03:00 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

After the curve fitting, I need to save all graphs created by Origin, the BMP name should correspond to my txt file in which there is data for one curve. So I changed the demo codes provided by Origin as the following:

void export_all_graphs_to_BMP(int fileNB, StringArray txtFileFullName)
{
PageBase pgb;
pgb = Project.Pages(); // Get the project's active page
if( pgb.IsValid() )
printf("Active page is of type %d\n", pgb.GetType());
else
printf("Active page is invalid\n");

StringArray BMPFileFullName;
string BMPFileBaseName = "";
string BMPFilePath = getPath(txtFileFullName[0]);

for(int i=0; i < fileNB; i++)
{
txtFileFullName[i] = txtFileFullName[i].Mid(0, lstrlen(txtFileFullName[i])-4);
BMPFileBaseName = getBaseName(txtFileFullName[i]);
BMPFileBaseName.Replace("cut_normalizedCell_ ", "cf_");
string fileName = BMPFilePath +"\\" + BMPFileBaseName + ".BMP";
printf("*****3: %s\n", fileName);
// Mike, until here, the codes still work.

string strFormat = "BMP"; // Width in pixels
int nWidth = 1024; // Get page properties and set height appropriately to// maintain aspect ratio
GraphPage gpg = pgb;
int nHeight = (int) (nWidth * gpg.Dimension.Height.dVal / gpg.Dimension.Width.dVal); // Bits per pixel
int nBitsPerPixel = 8; // Set export file path to be in the User Files folder - change as desired

BOOL bRet = export_page_to_image(fileName, strFormat, pgb, nWidth, nHeight, nBitsPerPixel);
// Report on error
if( !bRet ) printf("Failed to export graph page: %s\n", pgb.GetName());
}

}/////////////////////////////////////////////////////////////////////////////////

Yesterday it can run perfectly and the graph can be saved as BMP with the name corresponding to the txtFileFullName in which there is a curve. But today, when I run the codes again, it says:

....
*****3: C:\data\FittingResults\BMP\cf_132.BMP
Calling members of unattached wrapper class
Calling members of unattached wrapper class
Calling members of unattached wrapper class
Calling members of unattached wrapper class
Command Error!

This means that the last second line of the codes can not work: export_page_to_image(). But why did it work yesterday?!

Thanks in advance.
Tony

Deanna

China
Posts

Posted - 09/11/2006 :  01:26:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The problem seems to be that pgb is not valid. This happens when the active page is not a graph page. I guess yesterday you ran the function when a graph page is activated but today, the active page is not a graph. Please check.

I suggest that the first few lines should be changed to:

PageBase pgb;
pgb = Project.Pages(); // Get the project's active page
if( pgb.IsValid() )
printf("Active page is of type %d\n", pgb.GetType());
else
{
printf("Active page is invalid\n");
return; //Return immediately
}

Then if pgb is not valid, the function will return immediately, without executing the rest part of the function.

Deanna
OriginLab GZ Office

Edited by - Deanna on 09/11/2006 01:28:16 AM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 09/11/2006 :  08:35:59 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Another problem with your version of the example is that you will get fileNB copies of the same BMP rather than fileNB different BMPs. The original code exports all graphs as BMP whereas your code exports the same graph fileNB times.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 09/11/2006 08:37:46 AM
Go to Top of Page

tony_lincoln

USA
Posts

Posted - 09/11/2006 :  1:42:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks. Actually the key method is export_page_to_image(). I put it into the method simple_import_and_fit() that Mike provided several days ago and it works. Thanks a lot!
Tony
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000