[Question] Palette/Pyp File


Hello,

I have built this simple UI as an exercise for Python parts. My problem is as follows:
I want to show or hide elements on Page2 depending on whether the checkbox 2 is checked.
However, this only works if checkbox 1 is also checked.

I don't understand the connection here. Since I'm not very familiar with the .pyp structure, I ask for help.

Pièces-jointes (2)

Type: text/xml
Téléchargé 255 fois
Size: 6,26 KiB
Type: image/png
Téléchargé 28 fois
Size: 48,29 KiB

Cité par Michael_Bulant
Hello,
I have built this simple UI as an exercise for Python parts. My problem is as follows:

I want to show or hide elements on Page2 depending on whether the checkbox 2 is checked.

However, this only works if checkbox 1 is also checked.
I don't understand the connection here. Since I'm not very familiar with the .pyp structure, I ask for help.

Hi,

apparently PythonPartsFramework does not update the palette, when the first checkbox is unchecked. I don't know why, but you can make him do so by adding this function to your script:

def modify_control_properties(build_ele: BuildingElement,
                              ctrl_prop_util: ControlPropertiesUtil,
                              value_name: str,
                              event_id: int,
                              doc: AllplanElementAdapter.DocumentAdapter) -> bool:
    """Called after each change within the property palette

    Args:
        build_ele:      building element
        ctrl_prop_util: control properties utility
        value_name:     name(s) of the modified value (multiple names are separated by ,)
        event_id:       event ID
        doc:            document

    Returns:
        True if an update of the property palette is necessary, False otherwise
    """

    return True

It gets called every time, there is a change in the property palette and at the end you return a Boolean value: True means that the palette should be updated. In the above implementation True is return always, so the palette gets updated with every change in the palette (like unchecking a checkbox). This might slow down a PythonPart, but in your case there will be no significant drop in performance.

While looking on your problem, I've discovered that you added tags Visible and Enable to the first page:

    <Page>
        <Name>FirstPage</Name>
        <Text>First page</Text>
        <TextId>1001</TextId>
        <Visible>True</Visible>
        <Enable>True</Enable>[code]
But with this you basically overrides these tags in each parameter inside this page. This is why the enable condition in the parameter [i]Sturzplattenstärke[/i]...
[code]            <Parameter>
                <Name>Sturzplattenstärke</Name>
                <TextId>1010</TextId>
                <Value>150</Value>
                <MinValue>120</MinValue>
                <MaxValue>200</MaxValue>
                <ValueType>Length</ValueType>
                <Enable>SP_Dicke_ist_Schachtdicke == False</Enable>
                <BackgroundColor>(164, 164, 164) if SP_Dicke_ist_Schachtdicke == True else (-1, -1, -1) </BackgroundColor>
            </Parameter>

... doesn't work. It gets overridden by the one from the <Page> tag. Remove them and you can get rid of the BackgroundColor (which by the way gets ignored when changing pages - it's a bug we need to fix).
For the parameter Schachtelemente I would recommend you to use a list of tuples or even better namedtuples (see attached PYP file). ListGroups are OK, but it's much more text in the PYP file.

Hope that helps.

Best,
Bart

Pièces-jointes (1)

Type: text/xml
Téléchargé 188 fois
Size: 4,21 KiB

Thank you for this detailed response and these tips.