Add expression functions for perspective

@PGriffith
I try to understand the minimum requirement to add some expression function for perspective only.

With a module for Vision/Designer/Gateway scope, configureFunctionFactory in the module Hook enable to add some expression function for all scope
Expression functions added are available to prespective too.
I suppose this is due to Designer hook configureFunctionFactory ans gateway Hook configureFunctionFactory ?

But if I want to create a module for Gateway/Perspective only and add some expression Function, do I need to use only the GatewayHook and the DesignerHook ?
what are the dependency to use in the Gateway project, designer project ?

designer project pom:

        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>client-api</artifactId>
            <version>${ignition-sdk-version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>designer-api</artifactId>
            <version>${ignition-sdk-version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>vision-designer-api</artifactId>
            <version>${ignition-sdk-version}</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

client-api is required for vision or perspective or both

build pom

                  <projectScopes>
                        <projectScope>
                            <name>Utils-gateway</name>
                            <scope>G</scope>
                        </projectScope>
                        <projectScope>
                            <name>Utils-common</name>
                            <scope>CDG</scope>
                        </projectScope>
                        <projectScope>
                            <name>Utils-designer</name>
                            <scope>CD</scope>
                        </projectScope>
                    </projectScopes>

                    <!--> pour perspective-->
                    <depends>
                        <depend>
                            <scope>G</scope>
                            <moduleId>com.inductiveautomation.perspective</moduleId>
                        </depend>
                        <depend>
                            <scope>D</scope>
                            <moduleId>com.inductiveautomation.perspective</moduleId>
                        </depend>
                    </depends>


                    <hooks>

                        <hook>
                            <scope>D</scope>
                            <hookClass>com.bouyguesenergiesservices.ignition.designer.utils.DesignerHook</hookClass>
                        </hook>

                        <hook>
                            <scope>G</scope>
                            <hookClass>com.bouyguesenergiesservices.ignition.gateway.utils.GatewayHook</hookClass>
                        </hook>
                    </hooks>

After few tests For Perspective:

If I add GatewayHook::configureFunctionFactory, it’s enough to be able to execute function expression for gateway tag expression and in the designer !
Nevertheless, without DesignerHook::configureFunctionFactory the expression is not listed in the designer expression popup…

GatewayHook::initializeScriptManager is enought to execute script in the designer and to have auto-completion for added script function.
DesignerHook::initializeScriptManager is not usefull in this case.

To run and design in Perspective, you only need to configure a GatewayHook; the DesignerHook is only necessary for loading specific designer customizations (e.g. a custom project browser node). Expression editors should fetch the autocompletion information from the relevant scopes in the designer without having to load anything manually.

with Ignition 8.1.1, it’s ok for script function added with GatewayHook::initializeScriptManager,

GatewayHook::configureFunctionFactory

	@Override
	public void configureFunctionFactory(ExpressionFunctionManager factory) {
		factory.getCategories().add(FUNCTION_CATEGORY);
		factory.addFunction(FUNCTION_EVAL_EXPRESSION, FUNCTION_CATEGORY, new EvalExpressionFunction());
		factory.addFunction(FUNCTION_SUBSTRING_BEFORE, FUNCTION_CATEGORY, new FunctionSubstringBefore());
		factory.addFunction(FUNCTION_SUBSTRING_AFTER, FUNCTION_CATEGORY, new FunctionSubstringAfter());
		factory.addFunction(FUNCTION_COUNT_MATCHES, FUNCTION_CATEGORY, new FunctionCountMatches());
		factory.addFunction(FUNCTION_SPLIT_LIMIT, FUNCTION_CATEGORY, new FunctionSplitLimit());
		factory.addFunction(FUNCTION_SPLIT_GET_INDEX, FUNCTION_CATEGORY, new FunctionSplitGetIndex());
		super.configureFunctionFactory(factory);
	}

but for expression function, I have to add a DesignerHook::configureFunctionFactory if I want to see the added function in the Menu.

I’ll try with restarting the gateway after module upload, not only the designer.

Oh, looks like I’m wrong; Perspective has some somewhat convoluted logic to double-register ‘fake’ expression functions in the designer scope. That’s silly, but I’ll assume there’s a valid reason. If you wanted something to just be available to Perspective (but not show up in the rest of the designer’s auto completion) I’m not sure you can…let me take a look.

EDIT: No, it doesn’t look like you can.

Yes with designer Hook expression functions are both listed in designer vision and designer perspective sub system. That’s fine for my use case, despite it could be confusing in some case.

1 Like