Getting Ignition Root Folder

Hello!

Right now I'm working doing a script that acces some local files, specically some json schemas so I can check the structure of some jsons.

I'm trying to get the root folder where are stored the files doing this:

import os
def getPath():
    return os.getcwd() + "\data\projects\\.files\schemas\"

But for some reason instead of getting this path:
C:\Program Files\Inductive Automation\Ignition\data\projects\\.files\schemas

The os.getcwd() is returning this:

C:\Users\Idom\Ignition\data\projects\\.files\schemas

I checked the folder and I noticed that in the second path there is a designerlauncher.exe file.

I wanna ask if in newer version has changed something about the paths or If I'm doing something wrong. I'm working in Perspective but the script file is in the Scripting folder.

Thanks in advance!

ive gotten the path to some json files(views) with this, in the past, so idk if it still hold for the last updates, but i guess it should

	from com.inductiveautomation.ignition.gateway import IgnitionGateway
		
	context = IgnitionGateway.get()
	pathToProjectFolder = str(context.systemManager.dataDir.absoluteFile).replace('\\','/') + '/projects'	
	pathToProject = pathToProjectFolder + "/" + system.perspective.getProjectInfo().name + "/com.inductiveautomation.perspective/views/"

(used it for finding translation keys)

Sadly it doesn't, or I'm not able to make it work.

image

As I have seen in the forum IgnitionGateway now is a private Class.

Thanks for the help anyway!

Are you sure you are running this in the correct scope? the screen shot suggests its the script console, this will not work in the script console, but will (might) run on a button/ gateway scope

I need it in a script file (code.py).

What I did was place it in a function and call it from the scripting console. I need to be able to get the correct path to my schemas folder.
C:\Program Files\Inductive Automation\Ignition\data\projects\.files\schemas

Hard-coding it will work, but I need it to work for Linux and Windows, that's why I need to be able to get to the project folder independent of the OS.

i think thats fine if its the gateway that triggers this code, im not sure

try it in a button, to see if that works

The project script library has no inherent scope. It's a library. What matters is where you invoke it from.
In a Perspective context, even in the designer, your code will be running on the gateway. In the script console, your code will be running on the local machine you're running the designer on.

2 Likes