2.2.4.32.2 OriginObject::ApplyFormat

Description

Apply format stored in theme file to object


Apply format stored in tree to object

Syntax

BOOL ApplyFormat( LPCSTR lpcszXMLPath, BOOL bRepaint = TRUE, BOOL bRelative = FALSE, BOOL bUndo = FALSE, vector<int> * piaErrors = NULL, vector<string> * psaErrors = NULL )


BOOL ApplyFormat( const TreeNode & trNode, BOOL bRepaint = TRUE, BOOL bRelative = FALSE, BOOL bUndo = FALSE, vector<int> * piaErrors = NULL, vector<string> * psaErrors = NULL )

Parameters

lpcszXMLPath
[input]path of XML theme file
bRepaint
[input]if TRUE object will be repainted when format is applied
bRelative
if TRUE, it will be considered relative to that object
bUndo
whether to apply undoably, or not.
piaErrors
[optional][output] Array of errors. See OTHEMEERROR for possible values. If neither piaErrors nor psaErrors is used errors will be dumped into the script window.
psaErrors
[optional][output] Array of error strings. See E_STR_THEME_ERROR_* for possible strings. If neither piaErrors nor psaErrors is used errors will be dumped into the script window.


trNode
[input] The tree containing format information
bRepaint
[input] if TRUE object will be repainted when format is applied
bRelative
[input] if TRUE tree will be considered relative to that object
bUndo
whether to apply undoably, or not.
piaErrors
[optional][output] Array of errors. See OTHEMEERROR for possible values. If neither piaErrors nor psaErrors is used errors will be dumped into the script window.
psaErrors
[optional][output] Array of error strings. See E_STR_THEME_ERROR_* for possible strings. If neither piaErrors nor psaErrors is used errors will be dumped into the script window.

Return

Examples

EX1

// Graph should exist with ticks facing outward
// After running example, ticks will face inward
void OriginObject_ApplyFormat_Ex1()
{
    GraphPage gp = Project.GraphPages(0);
    gp.ApplyFormat("themes\\graph\\Ticks All In.OTH");
}


EX2

// In a new project, import some data and make two graphs of the same type
// Modify the first graph created in any way you like
// Run the example. The second graph will get the modifications of the first.
void OriginObject_ApplyFormat_Ex2()
{
    GraphPage pg1 = Project.GraphPages(0);
    GraphPage pg2 = Project.GraphPages(1);
    Tree tr;
    tr = pg1.GetFormat();
    pg2.ApplyFormat(tr);
}

EX3

// following code will set properties of a given Rect object
void OriginObject_ApplyFormat_Ex3(string strName = "Rect")
{
    GraphLayer gl = Project.ActiveLayer();
    GraphObject gg =  gl.GraphObjects(strName);
    if(gg)
    {
        Tree tr;                
        tr.Root.Fill.Color.nVal = -4; // this value corresponds to transparent, or NONE in dialog
        tr.Root.Fill.Pattern.Style.nVal = 6;
        tr.Root.Fill.Pattern.UseBorderColor.nVal = 0;// independent color for fill pattern lines
        tr.Root.Fill.Pattern.PatternColor.nVal = 6; // yellow
        tr.Root.Fill.Pattern.Width.dVal = 0.1; // fill pattern line width
        tr.Root.Fill = tr.Root.Border;
          
        int nErr = gg.UpdateThemeIDs(tr.Root);
        if(0 == nErr)
            gg.ApplyFormat(tr, true, true);
    }
}

Note

If you use the same tree to get and apply format, please note that: changing some setting will possibly make some other setting outdated.

The correct way is to apply setting changed by purpose only and the relative setting will automatically update. Example

See Also

OriginObject::CopyFormat,OriginObject::GetFormat,OriginObject::UpdateThemeIDs

Header to Include

origin.h