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
 labtalk "label" for a page in originC
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

christo2

Germany
Posts

Posted - 09/01/2009 :  07:39:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 8G SR4
Operating System: XP

Hi.
I got a problem with the labeling of a graphpage. I already found the page_insert_label function, but that one doesn't position my label where I want it to be. In Labtalk I used:

win -a graphpage;
label -s -sa -d 5650 450 strLabel;

How do I get this for OriginC at exactly the same position as with Labtalk?

Many thanks,
conny

rlewis

Canada
253 Posts

Posted - 09/01/2009 :  10:42:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try this ...

bool CreateTextLabel(string strLabelName, int PageUnits, int FromLeft, int FromTop, string strLabelText)
{
/*
		Create TextLabel
		Creates a Text label named "strlabelName" at the coordinates FromLeft and FromTop of the active layer
		On success: TextLabel created with the text strLabelText ... Returns true
		On Failure: returns false

*/		
	Layer Layr=Project.ActiveLayer();
	GraphObject gO;
	gO=Layr.GraphObjects(strLabelName);
	if(gO.IsValid()==false)
	{
		gO=Layr.CreateGraphObject(GROT_TEXT);
		gO.SetName(strLabelName);
	}
	else
	{
		string strObjType=gO.GetObjectType();
		strObjType.TrimLeft();
		strObjType.TrimRight();
		if(strObjType.CompareNoCase("Text")!=0)
		{
			return (false);
		}
	}
	gO.Text=strLabelText;
	gO.Left=FromLeft;
	gO.Top=FromTop;
	return (true);
}
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 09/01/2009 :  10:45:24 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Correction ...

bool CreateTextLabel(string strLabelName, int FromLeft, int FromTop, string strLabelText)
{
/*
		Create TextLabel
		Creates a Text label named "strlabelName" at the coordinates FromLeft and FromTop of the active layer
		On success: TextLabel created with the text strLabelText ... Returns true
		On Failure: returns false

*/		
	Layer Layr=Project.ActiveLayer();
	GraphObject gO;
	gO=Layr.GraphObjects(strLabelName);
	if(gO.IsValid()==false)
	{
		gO=Layr.CreateGraphObject(GROT_TEXT);
		gO.SetName(strLabelName);
	}
	else
	{
		string strObjType=gO.GetObjectType();
		strObjType.TrimLeft();
		strObjType.TrimRight();
		if(strObjType.CompareNoCase("Text")!=0)
		{
			return (false);
		}
	}
	gO.Text=strLabelText;
	gO.Left=FromLeft;
	gO.Top=FromTop;
	return (true);
}

Go to Top of Page

christo2

Germany
Posts

Posted - 09/01/2009 :  1:15:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!!! It worked like a charm!! (well the boolean didn't want to, but hey, it's at the very end of my program, so i don't care)!
Just another quick question: How do I set the fontsize?

conny
Go to Top of Page

rlewis

Canada
253 Posts

Posted - 09/01/2009 :  8:28:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The following combination of OC functions should do ...

bool CreateTextLabel(string strLabelName, int FromLeft, int FromTop, string strLabelText, int TypeFace=-1, int FontSize=-1)
{
/*
		Create TextLabel
		Creates a Text label named "strlabelName" at the coordinates FromLeft and FromTop of the active layer
		TypeFace > 0  ... Alters the Typeface to the new value
		FontSize > 0  ... Alters the FontSize to the new value
		On success: TextLabel created with the text strLabelText ... Returns true
		On Failure: returns false

*/		
	Layer Layr=Project.ActiveLayer();
	GraphObject gO;
	gO=Layr.GraphObjects(strLabelName);
	if(gO.IsValid()==false)
	{
		gO=Layr.CreateGraphObject(GROT_TEXT);
		gO.SetName(strLabelName);
	}
	else
	{
		string strObjType=gO.GetObjectType();
		strObjType.TrimLeft();
		strObjType.TrimRight();
		if(strObjType.CompareNoCase("Text")!=0)
		{
			return (false);
		}
	}
	gO.Text=strLabelText;
	SetFontProperties(gO, TypeFace,FontSize);
	gO.Left=FromLeft;
	gO.Top=FromTop;
	return (true);
}

bool GetFontInfo(GraphObject gO, int &TypeFace, int &FontSize)
{
	if (gO.IsValid()==true)
	{
		string strObjType=gO.GetObjectType();
		strObjType.TrimLeft();
		strObjType.TrimRight();
		if(strObjType.CompareNoCase("Text")!=0)
		{
			return (false);
		}
		Tree trFormat;
		trFormat = gO.GetFormat(FPB_ALL	,FPB_ALL,TRUE,TRUE);
		TypeFace=trFormat.Root.Font.Face.dVal;
		FontSize=trFormat.Root.Font.Size.dVal;
		return (true);
	}
	return (false);
}

bool SetFontProperties(GraphObject &gO,  int TypeFace=-1, int FontSize=-1)
{
	if(gO.IsValid()==true)
	{
		string strObjType=gO.GetObjectType();
		strObjType.TrimLeft();
		strObjType.TrimRight();
		if(strObjType.CompareNoCase("Text")!=0)
		{
			return (false);
		}
		Tree trFormat;
		trFormat = gO.GetFormat(FPB_ALL	,FPB_ALL,TRUE, TRUE);
		if(TypeFace>=0)
		{
			trFormat.Root.Font.Face.dVal=TypeFace;
		}
		if(FontSize>0)
		{
			trFormat.Root.Font.Size.dVal=FontSize;
		}
		gO.ApplyFormat(trFormat,true,true);
		return (true);
	}
	return (false);
}
Go to Top of Page

Iris_Bai

China
Posts

Posted - 09/02/2009 :  01:54:08 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I cleanup rlewis's example functions above to wiki page http://ocwiki.originlab.com/index.php?title=Category:GraphObject%28Examples%29
And we will support more examples about Graph Object later.

Iris
Go to Top of Page

christo2

Germany
Posts

Posted - 09/02/2009 :  05:22:28 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!! Thant one really does it. And I found out, why the bool didn't work (it was too late and I copied it into my program....)

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