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

cm432

2 Posts

Posted - 07/18/2011 :  08:51:24 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I'm trying to format colormap surface and contour colorfill plots. I want to make the color scale or spectrum1 visible on the plots using c and then place it in the upper right hand corner of the plot. Can you please tell me the command to make SPECTRUM1 visible on the plots and also if there's a way to automatically position them as well? Thank you!

Penn

China
644 Posts

Posted - 07/19/2011 :  04:52:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Actually, the SPECTRUM1 is a graph object, that is to say, you can use the GraphObject to control SPECTRUM1. If you want to remove the SPECTRUM1 from the graph layer, please use the RemoveGraphObject method. If the SPECTRUM1 does not exist in the layer, use the following line to add it.

LT_execute("spectrum;");  // add spectrum1

The code below is used to set the SPECTRUM1 position.

void layer_set_spectrum1()
{
	GraphLayer gl = Project.ActiveLayer();  // get the active graph layer
	if(!gl)
		return;
	
	GraphObject go = gl.GraphObjects("spectrum1");  // get the spectrum1
	if(!go)  // if the spectrum1 not exist
	{
		LT_execute("spectrum;");  // add spectrum1
		go = gl.GraphObjects("spectrum1");  // get spectrum1
	}
	// set position of spectrum1
	go.X = 0;
	go.Y = 0;
	// refresh the graph
	gl.GetPage().Refresh();
}

Also, you can get more examples on setting colormap.

Penn
Go to Top of Page

cm432

2 Posts

Posted - 07/19/2011 :  09:59:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much, that was exactly what I needed. I was also trying to run this for every graphpage in the project. It doesn't work for every graphpage and I get an error "Calling members of unattached wrapper class" sometimes. Do you know how I can fix this? I was using the following code:

foreach( GraphPage gp in Project.GraphPages )
{
foreach( GraphLayer gl in gp.Layers )
{
//Add Color Spectrum
if( gp.IsValid() )
{
GraphObject go = gl.GraphObjects("spectrum1"); // get the spectrum1
//if (gl.GraphObjects("spectrum1") == NULL)
if(!go) // if the spectrum1 not exist
{
LT_execute("spectrum;"); // add spectrum1
go = gl.GraphObjects("spectrum1"); // get spectrum1
// set position of spectrum1
if (gl.GraphObjects("YR") == NULL)
{
go.X = 65;
go.Y = 25;
}
else
{
go.X = 165;
go.Y = 0;
}
}
}

// refresh the graph
gl.GetPage().Refresh();
}
}
Go to Top of Page

Penn

China
644 Posts

Posted - 07/20/2011 :  03:12:42 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Please note that, LT_execute("spectrum;") only adds SPECTRUM1 to the active graph layer. In your code, I suppose there are two graph layers in the graph page which you want to loop over. If the active layer is layer one, when the loop is going to layer two, LT_execute("spectrum;") will add SPECTRUM1 to layer one, and go = gl.GraphObjects("spectrum1") cannot get SPECTRUM1 from layer two. That is to say, go is NULL. And then, when you try to set the position of SPECTRUM1 by go, the error happens.

So, you can change the line LT_execute("spectrum;"); to

gl.LT_execute("spectrum;"); // add spectrum1


Otherwise, you can activate the layer before LT_execute.

set_active_layer(gl);  // activate the graph layer
LT_execute("spectrum;"); // add spectrum1



Penn
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