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
 Special or Custom tick labels using VBA
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

speicherm

2 Posts

Posted - 07/18/2016 :  2:39:23 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2016 b9.3.2.303
Operating System: Windows 7

I am trying to get OriginPro to add custom labels to the beginning and end ticks of the y-axis. I created a "custom.c" file and used the following VBA code in MS Excel to "link" it to OriginPro:

app.Execute ("run.addOC(X:\folder\custom.c);") 'build and link the custom functions that i created to add special ticks


The code for the custom.c is as follows:

void SetSpecialTicks(string strFirst, string strLast) {
GraphLayer gl = Project.ActiveLayer();
if(!gl) return;

Tree trFormat;
trFormat = gl.GetFormat(FPB_ALL, FOB_AXIS_LABELS, TRUE, TRUE);
trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.Begin.Type.nVal = 3;
trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.End.Type.nVal = 3;
trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.Begin.Label.strVal = strFirst;
trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.End.Label.strVal = strLast;

int iError = gl.UpdateThemeIDs(trFormat.Root, "", "");
gl.ApplyFormat(trFormat, TRUE, TRUE);
}


This code worked in prior versions of OriginPro but does not work in OriginPro 2016. This may have something to do with "custom" tick labels are now called "special" in 2016. Does anyone know how to get this to work? Or another way to specify the special labels via Excel/VBA.



Matthew Speicher

easwar

USA
1965 Posts

Posted - 08/05/2016 :  5:36:29 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Matthew,

Yes, you are correct. This area has changed. We will provide an updated example soon.

Easwar
OriginLab
Go to Top of Page

minimax

354 Posts

Posted - 08/08/2016 :  03:00:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Matthew,

Your code should still work, we will fix it in the next Origin 2017 version.

On the other hand, as a workaround for Origin (>=2015), following code is recommended.
void SetSpecialTicks2(string strFirst, string strLast)
{
	GraphLayer gl = Project.ActiveLayer();
	if(!gl) return;

	Tree trFormat;
	trFormat.Root.Axes.Y.Specials.LeftSpecials.SpecialCount.nVal = 2;
	trFormat.Root.Axes.Y.Specials.LeftSpecials.Specials.Special1.Type.nVal = SAT_LABEL;
	trFormat.Root.Axes.Y.Specials.LeftSpecials.Specials.Special1.Label.strVal = strFirst;
	trFormat.Root.Axes.Y.Specials.LeftSpecials.Specials.Special2.Type.nVal = SAT_LABEL|SAT_POS_END;
	trFormat.Root.Axes.Y.Specials.LeftSpecials.Specials.Special2.Label.strVal = strLast;
	
	int iError = gl.UpdateThemeIDs(trFormat.Root, "", ""); 
	int nRet = gl.ApplyFormat(trFormat, TRUE, TRUE); 
}


Max
OriginLab
Go to Top of Page

minimax

354 Posts

Posted - 08/09/2016 :  06:21:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Matthew,

We found it is hard to fix your original code based on the imperfect theme apply mechanism.

A general rule is that we should avoid calling GetFormat() and ApplyFormat() in a same function.

You can use GetFormat() to figure out how the treenode should look like and then set the individual node values. (it is also how we write code ourselves)

But it is recommended that you comment out that line after you test pass.

That is to say, following code should work in Origin 2016.
void SetSpecialTicks(string strFirst, string strLast)
{ 
	GraphLayer gl = Project.ActiveLayer();
	if(!gl) return;

	Tree trFormat;
	//trFormat = gl.GetFormat(FPB_ALL, FOB_AXIS_LABELS, TRUE, TRUE); 	//comment out after you test successfully
	trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.Begin.Type.nVal = 3; 
	trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.End.Type.nVal = 3; 
	trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.Begin.Label.strVal = strFirst; 
	trFormat.Root.Axes.Y.Labels.LeftLabels.Custom.End.Label.strVal = strLast; 

	int iError = gl.UpdateThemeIDs(trFormat.Root, "", ""); 
	gl.ApplyFormat(trFormat, TRUE, TRUE); 
}



PS1: theme tree is quite large, so GetFormat() is not fast, comment it out can have better performance as well.

PS2: The reason is that the tree will contain many node values after GetFormat().
One of them is the special tick count (new in Origin 2016), which is 0.
On applying, the tick count node (new) is applied after those custom tick nodes (old).
So it becomes no custom ticks finally.

Hope it is clearer now.

Max
OriginLab
Go to Top of Page

speicherm

2 Posts

Posted - 09/06/2016 :  4:08:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks for the responses. I will try and update my code. My current workaround was to use an old computer with an older version of Origin.

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