@@ -167,7 +167,21 @@ def export_dss_api_cls(dss: dss.IDSS, dss_cls):
167167 is_ckt_element = getattr (type (dss_cls ), '_is_circuit_element' , False )
168168 ckt_elem = dss .ActiveCircuit .ActiveCktElement
169169 ckt_elem_columns = set (type (ckt_elem )._columns ) - ckt_elem_columns_meta - pc_elem_columns - {'Handle' , 'IsIsolated' , 'HasOCPDevice' }
170- fields = list (type (dss_cls )._columns )
170+ try :
171+ fields = list (type (dss_cls )._columns )
172+ except :
173+ print (dss_cls , '_columns not found, skipping...' )
174+ return
175+
176+ if lname .endswith ('fuses' ) and IS_V11 :
177+ for f in ['CurveMultiplier' , 'InterruptingRating' ]:
178+ if f in fields :
179+ fields .remove (f )
180+
181+ # if lname.endswith('swtcontrols') and IS_V11:
182+ # for f in ['Action', 'NormalState', 'State', 'RatedCurrent', 'Open', 'Close', ]:
183+ # if f in fields:
184+ # fields.remove(f)
171185
172186 if lname .endswith ('solution' ):
173187 fields .extend (['IncMatrix' , 'Laplacian' , 'IncMatrixCols' , 'IncMatrixRows' , ])
@@ -243,80 +257,88 @@ def iter_cls():
243257 except :
244258 pass
245259
260+ if 'loadshapes' in lname :
261+ dss ('//!AltDSS PushCompatFlags' )
262+ dss ('//!AltDSS SetCompatFlag PermissiveProperties' )
246263
247- for _ in items :
248- record = {}
249- for field in fields :
250- # printv('>', getattr(_, 'Name', '---'), field)
251- try :
252- record [field ] = adjust_to_json (dss_cls , field )
253- except DSSException as e :
254- # Check for methods not implemented
255- if 'not implemented' in e .args [1 ].lower ():
256- #print(e.args)
264+ try :
265+ for _ in items :
266+ record = {}
267+ for field in fields :
268+ # printv('>', getattr(_, 'Name', '---'), field)
269+ try :
270+ record [field ] = adjust_to_json (dss_cls , field )
271+ except DSSException as e :
272+ # Check for methods not implemented
273+ if 'not implemented' in e .args [1 ].lower ():
274+ #print(e.args)
275+ continue
276+ raise
277+ except StopIteration :
278+ # Some fields are functions, skip those
279+ continue
280+ except AttributeError :
281+ # Depending on the version, a field doesn't exist
257282 continue
258- raise
259- except StopIteration :
260- # Some fields are functions, skip those
261- continue
262- except AttributeError :
263- # Depending on the version, a field doesn't exist
264- continue
265283
266- if meter_section_fields :
267- if dss_cls .NumSections > 0 :
268- dss_cls .SetActiveSection (1 )
269- for field in meter_section_fields :
284+ if meter_section_fields :
285+ if dss_cls .NumSections > 0 :
286+ dss_cls .SetActiveSection (1 )
287+ for field in meter_section_fields :
288+ # printv('>', field)
289+ try :
290+ record [field ] = adjust_to_json (dss_cls , field )
291+ except StopIteration :
292+ # Some fields are functions, skip those
293+ continue
294+
295+ if is_ckt_element :
296+ # also dump the circuit element info
297+ ckt_record = {}
298+ for field in ckt_elem_columns :
270299 # printv('>', field)
271- try :
272- record [field ] = adjust_to_json (dss_cls , field )
273- except StopIteration :
274- # Some fields are functions, skip those
275- continue
300+ ckt_record [field ] = adjust_to_json (ckt_elem , field )
276301
277- if is_ckt_element :
278- # also dump the circuit element info
279- ckt_record = {}
280- for field in ckt_elem_columns :
281- # printv('>', field)
282- ckt_record [field ] = adjust_to_json (ckt_elem , field )
302+ record ['ActiveCktElement' ] = ckt_record
283303
284- record ['ActiveCktElement' ] = ckt_record
285304
305+ if not has_iter :
306+ # simple record
307+ return record
286308
287- if not has_iter :
288- # simple record
289- return record
309+ # accumulate records
310+ records .append (record )
290311
291- # accumulate records
292- records .append (record )
312+ if is_ckt_element and not metadata_record :
313+ if records :
314+ for field in ckt_elem_columns_meta :
315+ # printv('>', field)
316+ metadata_record [field ] = adjust_to_json (ckt_elem , field )
293317
294- if is_ckt_element and not metadata_record :
295- if records :
296- for field in ckt_elem_columns_meta :
318+ for field in ckt_iter_columns_meta :
297319 # printv('>', field)
298- metadata_record [field ] = adjust_to_json (ckt_elem , field )
320+ try :
321+ metadata_record [field ] = adjust_to_json (dss_cls , field )
322+ except DSSException as e :
323+ if 'not implemented' in e .args [1 ].lower ():
324+ # print(e.args)
325+ continue
299326
300- for field in ckt_iter_columns_meta :
301- # printv('>', field)
302- try :
303- metadata_record [field ] = adjust_to_json (dss_cls , field )
304- except DSSException as e :
305- if 'not implemented' in e .args [1 ].lower ():
306- # print(e.args)
307- continue
327+ raise
308328
309- raise
310329
311330
331+ if 'Meters' in type (dss_cls ).__name__ :
332+ # This breaks the iteration
333+ extra = {'Totals' : adjust_to_json (dss_cls , 'Totals' )}
312334
313- if 'Meters' in type ( dss_cls ). __name__ :
314- # This breaks the iteration
315- extra = { 'Totals' : adjust_to_json (dss_cls , 'Totals' )}
335+ # elif has_iter and not metadata_record :
336+ # for field in iter_columns_meta:
337+ # metadata_record[field] = adjust_to_json(dss_cls, field)
316338
317- # elif has_iter and not metadata_record :
318- # for field in iter_columns_meta :
319- # metadata_record[field] = adjust_to_json(dss_cls, field )
339+ finally :
340+ if 'loadshapes' in lname :
341+ dss ( '//!AltDSS PopCompatFlags' )
320342
321343 return {'records' : records , 'metadata' : metadata_record , ** extra }
322344
@@ -342,19 +364,23 @@ def save_state(dss: dss.IDSS, runtime: float = 0.0) -> str:
342364 'Monitors' : dss .ActiveCircuit .Monitors ,
343365 'PDElements' : dss .ActiveCircuit .PDElements ,
344366 'PVSystems' : dss .ActiveCircuit .PVSystems ,
345- 'Reclosers' : dss .ActiveCircuit .Reclosers ,
346367 'RegControls' : dss .ActiveCircuit .RegControls ,
347368 'Relays' : dss .ActiveCircuit .Relays ,
348369 'Sensors' : dss .ActiveCircuit .Sensors ,
349370 'Settings' : dss .ActiveCircuit .Settings ,
350371 'Solution' : dss .ActiveCircuit .Solution ,
351- 'SwtControls' : dss .ActiveCircuit .SwtControls ,
352372 'Topology' : dss .ActiveCircuit .Topology ,
353373 'Transformers' : dss .ActiveCircuit .Transformers ,
354374 'Vsources' : dss .ActiveCircuit .Vsources ,
355375 'XYCurves' : dss .ActiveCircuit .XYCurves ,
356376 }
357377
378+ if not IS_V11 :
379+ dss_classes .update ({
380+ 'Reclosers' : dss .ActiveCircuit .Reclosers ,
381+ 'SwtControls' : dss .ActiveCircuit .SwtControls ,
382+ })
383+
358384 try :
359385 dss_classes .update ({
360386 'Storages' : dss .ActiveCircuit .Storages ,
@@ -369,12 +395,18 @@ def save_state(dss: dss.IDSS, runtime: float = 0.0) -> str:
369395 except AttributeError :
370396 pass
371397
398+ try :
399+ dss_classes .update ({
400+ 'Reactors' : dss .ActiveCircuit .Reactors ,
401+ })
402+ except AttributeError :
403+ pass
404+
372405 try :
373406 dss_classes .update ({
374407 'CNData' : dss .ActiveCircuit .CNData ,
375408 'LineGeometries' : dss .ActiveCircuit .LineGeometries ,
376409 'LineSpacings' : dss .ActiveCircuit .LineSpacings ,
377- 'Reactors' : dss .ActiveCircuit .Reactors ,
378410 'TSData' : dss .ActiveCircuit .TSData ,
379411 'WireData' : dss .ActiveCircuit .WireData ,
380412 })
@@ -412,6 +444,8 @@ def get_archive_fn(live_fn, fn_prefix=None):
412444 return archive_fn
413445
414446if __name__ == '__main__' :
447+ IS_V11 = False
448+
415449 if os .path .exists ('../../electricdss-tst/' ):
416450 ROOT_DIR = os .path .abspath ('../../electricdss-tst/' )
417451 else :
@@ -443,14 +477,18 @@ def get_archive_fn(live_fn, fn_prefix=None):
443477
444478 elif SAVE_DSSX_OUTPUT :
445479 from dss import DSS , DSSCompatFlags
480+ extrasuffix = ''
481+ if DSS .ActiveCircuit .Settings .COMErrorResults :
482+ extrasuffix += '_CER'
483+
446484 DSS .ActiveCircuit .Settings .CompatFlags = 0 # DSSCompatFlags.InvControl9611
447485 print ("Using DSS-Extensions:" , DSS .Version )
448486 match = re .match ('DSS C-API Library version ([^ ]+) revision.* ([0-9]+);.*' , DSS .Version )
449487 dssx_ver , dssx_timestamp = match .groups ()
450488 if (DSSCompatFlags .InvControl9611 & DSS .CompatFlags ):
451- suffix = f'-dssx_InvControl9611- { sys . platform } - { platform . machine () } - { dssx_ver } - { dssx_timestamp } '
452- else :
453- suffix = f'-dssx-{ sys .platform } -{ platform .machine ()} -{ dssx_ver } -{ dssx_timestamp } '
489+ extrasuffix += '_InvControl9611 '
490+
491+ suffix = f'-dssx{ extrasuffix } -{ sys .platform } -{ platform .machine ()} -{ dssx_ver } -{ dssx_timestamp } '
454492
455493 DSS .AllowEditor = False
456494 else :
@@ -462,6 +500,7 @@ def get_archive_fn(live_fn, fn_prefix=None):
462500 com_ver = DSS .Version .split (' ' )[1 ]
463501 suffix = f'-COM-{ platform .machine ()} -{ com_ver } '
464502
503+ IS_V11 = hasattr (DSS .ActiveCircuit .Fuses , 'InterruptingRating' )
465504 DSS .AllowForms = False
466505
467506 try :
@@ -472,7 +511,16 @@ def get_archive_fn(live_fn, fn_prefix=None):
472511 else :
473512 DSS .Text .Command = r'set Editor="C:\Program Files\Git\usr\bin\true.exe"'
474513
475- DSS .Text .Command = 'set ShowExport=NO'
514+ try :
515+ DSS .Text .Command = 'set ShowExport=NO'
516+ except :
517+ pass
518+
519+ try :
520+ DSS .Text .Command = 'set ShowReports=NO'
521+ except :
522+ pass
523+
476524 check_error ()
477525 sleep (0.1 )
478526 DSS .Text .Command = 'clear'
@@ -514,8 +562,11 @@ def get_archive_fn(live_fn, fn_prefix=None):
514562 exit ()
515563 except OSError :
516564 traceback .print_exc ()
565+ print ('Last file was:' )
566+ print (fn )
517567 exit ()
518568 except :
569+ print ('=' * 60 )
519570 print ('ERROR:' , fn )
520571 if colorizer :
521572 colorizer .colorize_traceback (* sys .exc_info ())
0 commit comments