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

Shemini

USA
11 Posts

Posted - 07/22/2010 :  1:28:24 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin8 SR6
Operating System: Windows7

I have a custom button to format graphs and I want it to check if the plots have been grouped. I can only get this to function if in fact they have been grouped. I would like to know if there is a way to have the code find out if there are any groups and have it move on without errors if there are not any groups. It seems like there should be some method for checking this.

The reason for wanting this is because I would like the code to perform a different function in the case where they have been grouped than if they have not.

Please let me know if there is a way to check for groups when there are none without the code giving errors.

Thank you

Penn

China
644 Posts

Posted - 07/22/2010 :  10:39:14 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

You can use the try-catch to handle with error and exception. For example:

void testGroupPlot()
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl)
	{
		out_str("Please activate a graph layer!");
		return;
	}

	try
	{
		GroupPlot gplot = gl.Groups(0);
		out_str("Has Group!");
	}
	catch(int iErr)
	{
		out_str("Has no Group!");
		printf("Error No. is %d.\n", iErr);
	}
	
	out_str("Out of try-catch!");
}


Penn
Go to Top of Page

Shemini

USA
11 Posts

Posted - 08/02/2010 :  7:22:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Penn, that did the trick. One more question, given a curve in a GraphLayer, is there a way to find the worksheet column label (long name)? I found a function made for finding the worksheet column name (short name) but I need the long name cause that seems to be more consistent, it doesn't get cut short.

Thanks again,
Shemini
Go to Top of Page

Penn

China
644 Posts

Posted - 08/02/2010 :  9:59:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Shemini,

To get the Long Name, you can use the Column::GetLongName method. So, we should first get the column from the data plot in the graph layer. Here we need to use the following methods: DataPlot::GetDataRange, XYRange::GetXColumn and XYRange::GetYColumn.

The example below will be helpful.

void testGetLongName()
{
	GraphLayer gl = Project.ActiveLayer();  // get the active graph layer
	if(gl)
	{
		foreach(DataPlot dp in gl.DataPlots)  // loop all data plots in the active graph layer
		{
			XYRange xy;  // xy range of the data plot
			Column xCol, yCol;  // xy columns of the data plot
			
			// get xy range and xy columns of the data plot
			if(dp.GetDataRange(xy) && xy.GetXColumn(xCol) && xy.GetYColumn(yCol))
			{
				string strXLongName, strYLongName;
				strXLongName = xCol.GetLongName();  // get long name of x column
				strYLongName = yCol.GetLongName();  // get long name of y column
				out_str("Long Name of Column X:"+strXLongName);
				out_str("Long Name of Column Y:"+strYLongName);
			}
		}
	}
}


Penn
Go to Top of Page

Shemini

USA
11 Posts

Posted - 08/03/2010 :  10:29:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Penn,

That did the trick. Thank you very much.

Shemini
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