How do I get the Location property from the object.Properties list?
From what I've been able to tell, generally, the APIName
of a property in an object's object.Properties
list corresponds to the name used to access that property directly from the object. In other words, to get the value of the property from a given index
of object.Properties
, this should work: getattr(object, object.Properties[index].APIName)
.
As an example, for a named selection, the second item in the object.Properties
list shows up as GeometrySelection
when you execute object.Properties[1]
, and 'Location'
is returned when you execute object.Properties[1].APIName
. So, object.Location
is equivalent to getattr(object, object.Properties[1].APIName)
. This can be useful since it allows the entirety of the properties for a given object to be obtained by the script without having to know ahead of time the means of getting a specific property.
However, there is at least one instance where this is not the case. For the "Optimization Region" of a "Structural Optimization" simulation, object.DesignRegionLocation
returns the scoped geometry for the region. However, the item that corresponds to that property is the third item from the object.Properties
list, and the APIName
is empty. As far as I can tell, there is no means of identifying the DesignRegionLocation
from the object.Properties
list. Am I missing something?
Answers
-
Hi @tlewis3348. This sounds like a bug, but I could not reproduce it in 2024R1. Here are some screenshots:
0 -
Well, that's a little embarrassing. I've been using this code to grab all the properties for the object:
prop_dict = {} for prop in obj.Properties: if prop.Visible and prop.APIName and not prop.ReadOnly: api_nm = prop.APIName if prop.APIName in obs_typs_dict: api_nm = obs_typs_dict[prop.APIName] val = getattr(obj, api_nm) if hasattr(val, "DataModelObjectCategory"): val = ("ans_obj:" + str(val.DataModelObjectCategory) + ":" + val.Name) prop_dict[api_nm] = str(val)
It doesn't record the
DesignRegionLocation
in the dictionary, and I thought it was because theprop.APIName
wasNone
, but I thought that because I was looking atobj.Properties[2]
(whoseprop.APIName
is rightlyNone
) rather thanobj.Properties[1]
. The actual reason forDesignRegionLocation
not being recorded to the dictionary is due to the fact that obj.Properties[1].Visibleis
False`, even though it can be seen in the UI.0 -
I have filed Bug 1117027
Interestinglyobj.DesignRegionLocation.Visible
returns True0 -
So, maybe a more robust means of getting the
Visible
(and, for that matter,ReadOnly
) property would be to use this:getattr(obj, api_nm).Visible
(orgetattr(obj, api_nm).ReadOnly
). In other words, use thegetattr()
function to get the property and then check the desiredVisible
andReadOnly
properties.0