55Copyright (c) 2018-2022 DSS Extensions contributors
66'''
77import warnings
8- from .._cffi_api_util import Base , CffiApiUtil
8+ from .._cffi_api_util import Base , CffiApiUtil , DSSException
99from .ICircuit import ICircuit
1010from .IError import IError
1111from .IText import IText
@@ -216,6 +216,48 @@ def AllowChangeDir(self):
216216 def AllowChangeDir (self , Value ):
217217 self .CheckForError (self ._lib .DSS_Set_AllowChangeDir (Value ))
218218
219+ @property
220+ def AllowDOScmd (self ):
221+ '''
222+ If enabled, the `DOScmd` command is allowed. Otherwise, an error is reported if the user tries to use it.
223+
224+ Defaults to False/0 (disabled state). Users should consider DOScmd deprecated on DSS Extensions.
225+
226+ This can also be set through the environment variable DSS_CAPI_ALLOW_DOSCMD. Setting it to 1 enables
227+ the command.
228+
229+ (API Extension)
230+ '''
231+ return self .CheckForError (self ._lib .DSS_Get_AllowDOScmd ()) != 0
232+
233+ @AllowDOScmd .setter
234+ def AllowDOScmd (self , Value ):
235+ self .CheckForError (self ._lib .DSS_Set_AllowDOScmd (Value ))
236+
237+ @property
238+ def COMErrorResults (self ):
239+ '''
240+ If enabled, in case of errors or empty arrays, the API returns arrays with values compatible with the
241+ official OpenDSS COM interface.
242+
243+ For example, consider the function `Loads_Get_ZIPV`. If there is no active circuit or active load element:
244+ - In the disabled state (COMErrorResults=False), the function will return "[]", an array with 0 elements.
245+ - In the enabled state (COMErrorResults=True), the function will return "[0.0]" instead. This should
246+ be compatible with the return value of the official COM interface.
247+
248+ Defaults to True/1 (enabled state) in the v0.12.x series. This will change to false in future series.
249+
250+ This can also be set through the environment variable DSS_CAPI_COM_DEFAULTS. Setting it to 0 disables
251+ the legacy/COM behavior. The value can be toggled through the API at any time.
252+
253+ (API Extension)
254+ '''
255+ return self .CheckForError (self ._lib .DSS_Get_COMErrorResults ()) != 0
256+
257+ @COMErrorResults .setter
258+ def COMErrorResults (self , Value ):
259+ self .CheckForError (self ._lib .DSS_Set_COMErrorResults (Value ))
260+
219261 def NewContext (self ):
220262 '''
221263 Creates a new DSS engine context.
@@ -230,3 +272,43 @@ def NewContext(self):
230272 new_ctx = lib .ctx_New ()
231273 new_api_util = CffiApiUtil (ffi , lib , new_ctx )
232274 return IDSS (new_api_util )
275+
276+ def __call__ (self , single = None , block = None ):
277+ '''
278+ Shortcut to pass text commands.
279+
280+ If `single` is set and is a string, a normal `DSS.Text.Command = single` is called.
281+ Otherwise, the value is passed to `DSS.Text.Commands`.
282+
283+ Examples:
284+
285+ # single command
286+ DSS("new Circuit.test")
287+ DSS(single="new Circuit.test")
288+
289+ # list of commands (either will work)
290+ DSS(["new Circuit.test", "new Line.line1 bus1=a bus2=b"])
291+ DSS(single=["new circuit.test", "new Line.line1 bus1=a bus2=b"])
292+ DSS(block=["new circuit.test", "new Line.line1 bus1=a bus2=b"])
293+
294+ # block of commands in a big string
295+ DSS(block="""
296+ clear
297+ new Circuit.test
298+ new Line.line1 bus1=a bus2=b
299+ new Load.load1 bus1=a bus2=b
300+ """)
301+
302+ (API Extension)
303+ '''
304+ if (single is not None ) and (block is not None ):
305+ raise DSSException ("Only a single argument is accepted." )
306+
307+ if (single is None ) and (block is None ):
308+ raise DSSException ("A value is required." )
309+
310+ if single is not None :
311+ self .Text .Command = single
312+ return
313+
314+ self .Text .Commands (single or block )
0 commit comments