When using physical units in an attribute, I get an error while evaluating the feature value expression.
Here’s my SysML v2 code:
package 'Part Tree Example' {
private import ISQ::mass;
private import SI::kg;
part def PhysicalPart {
attribute mass :> ISQ::mass;
}
part def Electrical specializes PhysicalPart;
part def Mechanical specializes PhysicalPart;
part automobile {
part drive_train {
part battery : Electrical {
attribute redefines mass = 150 [kg];
}
part motor : Electrical {
attribute redefines mass = 200 [kg];
}
}
part chassis {
part suspension : Mechanical {
attribute redefines mass = 100 [kg];
}
part body : Mechanical {
attribute redefines mass = 150 [kg];
}
}
}
}
And here’s my Python code:
import syside
def find_part_usage(element: syside.Element, part_name: str) -> syside.PartUsage:
if element.try_cast(syside.PartUsage) and element.name == part_name:
return element
else:
for owned_element in element.owned_elements:
found_part = find_part_usage(owned_element, part_name)
if found_part:
return found_part
return
def find_attribute_usage(
element: syside.Element, attr_name: str
) -> syside.AttributeUsage | None:
for owned in element.owned_members.collect():
if owned.try_cast(syside.AttributeUsage):
if owned.name == attr_name:
return owned
model, diagnostics = syside.load_model(["models/example_model_mass.sysml"])
assert not diagnostics.contains_errors(warnings_as_errors=True)
for doc in model.user_docs:
with doc.lock() as locked:
found_part = find_part_usage(locked.root_node, "battery")
print(found_part.name)
found_attr = find_attribute_usage(found_part, "mass")
print(found_attr.name)
assert found_attr.feature_value_expression is not None
evaluation = syside.Compiler().evaluate(found_attr.feature_value_expression)
if evaluation[1].fatal:
print(
f"Error evaluating {found_attr.name} attribute of part usage {found_part.name}"
)
for diag in evaluation[1].diagnostics:
print(f'Diagnostic code: "{diag.code}", message: "{diag.message}"')
else:
total_mass = evaluation[0]
Will print:
battery
mass
Error evaluating mass attribute of part usage battery
Diagnostic code: "unsupported-operator", message: "Operator '[' is not model-level evaluable"
I am using syside automator 0.6.3.