-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinteger_array.py
More file actions
97 lines (75 loc) · 2.72 KB
/
integer_array.py
File metadata and controls
97 lines (75 loc) · 2.72 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# SPDX-FileCopyrightText: 2025 Autodesk, Inc.
# SPDX-License-Identifier: Apache-2.0
"""
Usage:
IntegerArray Class API Wrapper
"""
from .logger import process_log
from .helper import check_type
from .com_proxy import safe_com, flag_com_method
from .common import LogMessage
class IntegerArray:
"""
Wrapper for IntegerArray class of Moldflow Synergy.
"""
def __init__(self, _integer_array):
"""
Initialize the IntegerArray with a IntegerArray instance from COM.
Args:
_integer_array: The IntegerArray instance from COM.
"""
process_log(__name__, LogMessage.CLASS_INIT, locals(), name="IntegerArray")
self.integer_array = safe_com(_integer_array)
flag_com_method(self.integer_array, "ToVBSArray")
flag_com_method(self.integer_array, "FromVBSArray")
def val(self, index: int) -> int:
"""
Get the value at the specified index.
Args:
index (int): index between 0 and integer_array.size-1 (inclusive)
Returns:
The value at the specified index.
"""
process_log(__name__, LogMessage.FUNCTION_CALL, locals(), name="val")
check_type(index, int)
return self.integer_array.Val(index)
def add_integer(self, value: int) -> None:
"""
Adds an integer value to the end of the array.
Args:
value (int): The value to add.
"""
process_log(__name__, LogMessage.FUNCTION_CALL, locals(), name="add_integer")
check_type(value, int)
self.integer_array.AddInteger(value)
def to_list(self) -> list[int]:
"""
Convert the integer array to a list of integers.
Returns:
The list of integers.
"""
process_log(__name__, LogMessage.FUNCTION_CALL, locals(), name="to_list")
vb_array = self.integer_array.ToVBSArray()
return list(vb_array)
def from_list(self, values: list[int] | tuple[int, ...]) -> int:
"""
Convert a list of integers to an integer array.
Args:
values (list[int] | tuple[int, ...]): The list of integers to convert.
Returns:
The number of elements added.
"""
process_log(__name__, LogMessage.FUNCTION_CALL, locals(), name="from_list")
check_type(values, (list, tuple))
for value in values:
check_type(value, int)
return self.integer_array.FromVBSArray(list(values))
@property
def size(self) -> int:
"""
Get the size of the array.
Returns:
The size of the array.
"""
process_log(__name__, LogMessage.PROPERTY_GET, locals(), name="size")
return self.integer_array.Size