How can I get attribute values?

I want to get the value of “type”. My starting point is the element “type” with qualified_name = Structure::vehicle::type. Thanks for your help!

   part def Vehicle {
    attribute type;
  }
  part vehicle : Vehicle {
    :>> type = Structure::VehicleType::combi;
  }

  enum def VehicleType {
    van;
    combi;
  }

The most general way to do so would be to evaluate the expression using the Compiler:

expression = element_named_type.feature_value_expression
result = syside.Compiler().evaluate(expression)[0]

The result in this case would be the element Structure::VehicleType::combi. (Note: the [0] at the end is needed because the compiler evaluation returns tuple[syside.Value | None, syside.CompilationReport])

3 Likes