import os, json, sys global_project_page_ids = {} def get_project_config(): """ Scan each view.json under Detailed_Views (no recursion), go one level deeper (coordinateContainer), extract tagProps[0] from children, and store as {source_id: view_folder_name}. """ global global_project_page_ids global_project_page_ids.clear() try: project_name = system.util.getProjectName() base_path = ( os.getcwd().replace("\\", "/") + "/data/projects/" + project_name + "/com.inductiveautomation.perspective/Views/autStand/Detailed_Views/MCM-Views" ) if not os.path.exists(base_path): system.perspective.print("Path not found: " + base_path) return {} for view_folder in os.listdir(base_path): json_file = os.path.join(base_path, view_folder, "view.json") if not os.path.isfile(json_file): continue with open(json_file, "r") as fh: view_json = json.load(fh) # go one level deeper: root -> children[0] (coordinateContainer) -> its children root_children = (view_json.get("root") or {}).get("children") or [] if not root_children: continue # assume first child is the coordinateContainer container = root_children[0] children = container.get("children") or [] # now loop through these children to get tagProps for child in children: props = child.get("props") or {} params = props.get("params") or {} tag_props = params.get("tagProps") meta = child.get("meta") or {} comp_name = meta.get("name", "") if isinstance(tag_props, list) and len(tag_props) > 0: source_id = str(tag_props[0]) global_project_page_ids[source_id] = { "Page": view_folder, "Name":comp_name } except: whid = system.tag.readBlocking("Configuration/FC")[0].value logger = system.util.getLogger("%s-get_project_config" % whid) exc_type, exc_obj, tb = sys.exc_info() logger.error("Error at line %s: %s" % (tb.tb_lineno, exc_obj)) return global_project_page_ids def navigate_to_url(self, source_id, page_id, priority ="Diagnostic"): url_to_navigate = "autStand/Detailed_Views/%s" % (page_id) if "MCM01" in url_to_navigate: url_to_navigate += "-FLUID INBOUND" else: url_to_navigate += "-NON CON SORTER" system.perspective.navigate(view=url_to_navigate, params={"highlightTagPath": source_id + "||" + priority}) def source_id_lookup(self, device_name): """ Finds page_id from global_project_page_ids by source_id or by hierarchy, then navigates. """ ids = get_project_config() if not isinstance(ids, dict): system.perspective.print("Error: project config invalid") for source_id, info in ids.items(): name = info.get("Name", "Unknown") page = info.get("Page", "Unknown") if name.replace("_", "") == device_name: return source_id