File size: 1,205 Bytes
46b66f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""PCSWMM Script Editor connection test.

PCSWMM injects pcpy. Do not import pcpy.
"""

def safe_count(collection):
    try:
        return len(collection)
    except Exception:
        try:
            return int(collection.Count)
        except Exception:
            return None


try:
    swmm = pcpy.SWMM

    information = {
        "project_open": True,
        "project_name": str(swmm.ProjectName),
        "project_folder": str(swmm.ProjectFolder),
        "model_file": str(swmm.FilePath),
        "swmm_version": str(swmm.Version),
        "scenario_count": safe_count(swmm.Scenarios),
        "node_count": safe_count(swmm.Nodes),
        "link_count": safe_count(swmm.Links),
        "subcatchment_count": safe_count(swmm.Subcatchments),
        "storage_count": safe_count(swmm.Storages),
        "outfall_count": safe_count(swmm.Outfalls),
    }
except Exception as exc:
    information = {
        "project_open": False,
        "error": str(exc),
    }

print("=" * 60)
print("PCSWMM CONNECTION TEST")
print("=" * 60)

for key, value in information.items():
    print("{:<25} {}".format(key, value))

print("\nCONNECTION STATUS:", "SUCCESS" if information["project_open"] else "FAILED")