How do I get the Location property from the object.Properties list?

tlewis3348
tlewis3348 Member Posts: 16
10 Comments Photogenic Name Dropper
**

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

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 287
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭

    Hi @tlewis3348. This sounds like a bug, but I could not reproduce it in 2024R1. Here are some screenshots:




  • tlewis3348
    tlewis3348 Member Posts: 16
    10 Comments Photogenic Name Dropper
    **

    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 the prop.APIName was None, but I thought that because I was looking at obj.Properties[2] (whose prop.APIName is rightly None) rather than obj.Properties[1]. The actual reason for DesignRegionLocation not being recorded to the dictionary is due to the fact that obj.Properties[1].VisibleisFalse`, even though it can be seen in the UI.

  • Landon Mitchell Kanner
    Landon Mitchell Kanner Member, Employee Posts: 287
    100 Comments 25 Answers 25 Likes Photogenic
    ✭✭✭✭
    edited August 20

    I have filed Bug 1117027
    Interestingly obj.DesignRegionLocation.Visible returns True

  • tlewis3348
    tlewis3348 Member Posts: 16
    10 Comments Photogenic Name Dropper
    **

    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 (or getattr(obj, api_nm).ReadOnly). In other words, use the getattr() function to get the property and then check the desired Visible and ReadOnly properties.