Global custom method

In perspective I know I can create a custom method at root and call that in any of my components within that view.

Is it possible to call a custom method to multiple views? or would I have to create that method for each view independently

Sounds like you just want to create a script module. Is there any particular reason it NEEDS to be attached as a custom method on the root?

1 Like

It does not have to be attached on root. I just know from previous work that it works on root. But I am not sure how to create a global method that I can use across multiple views within a project

In the top left of designer click “Scripting” and then “Project Library”. Right click and select “New Script”, give it a name, for example I will use myTestScript. Make a function that does what you want

def myFunction(your arguments here):
    # your script here

Then, im not sure what you want to trigger this script, but you simply do

import myTestScript

myTestScript.myFunction()

to call it.

If its on a root property change it would look like

import myTestScript

if event.propertyName == 'someProperyName':
    myTestScript.myFunction()

Thank you [bkarabinchak.psi] I will give this a try

A small clarification - you actually most likely don’t want to explicitly import the myTestScript - it will be available automatically, and explicitly importing can lead to issues with stale code.

1 Like

Learn something new everyday