-
Notifications
You must be signed in to change notification settings - Fork 8
/
pscad_update_ums.py
50 lines (42 loc) · 1.53 KB
/
pscad_update_ums.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''
Update unit measurement pgb names
'''
from __future__ import annotations
import os
import sys
if __name__ == '__main__':
print(sys.version)
#Ensure right working directory
executePath = os.path.abspath(__file__)
executeFolder = os.path.dirname(executePath)
os.chdir(executeFolder)
sys.path.append(executeFolder)
print(executeFolder)
from typing import List
if __name__ == '__main__':
from execute_pscad import connectPSCAD
import mhi.pscad
def updateUMs(pscad : mhi.pscad.PSCAD, verbose : bool = False) -> None:
projectLst = pscad.projects()
for prjDic in projectLst:
if prjDic['type'].lower() == 'case':
project = pscad.project(prjDic['name'])
print(f'Updating unit measurements in project: {project}')
ums : List[mhi.pscad.UserCmp]= project.find_all(Name_='$ALIAS_UM_9124$') #type: ignore
for um in ums:
print(f'\t{um}')
canvas : mhi.pscad.Canvas = um.canvas()
umParams = um.parameters() #type: ignore
alias = umParams['alias'] #type: ignore
pgbs = canvas.find_all('master:pgb') #type: ignore
for pgb in pgbs:
if verbose:
print(f'\t\t{pgb}')
pgbParams = pgb.parameters() #type: ignore
pgb.parameters(Name = alias + '_' + pgbParams['Group']) #type: ignore
def main():
pscad = connectPSCAD() #type: ignore
updateUMs(pscad)
print()
if __name__ == '__main__':
main()