How to get the names of inherited projects of the actively running project on a client?

Thanks Paul!

This walks through each project and pulls out the styles as dictionaries with:

  • projectName
  • styleFullPath (directory filepath)
  • styleParentPath (relative-to-project path, excluding style name)
  • styleName (just the name of the style; styleParentPath + ‘/’ + styleName = the full path to the style for Ignition purposes)

The relevant part of the code to this topic is:

from com.inductiveautomation.ignition.gateway import IgnitionGateway
context = IgnitionGateway.get()
projectMgr = context.getProjectManager()
projectMfst = projectMgr.getProjectManifests()
projectName = system.project.getProjectName()
projectMfst[projectName].getParent() # this is the name of the inherited project of the active project

This is the full script:

def findFolderStyles(projectName, folderPath):
		import os
		import sys
		styles = []
		for root, subdirs, files in os.walk(folderPath):
			if 'resource.json' in files:
				styles.append({'projectName':projectName,
							   'styleFullPath':str(root), # this is the full directory path to the style in Windows
							   'styleParentPath':'/'.join(root.replace(folderPath,'').split('\\')[:-1]),  # gets the Perspective Style path used in Ignition, excluding the style name itself 
							   'styleName':str(root.split('\\')[-1])
							   })
		return styles
	
	def findProjectStyles(projectName):
		projectParentFolder = "C:\\Program Files\\Inductive Automation\\Ignition\\data\\projects\\"
		styleClassesRelPath = "\\com.inductiveautomation.perspective\\style-classes\\"
	
		styleClassFullPath = '%s%s%s' % (projectParentFolder, projectName, styleClassesRelPath)
		
		return findFolderStyles(projectName, styleClassFullPath)
	
	def findRelevantProjectStyles():
		from com.inductiveautomation.ignition.gateway import IgnitionGateway
		context = IgnitionGateway.get()
		projectMgr = context.getProjectManager()
		projectMfst = projectMgr.getProjectManifests()
		projectName = system.project.getProjectName()
		
		styles = []
		# get the Perspective Styles defined in the current project
		styles.extend(findProjectStyles(projectName))
		
		while projectMfst[projectName].getParent() != '':
			# get the parent project
			projectName = projectMfst[projectName].getParent()
			# get the Perspective Styles defined in the parent project 
			styles.extend(findProjectStyles(projectName))
		return styles
	
	styles = findRelevantProjectStyles()
	udtInstances = styles
	self.getChild("FlexRepeater").props.instances = udtInstances

2 Likes