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
 Center text
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

starman2049

USA
15 Posts

Posted - 03/24/2010 :  6:46:30 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I have added text to a page programatically and I want to be able to have it centered in X how do I do this?

Origin Ver. and Service Release (Select Help-->About Origin): 8.1
Operating System: XP

Penn

China
644 Posts

Posted - 03/24/2010 :  10:00:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

These examples can help.

Penn
OriginLab Technical Services
Go to Top of Page

starman2049

USA
15 Posts

Posted - 03/26/2010 :  5:49:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I checked out the examples - thank you. In my case I am trying to put multiple charts on one page, it could be 1, 2, 3, 4, or more.

I am unable to figure out how to find the proper X of the center of the page, regardless of what layers/charts are present.

Does anyone know how to find the center X of the page?
Go to Top of Page

Penn

China
644 Posts

Posted - 03/29/2010 :  03:49:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can activate your graph, then run the following function.

void page_center_x()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return;
	
	GraphPage gp = gl.GetPage();
	if(!gp)
		return;
	
	Tree tr;
	tr = gp.GetFormat(FPB_ALL, FOB_ALL, true, true);  // get format tree of the graph page
	//out_tree(tr);  // print this format tree
	
	double dWidth = tr.Root.Dimension.Width.dVal;  // get the width of the graph page
	printf("x center=%f\n", dWidth/2);
}

I hope it is what you want.

Penn
OriginLab Technical Services
Go to Top of Page

starman2049

USA
15 Posts

Posted - 04/06/2010 :  1:41:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Penn, thank you.

When I run your code I get width in inches, but the GraphObject.Left expects device units (width is like 6000, I assume to be printer DPI * page width? So how do I get width in a way that I can align a GraphObject?

I want to do the following:

GraphObject go = gl.GraphObjects("TITLE_SAMPLING_RATE");
go.Text = sampleString;
go.Left = gp.SomePropertyToGetWidth*0.9 - go.Width/2;

That should make it look like the text is right-justified at 90% of the page width.

Thanks!
Go to Top of Page

Penn

China
644 Posts

Posted - 04/06/2010 :  9:59:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

The unit of pixel maybe satisfy your requirement. So, the first thing is to set unit to be pixel, and then get the width value. You can try the following code.

void page_center_x()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
		return;
	
	GraphPage gp = gl.GetPage();
	if(!gp)
		return;	

	Tree tr1;
	tr1.Root.Dimension.Units.nVal = 3;  // pixel = 3
	if(0 == gp.UpdateThemeIDs(tr1.Root))
		gp.ApplyFormat(tr1, true, true);  // set unit to pixel

	Tree tr;
	tr = gp.GetFormat(FPB_ALL, FOB_ALL, true, true);  // get format tree of the graph page
	double dWidth = tr.Root.Dimension.Width.dVal;  // get the width of the graph page
	printf("x center=%f\n", dWidth/2);
	
	
	GraphObject go = gl.GraphObjects("TITLE_SAMPLING_RATE");
	go.Text = "sampleString";
	go.Left = dWidth*0.9 - go.Width/2;
}


Penn
OriginLab Technical Services
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