I’m currently trying to set property values of a specific component based off of an excel spreadsheet.
I currently extract all components in the model and all property value groups + values associated with each component. However, I make edits to the spreadsheet and due to the sheer number of changes, it’s impractical to go through using the project explorer to search for the specific component and change the property values 1 by 1. I’ve looked at the “get_p_v_value()” function from the PVMT API and somewhat reverse engineered the script to allow me to set values but it’s not behaving the way it’s intended - which I suspect is because I’m only changing the top level of information.
The code I’ve written below is able to change the value assigned to each property value somewhat successfully.
for x in se.get_physical_architecture().get_all_contents_by_type(PhysicalComponent):
# Prints the component name
# Checks the owned property value groups of each component
for test in x.get_java_object().getOwnedPropertyValueGroups():
# Checks each owne property value for each property value group
for a in test.getOwnedPropertyValues():
#if the name of the property value is allocation2
if a.getName() == “allocation2”:
# if the value is none try to set the name’s value to test1
if a.getValue() is None:
try: a.getValue().setName("test1") except: pass # else set it to test2 else: try: a.getValue().setName("test2") except: pass # for all other property values, set the name to test3 else: try: a.getValue().setName("test3") except: pass
Running this script will change the value to test1, test2 or test3 almost randomly and sometimes even set all values of allocation1, allocation2, allocation3 to test3 ignoring the logic I’ve set. Is there another method I should look into in order to correctly change the property values as I only want to change the property value if the name == allocation2? Is it also therefore possible to assign known property value groups to components based on a script too?