Ignition 8 SFC Scope to Project Scripts

scripting
ignition80
#1

Hello,

I’m struggling to get the scripting scope figured out, particularly as it relates to SFCs and scripts in a project. Currently I have a package I’ve put down in …\user-lib\pylib<my package> on the Ignition server, but would prefer to move the package to Project Library.

The issue I’m having is if I have an SFC in a project and add the script to the Project Library, I’m not able to make an import/reference work from the SFC to modules in the package.

For example if in the Project Library I have a package myPackage and maybe subpackage mySubPackage with various modules … nothing like myPackage.mySubPackage. works.

Thanks,

Rick

0 Likes

#2

Paul Scott’s post Ignition 8 Tag Event Script helped me resolve the issue. While Paul didn’t address an SFC specifically a couple key phrases helped me understand … basically since an SFC is gateway scoped, getting access to the project script isn’t going to happen, except via “Gateway Scripting Project” project setting.

Thanks,

Rick

0 Likes

#3

Hey, it looks like we missed this one.

Something doesn’t sound right about this.

SFCs belong to a project and should be able to access the project scripts available to that project. The Gateway Scripting Project is really only relevant for things like tags, which don’t belong to any project.

0 Likes

#4

Hi Keven,

I created a simple SFC that opens a logger and calls testScript.doSomething() printing to the log the return value, here is the script:

def doSomething():
	return "This is something"

Regardless if I

import testScript
# Or
from . import testScript

# Or simply use full path
testScript.doSomething()

I also tried various other namespaces such as project…, or myProject… and other variations but the end result is along the lines of no module named testScript, no module named null, global name ‘testScript’ is not defined, etc.

Probably something simple, but I’m missing what it is.

Running version 8.02

Thanks,

Rick

0 Likes

#5

Is the script in the same project as the SFC? Or if in a parent project, has the script’s module been overridden? Consider logging str(dir()) to see what local variables are present.

0 Likes

#6

All in the same project, here is an image:

Ignition_Project

Any attempt in the SFC, which is nothing more then (Entry, Action, End) with the Action attempting to reference testScript (import testScript, or testScript.<some_method>) results in the SFC aborting instead of making a clean exit.

Thanks,

Rick

0 Likes

#8

I thought this was resolved in 8.03, turns out the offending line of code was commented out. Appears SFC in a project still cannot access script in the same project with 8.03.

Interesting though, if I create a timer even in Gateway Events in the same project, no problem getting to the project script. The SFC appears not to “scope in” the project itself.

Thanks,

Rick

0 Likes