Minimum Origin Version Required: Origin8 SR0
void AddLine() { GraphLayer gl = Project.ActiveLayer(); if( gl ) { // add vertical line and set position GraphObject goVLine = gl.CreateGraphObject(GROT_LINE); goVLine.SetName("vline"); goVLine.X = gl.X.From + (gl.X.To - gl.X.From) / 2; // set the init position of vertical line // set direction, script string strScript = "type -a " + " \"X = $(vline.X)\" "; // set this script, moving vertical line will print out X pos to Command window. SetLineFormat(goVLine, LN_VERTICAL, strScript, GRCT_MOVE); // add horizontal line and set position GraphObject goHLine = gl.CreateGraphObject(GROT_LINE); goHLine.SetName("hline"); goHLine.Y = gl.Y.From + (gl.Y.To - gl.Y.From) / 2; // set the init position of horizontal line // set direction, script strScript = "type -a " + " \"Y = $(hline.Y)\" "; // set this script, moving horizontal line will print out Y pos to Command window. SetLineFormat(goHLine, LN_HORIZONTAL, strScript, GRCT_MOVE); } } // set line object properties, script, format, color, width, attach mode, direction... void SetLineFormat(GraphObject& goLine, int nDirection, string strScript, int nExecMode) { goLine.Attach = 2;// 2, layer and scale Tree tr; tr.Root.Span.nVal = 1; // 1 to span over the whole layer tr.Root.Direction.nVal = nDirection; // vertical or horizontal tr.Root.Color.nVal = SYSCOLOR_RED; tr.Root.Width.dVal = 3; tr.Root.Event.nVal = nExecMode; tr.Root.Script.strVal = strScript; // set script, run it after the Event specified by nExecMode if( 0 == goLine.UpdateThemeIDs(tr.Root) ) // 0 means no error { bool bRet = goLine.ApplyFormat(tr, true, true); // return true if applied format successfully } }