T O P I C R E V I E W |
speicherm |
Posted - 07/18/2016 : 2:39:23 PM 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 |
4 L A T E S T R E P L I E S (Newest First) |
speicherm |
Posted - 09/06/2016 : 4:08:44 PM 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.
|
minimax |
Posted - 08/09/2016 : 06:21:03 AM 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 |
minimax |
Posted - 08/08/2016 : 03:00:33 AM 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 |
easwar |
Posted - 08/05/2016 : 5:36:29 PM Hi Matthew,
Yes, you are correct. This area has changed. We will provide an updated example soon.
Easwar OriginLab
|
|
|