"""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")