Some solutions require a great deal of complexity. In such cases, it makes sense to use ExternalFunction. Here, we locate parts of the code as an .xml file in the plugin and then call it by its name in the module. This is handy if the solution requires to do something in the document several times. Using this approach, it is possible to have an external function that accepts several parameters.
How to configure
The external function must be an .xml file that should be located in this path:
...\Plugins\SkabelonDesign.ALang\Configuration
To call the external function, insert the line below inside your ALang command in the module:
<ExternalFunction name="X"/>
X
refers to the name of the .xml file located in the Configuration folder. In this line, you are able to define parameters as variables to be called in the external function.
The .xml file must only contain what should happen. This means, you should not define that it is a button nor insert the command for ALang.
Variables
All parameters added to the call will be stored as variables. This means that they can be referred to in the external function either in the place of variables or as $variableName$
. The last one enable us to define a variable with a value in the module that can be called in the external function. Let's say that this variable is called shapeName
and has "Shape1" as value. By making use of $
, we target this variable, and thereby its value. In that case, it should be defined as $shapeName$
.
Example of usage
The example below is an extract from RegionH's solution. This example shows a scenario where it is beneficial to use an external function as it should execute the same operation to different shapes. Take a look at RegionH to see the entire case.
Firstly, the module calls the external function called "Frontpage" and defines variables to be used:
<Button label="Forside Type 1" icon="GroupInsertPages">
<Cmd case="SkabelonDesign.ALang:execute">
<ExternalFunction name="Frontpage"
showShapeNameContains="_A_"
colorAccent1="Accent4"
colorAccent2="Accent1"
titleAccent="lt1"
/>
</Cmd>
</Button>
The .xml file "Frontpage" contains this code:
<ForEach name="Shape" source="Document.Shapes">
<If source="Shape.Name" contains="$showShapeNameContains$">
<True>
<Show target="Shape"/>
<If source="Shape.Name" contains="_ColorAccent">
<True>
<If source="Shape.Name" contains="_ColorAccent1_">
<True>
<Color target="Shape.Fill" accent="$colorAccent1$"/>
</True>
</If>
<If source="Shape.Name" contains="_ColorAccent2_">
<True>
<Color target="Shape.Fill" accent="$colorAccent2$"/>
</True>
</If>
</True>
</If>
</True>
<False>
<Hide target="Shape"/>
</False>
</If>
</ForEach>
<Color target="Document.Styles[Forside - Titel].Font" accent="$titleAccent$"/>
<Color target="Document.Styles[Forside - Undertitel].Font" accent="$titleAccent$"/>
At first, the external function will go through each shape in the document. If the name of the shape contains the value from the variable showShapeNameContains
, which is"_A_", it will show the shape concerned. Afterwards, it will check whether the shape name contains "_ColorAccent". If that turns out to be true, it will further check if the shape name contains "_ColorAccent1_". If so, the fill color in the shape is changed to the accent defined in the variable colorAccent1
. Likewise, if the shape name contains "_ColorAccent2_", the fill color in that shape is changed to the accent defined in the variable colorAccent2
. If the name of a shape does not contain "_A_", the certain shape will be hidden.
Lastly, the external function will target the font of the styles "Forside - Titel" and "Forside - Undertitel" and change the color to the accent defined in titleAccent
.
Comments
0 comments
Article is closed for comments.