Scripting libraries for V8 and V7.9

where to include external jar files in Ignition lib folder? If the library is required by both gateway as well as client scope then where to put them ? (In “common” folder under lib?) After copying the jar in appropriate folder do we need to restart Ignition?

I intend to import these libraries in jython. I had kept them in gateway folder but it gives error “No module named …”

Also if I want to import some global libraries e.g. “com.google.gson” in my jython script , will it import them from the Internet?

In version 7.9 designer, there were gateway event scripts and client event scripts under projects node where as in 8 there is only gateway scripts. The client event scripts seem to be moved to vision node and perspective nodes respectively. Is that correct? Hope the gateway event scripts are specific to each project and they start/stop on each project start/stop event?

In version 7.9 and the IU course on scripting,there was a concept of shared scripts and project scripts, in version 8 there is only project library, so does it mean shared scripts across projects is not supported in version 8? Just a clarification.

Shared scripts are absolutely supported in 8.0, you just need to make sure that the script you would like shared is located in the parent project. 8.0 does NOT support sharing scripts between projects if there is not inheritance, so if ParentProjectA has a script, and ChildProjectA is a descendant of ParentProjectA, then ChildProjectA has access to the script (and can also override the script if needed). ChildProjectB - which is not a descendant of ParentProjectA - will not be able to access the script.

Client scripts are a Vision concept, and Session scripts are a Perspective concept, so yes, both concepts only live in their respective context. Gateway event scripts ARE specific to each project, BUT they can also be inherited. If you have ParentProjectA which has a Gateway Script which increments a tag every ten seconds, and you have ChildProjectA and ChildProjectAA which are both descendants of ParentProjectA, then that tag will get incremented twice every ten seconds (once for each child, zero times from the parent since inheritable projects are not runnable), so be careful how you use inheritable gateway scripts.

3 Likes

Makes sense.

Got it. However, why would anyone inherit a project from another project! Generally each project will be independent of each other I guess!

While each project should be independent, there are many instances when logic (scripts, Reports) is/are identical across projects, and there are also instances where content (Views, Styles, Windows) can be shared across Projects.

My projects, for example, all inherit from a project named “global”. I happen to want all of my projects to be aesthetically identical, with only their content and logic to be different. To accomplish this I perform ALL of my Style customization in the “global” project, and then all of my descendant projects have the same Styles available to them; if I need to make a change and push it out to al projects, I perform the change in one place. As you can imagine, this same “one point of truth” principal applies to all resources in the inherited project. If for some reason I decide I want one project to use a different color, but keep all of the other properties in a Style, I can just override the inherited resource without affecting any other projects.

This is also very useful for Named Queries!

1 Like

Understood. The concepts of inheritance can be applied to projects as well with this approach.

The Timer (gateway) is enabled/disabled thru the script playground using dialog box while defining it, but how to start/stop the timer script thru script or a tag change event ?

You could easily make a check against a tag value at the start of the Timer script. It won’t stop the script from executing, but it would prevent the internal logic from executing.

If you’re attempting to enable/disable the script entirely, there is currently no way to bind Gateway scripts to any value.

OK fine. So the timer will be active while gateway is started , but I need to by pass the logic on a tag value to simulate as if the timer is not running.

Also how to force the gateway startup script run? It runs only when I change a startup script and save. Is there any other way?

It's a gateway startup script. Restart your gateway and it'll run. (-:

2 Likes

If you really need it while testing, put all of your gateway startup logic in a project script module function. Then the gateway startup script just calls that function. And you can define a tag change event that also calls that function, which you can trigger to your heart’s content.

1 Like

Restarting gateway is too brute force approach. I have some initialization stuff to be done at start of the project (e.g. initializing some global parameters or reading a small init file once at start of the project). I have put this in gateway startup script. There is no project startup script in version 8. So restarting gateway every time during testing phase is not practical. Also I don't know how to restart the gateway? In <8 version it was from GCU console, but that's slow and sledgehammer for killing fly approach.

I think that's more practical. I can call an init function on a button click which changes a tag to run the init.

Agreed. I'm pretty sure that's why pturmel added the " (-: "

2 Likes

Can I import one project in to another? This is required as I want my scripts and a few control tags to be imported from my sample project in to a user project.

Is there any other way of exporting my scripts (both project and global) in to user projects.Basically I am trying to find best way to distribute my scripts to users.

No, you can’t import one project into another.

If you have scripts that you want the scripts to be in the user project, you have two avenues:

  1. Make the sample project the parent of the user project.
  2. Copy the script files from the sample project (C:\Program Files\Inductive Automation\Ignition\data\projects\<sample-project>\ignition\script-python\<package-name>), and paste them into the same directory for your user project (but obviously replace sample-project with user-project).

The BEST way to distribute ANY PROJECT RESOURCE from one project to another is through the inheritance hierarchy. Place resources as high in the hierarchy as is possible/responsible to make them more available.

The Copy/Paste solution I provided should only be used as a one-off; if you find yourself doing this more than once, then you’ve begun designing in a manner which does not lend itself to easy maintenance.

As for control TAGS… If you’re referring to Client Tags, they have essentially the same solution, but we’re aware of a couple of bugs surrounding their inheritance. Tags which are NOT Client Tags should already be available across any project which uses the same Tag Provider, so there is nothing to do if that is the case. Keep in mind though that using TAGS for controls across different projects can be dangerous, and you should consider moving them into a project-siloed Tag provider.

Alternatively , I just distribute my demo project with its scripts and the control tags (they are just a few in number , say <5) to users, and they copy paste the scripts from the demo project to their project as is and manually create the control tags in their DB as they are few in number. Of course the tag paths of these tags where ever they are used in scripts should be manually edited by user (I have to put it in user manual).

With this the users is fully aware about what’s going on and there are less chances of errors in exporting scripts. More transparency though less protection of my IP.!

I hope the scripts are copied as project resources when a project is imported?

In the scripts editor, my wish list is to have a search feature to find strings in the python code. I feel so handicapped without the ability to search a string in the code.

1 Like

We’re working on it, but no ETA.

1 Like

Ever since I installed version 8.0.1, I am observing a strange behavior of my gateway scripts ! When I make a change in a script and save the project and run the scripts from my project (thru a memory Tag in Ignition from the designer) the changes are not reflected in the running scripts though the new code is saved in project but the old code seems to run! Gateway server is running in trial mode.! What could be going wrong! Do I have to install the designer again? I am running the old designer ICON stored on my desk top from the previous version.

There’s a bug with gateway scripts that will probably be fixed in 8.0.2 - the PR is currently open, just needs to go through QA approval and be merged in.