[Вопрос] [PythonParts] Dynamic Attribute Value in Palette [Решен]


Hi,

We can use Attributes in the palette with :

<Parameter>
    <Name>FireRiskFactor</Name>
    <Text>Fire risk factor</Text>
    <Value>A1</Value>
    <ValueType>Attribute</ValueType>
    <AttributeId>1398</AttributeId>
</Parameter>

Link

I tried to set a dynamic value such as :

-Double * 1000 if Double &lt; 1000 else -Double

but it doesn't work.

I changed the code in the Python file but is it possible to set it directly in pyp ?

Best

Show solution Hide solution

Hi,

now I understand. In this case it is technically not a parameter but more an infobox for the user to inform him, what value is saved in the attribute @507@. The actual parameter influencing your PyP is the ComboBox. I would suggest you to implement the behavior in the modify_element_property() method of your interactor. Consider creating just a normal string parameter (with the persistency turned off) that you will only use to show the value assigned to @507@ and which you will update with every property modification. Assign the attribute directly in your script, as described here). But that is only my suggestion, how I would do that

Hi,

I will assume, you are creating a standard PythonPart. I am not sure, what kind of behavior do you want do achieve, because you can:

  • fill the parameter values dynamically, when starting the PythonPart to provide some initial values
  • change the parameter values based on other values every time a parameter is modified

In the first case you have to implement the initialize_control_properties function into your script. This function is called after the .pyp file was read (so the BuildingElement object is constructed), but before the palette is shown. You can modify the values in the build_ele accordingly and the framework will then display the palette with new values.

In the second case you have to implement the behavior in the modify_control_properties, which is called after every property modification in the palette.

I am a little confused by your formula:

<Value>-Double * 1000 if Double &lt; 1000 else -Double</Value>
This looks, like you wanted to modify the value of a parameter named Double based on the value of this parameter. That is a circular reference for me.

Hi,

It's for an Interactor PythonPart and I'm using the attribute field for "Designation" (@507@).

in my case, the user will have to choose between differents objects to build and the designation will depend of it (choice by StringComboBox).

As I said, I completed my python file for get it works with add_attribute and I wondered if the attribute's value can be dynamic in the pyp file.

For :

<Value>-Double * 1000 if Double &lt; 1000 else -Double</Value>

it's an example of dynamic value found in AllControls.pyp :

        <Parameter>
            <Name>Length</Name>
            <Text>Length</Text>
            <Value>4711</Value>
            <ValueType>Length</ValueType>
            <MinValue>-Double * 1000 if Double &lt; 1000 else -Double</MinValue>
            <MaxValue>
if Double &lt; 1000:
    return 2 * Double * 1000
else:
    return 2 * Double
            </MaxValue>
            <BackgroundColor>
if Double &lt; 1000:
    return (0, 255, 0)

return (0, 0, 255)
            </BackgroundColor>
        </Parameter>

Best

Edit:

Formula in pyp file is a great tool too and it's very flexible

Hi,

now I understand. In this case it is technically not a parameter but more an infobox for the user to inform him, what value is saved in the attribute @507@. The actual parameter influencing your PyP is the ComboBox. I would suggest you to implement the behavior in the modify_element_property() method of your interactor. Consider creating just a normal string parameter (with the persistency turned off) that you will only use to show the value assigned to @507@ and which you will update with every property modification. Assign the attribute directly in your script, as described here). But that is only my suggestion, how I would do that


https://campus.allplan.com/ uses cookies  -  More information

Accept