Skip to content

Commit e4dcd67

Browse files
committed
Sync methods with dss_python
1 parent 889b29d commit e4dcd67

File tree

10 files changed

+257
-11
lines changed

10 files changed

+257
-11
lines changed

opendssdirect/ActiveClass.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ def ActiveClassParent():
4949
return get_string(CheckForError(lib.ActiveClass_Get_ActiveClassParent()))
5050

5151

52+
def ToJSON(options=0):
53+
"""
54+
Returns the data (as a list) of all elements from the active class as a JSON-encoded string.
55+
56+
The `options` parameter contains bit-flags to toggle specific features.
57+
See `Obj_ToJSON` (C-API) for more.
58+
59+
Additionally, the `ExcludeDisabled` flag can be used to excluded disabled elements from the output.
60+
61+
(API Extension)
62+
"""
63+
return get_string(CheckForError(lib.ActiveClass_ToJSON(options)))
64+
65+
5266
_columns = ["ActiveClassName", "Name", "NumElements", "ActiveClassParent"]
5367
__all__ = [
5468
"ActiveClassName",
@@ -59,4 +73,5 @@ def ActiveClassParent():
5973
"Next",
6074
"NumElements",
6175
"ActiveClassParent",
76+
"ToJSON",
6277
]

opendssdirect/Basic.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ def LegacyModels(*args):
122122
or contact the authors from DSS Extensions: https://github.com/dss-extensions/
123123
124124
After toggling LegacyModels, run a "clear" command and the models will be loaded accordingly.
125-
Defaults to False.
125+
Defaults to False.
126126
127127
This can also be enabled by setting the environment variable DSS_CAPI_LEGACY_MODELS to 1.
128128
129+
NOTE: this option will be removed in a future release.
130+
129131
(API Extension)
130132
"""
131133
# Getter
@@ -134,7 +136,31 @@ def LegacyModels(*args):
134136

135137
# Setter
136138
Value, = args
137-
return CheckForError(lib.DSS_Set_LegacyModels(Value))
139+
CheckForError(lib.DSS_Set_LegacyModels(Value))
140+
141+
142+
def AllowChangeDir(*args):
143+
"""
144+
If disabled, the engine will not change the active working directory during execution. E.g. a "compile"
145+
command will not "chdir" to the file path.
146+
147+
If you have issues with long paths, enabling this might help in some scenarios.
148+
149+
Defaults to True (allow changes, backwards compatible) in the 0.10.x versions of DSS C-API.
150+
This might change to False in future versions.
151+
152+
This can also be set through the environment variable DSS_CAPI_ALLOW_CHANGE_DIR. Set it to 0 to
153+
disallow changing the active working directory.
154+
155+
(API Extension)
156+
"""
157+
# Getter
158+
if len(args) == 0:
159+
return CheckForError(lib.DSS_Get_AllowChangeDir()) != 0
160+
161+
# Setter
162+
Value, = args
163+
CheckForError(lib.DSS_Set_AllowChangeDir(Value))
138164

139165

140166
_columns = [
@@ -165,4 +191,5 @@ def LegacyModels(*args):
165191
"NewCircuit",
166192
"AllowEditor",
167193
"LegacyModels",
194+
"AllowChangeDir",
168195
]

opendssdirect/Bus.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def AllPDEatBus():
229229
"PuVoltage",
230230
"X",
231231
"Y",
232+
"AllPCEatBus",
233+
"AllPDEatBus",
232234
]
233235
__all__ = [
234236
"AllPCEatBus",

opendssdirect/Circuit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def SystemY():
203203

204204

205205
def TotalPower():
206-
"""(read-only) Total power, kw delivered to the circuit"""
206+
"""(read-only) Total power, kW delivered to the circuit"""
207207
return get_float64_array(lib.Circuit_Get_TotalPower)
208208

209209

opendssdirect/CktElement.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,23 @@ def IsIsolated():
304304
return CheckForError(lib.CktElement_Get_IsIsolated()) != 0
305305

306306

307+
def setVariableByIndex(Idx, Value):
308+
Code = ffi.new("int32_t*")
309+
CheckForError(lib.CktElement_Set_Variablei(Idx, Code, Value))
310+
return Code[0]
311+
312+
313+
def setVariableByName(Idx, Value):
314+
Code = ffi.new("int32_t*")
315+
CheckForError(lib.CktElement_Set_Variable(Idx, Code, Value))
316+
return Code[0]
317+
318+
319+
def NodeRef():
320+
"""Array of integers, a copy of the internal NodeRef of the CktElement."""
321+
return get_int32_array(lib.CktElement_Get_NodeRef)
322+
323+
307324
_columns = [
308325
"BusNames",
309326
"CplxSeqCurrents",
@@ -392,4 +409,7 @@ def IsIsolated():
392409
"VoltagesMagAng",
393410
"YPrim",
394411
"IsIsolated",
412+
"setVariableByIndex",
413+
"setVariableByName",
414+
"NodeRef",
395415
]

opendssdirect/Element.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,17 @@ def NumProperties():
1616
return CheckForError(lib.DSSElement_Get_NumProperties())
1717

1818

19+
def ToJSON(options=0):
20+
"""
21+
Returns the properties of the active DSS object as a JSON-encoded string.
22+
23+
The `options` parameter contains bit-flags to toggle specific features.
24+
See `Obj_ToJSON` (C-API) for more.
25+
26+
(API Extension)
27+
"""
28+
return get_string(CheckForError(lib.DSSElement_ToJSON(options)))
29+
30+
1931
_columns = ["Name", "NumProperties", "AllPropertyNames"]
20-
__all__ = ["AllPropertyNames", "Name", "NumProperties"]
32+
__all__ = ["AllPropertyNames", "Name", "NumProperties", "ToJSON"]

opendssdirect/Generators.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,136 @@ def kvar(*args):
176176
CheckForError(lib.Generators_Set_kvar(Value))
177177

178178

179+
def daily(*args):
180+
"""
181+
Name of the loadshape for a daily generation profile.
182+
183+
(API Extension)
184+
"""
185+
# Getter
186+
if len(args) == 0:
187+
return get_string(CheckForError(lib.Generators_Get_daily()))
188+
189+
# Setter
190+
Value, = args
191+
if type(Value) is not bytes:
192+
Value = Value.encode(codec)
193+
CheckForError(lib.Generators_Set_daily(Value))
194+
195+
196+
def duty(*args):
197+
"""
198+
Name of the loadshape for a duty cycle simulation.
199+
200+
(API Extension)
201+
"""
202+
# Getter
203+
if len(args) == 0:
204+
return get_string(CheckForError(lib.Generators_Get_duty()))
205+
206+
# Setter
207+
Value, = args
208+
if type(Value) is not bytes:
209+
Value = Value.encode(codec)
210+
CheckForError(lib.Generators_Set_duty(Value))
211+
212+
213+
def Yearly(*args):
214+
"""
215+
Name of yearly loadshape
216+
217+
(API Extension)
218+
"""
219+
# Getter
220+
if len(args) == 0:
221+
return get_string(CheckForError(lib.Generators_Get_Yearly()))
222+
223+
# Setter
224+
Value, = args
225+
if type(Value) is not bytes:
226+
Value = Value.encode(codec)
227+
CheckForError(lib.Generators_Set_Yearly(Value))
228+
229+
230+
def Status(*args):
231+
"""
232+
Response to dispatch multipliers: Fixed=1 (dispatch multipliers do not apply), Variable=0 (follows curves).
233+
234+
Related enumeration: GeneratorStatus
235+
236+
(API Extension)
237+
"""
238+
# Getter
239+
if len(args) == 0:
240+
return CheckForError(lib.Generators_Get_Status())
241+
242+
# Setter
243+
Value, = args
244+
CheckForError(lib.Generators_Set_Status(Value))
245+
246+
247+
def IsDelta(*args):
248+
"""
249+
Generator connection. True/1 if delta connection, False/0 if wye.
250+
251+
(API Extension)
252+
"""
253+
# Getter
254+
if len(args) == 0:
255+
return CheckForError(lib.Generators_Get_IsDelta()) != 0
256+
257+
# Setter
258+
Value, = args
259+
CheckForError(lib.Generators_Set_IsDelta(Value))
260+
261+
262+
def kva(*args):
263+
"""
264+
kVA rating of electrical machine. Applied to machine or inverter definition for Dynamics mode solutions.
265+
266+
(API Extension)
267+
"""
268+
# Getter
269+
if len(args) == 0:
270+
return CheckForError(lib.Generators_Get_kva())
271+
272+
# Setter
273+
Value, = args
274+
CheckForError(lib.Generators_Set_kva(Value))
275+
276+
277+
def Class(*args):
278+
"""
279+
An arbitrary integer number representing the class of Generator so that Generator values may be segregated by class.
280+
281+
(API Extension)
282+
"""
283+
# Getter
284+
if len(args) == 0:
285+
return CheckForError(lib.Generators_Get_Class_())
286+
287+
# Setter
288+
Value, = args
289+
CheckForError(lib.Generators_Set_Class_(Value))
290+
291+
292+
def Bus1(*args):
293+
"""
294+
Bus to which the Generator is connected. May include specific node specification.
295+
296+
(API Extension)
297+
"""
298+
# Getter
299+
if len(args) == 0:
300+
return get_string(CheckForError(lib.Generators_Get_Bus1()))
301+
302+
# Setter
303+
Value, = args
304+
if type(Value) is not bytes:
305+
Value = Value.encode(codec)
306+
CheckForError(lib.Generators_Set_Bus1(Value))
307+
308+
179309
_columns = [
180310
"ForcedON",
181311
"Model",
@@ -191,6 +321,14 @@ def kvar(*args):
191321
"kVARated",
192322
"kW",
193323
"kvar",
324+
"Bus1",
325+
"Class",
326+
"kva",
327+
"IsDelta",
328+
"Status",
329+
"daily",
330+
"duty",
331+
"Yearly",
194332
]
195333
__all__ = [
196334
"AllNames",
@@ -211,4 +349,12 @@ def kvar(*args):
211349
"kVARated",
212350
"kW",
213351
"kvar",
352+
"daily",
353+
"duty",
354+
"Yearly",
355+
"Status",
356+
"IsDelta",
357+
"kva",
358+
"Class",
359+
"Bus1",
214360
]

opendssdirect/Meters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ def Totals():
269269
"""(read-only) Totals of all registers of all meters"""
270270
return get_float64_array(lib.Meters_Get_Totals)
271271

272+
272273
def ZonePCE():
273274
"""Returns the list of all PCE within the area covered by the energy meter"""
274275
return CheckForError(get_string_array(lib.Meters_Get_ZonePCE))

opendssdirect/Settings.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def AutoBusList(*args):
3535

3636

3737
def CktModel(*args):
38-
"""{dssMultiphase * | dssPositiveSeq} IIndicate if the circuit model is positive sequence."""
38+
"""{dssMultiphase (0) * | dssPositiveSeq (1) } IIndicate if the circuit model is positive sequence."""
3939
# Getter
4040
if len(args) == 0:
4141
return CheckForError(lib.Settings_Get_CktModel())
@@ -222,7 +222,27 @@ def LoadsTerminalCheck(*args):
222222

223223
# Setter
224224
Value, = args
225-
return CheckForError(lib.Settings_Set_LoadsTerminalCheck(Value))
225+
CheckForError(lib.Settings_Set_LoadsTerminalCheck(Value))
226+
227+
228+
def IterateDisabled(*args):
229+
"""
230+
Controls whether `First`/`Next` iteration includes or skips disabled circuit elements.
231+
The default behavior from OpenDSS is to skip those. The user can still activate the element by name or index.
232+
233+
The default value for IterateDisabled is 0, keeping the original behavior.
234+
Set it to 1 (or `True`) to include disabled elements.
235+
Other numeric values are reserved for other potential behaviors.
236+
237+
(API Extension)
238+
"""
239+
# Getter
240+
if len(args) == 0:
241+
return CheckForError(lib.Settings_Get_IterateDisabled())
242+
243+
# Setter
244+
Value, = args
245+
CheckForError(lib.Settings_Set_IterateDisabled(int(Value)))
226246

227247

228248
_columns = [
@@ -243,6 +263,8 @@ def LoadsTerminalCheck(*args):
243263
"VoltageBases",
244264
"ZoneLock",
245265
"AllowDuplicates",
266+
"LoadsTerminalCheck",
267+
"IterateDisabled",
246268
]
247269
__all__ = [
248270
"AllowDuplicates",
@@ -264,4 +286,5 @@ def LoadsTerminalCheck(*args):
264286
"ZoneLock",
265287
"AllocationFactors",
266288
"LoadsTerminalCheck",
289+
"IterateDisabled",
267290
]

0 commit comments

Comments
 (0)