[Frage] [Interactor PythonParts] TYPE_CHECKING and BuildingElement [Gelöst]

Schlagworte:

Hi,

On the PythonParts, I see the use of "typing" verification tools.

Thanks for detailing your use in the scripts, in particular the lines below :

from typing import Any, List, cast, TYPE_CHECKING

...

if TYPE_CHECKING:
    from __BuildingElementStubFiles.PythonPartConnectionBuildingElement import PythonPartConnectionBuildingElement
else:
    PythonPartConnectionBuildingElement = BuildingElement

…

self.build_ele = cast(PythonPartConnectionBuildingElement, self.build_ele_list[0])

Moreover, in this example PythonPartConnection self.build_ele is associated with the 1st element of the list [0], but in PythonPartConnectionHole (sub script) with the second element [1].

Please also detail this procedure.

Best regards
Christophe

Lösung anzeigen Lösung verbergen

Hello Christophe!
Those two lines below

if TYPE_CHECKING:
    from __BuildingElementStubFiles.PythonPartConnectionBuildingElement import PythonPartConnectionBuildingElement
else:
    PythonPartConnectionBuildingElement = BuildingElement

have something to do with the new type hinting tool for pylance, we are about to create. As you might already noticed, pylance does not provide you any information about the typing of the properties inside the BuildingElement (which stands for the properties defined in the .pyp-file). We want to solve this problem by a tool, that builds a stub-file containing all the properties from the .pyp file and their types so you get the right type hinting, when referring to these properties in your code, instead of just "Unknown" type.

This if...else statemen basically just imports the stub file, while you are writing your code (TYPE_CHECKING = True) but ignores it, while the script runs (TYPE_CHECKING = False).

As the tool is done, we will upload it here and include it into documentation.

Regarding BuildingElementList:
It is an object, on which basis a PythonPart is created. Creating a PythonPart normally includes building a property palette and displaying it, creating a favorite file, saving the parameter values inside the PythonPart placed in the model, and so one... In general it can be done using single script and singly .pyp file. However you might want to build your PythonPart out of several sub-PythonParts. In this special case the BuildingElementList will have more than one element

Moreover, in this example PythonPartConnection self.build_ele is associated with the 1st element of the list [0], but in PythonPartConnectionHole (sub script) with the second element [1].

As the example PythonPartConnection consists of a main script and one sub script (which is variable, plate or hole) the BuildingElementList contains two BuildingElement objects - the first with the data from PythonPartConnection.pyp and the second from PythonPartConnectionHole/Plate.pyp. Both objects are used to create one palette and one PythonPart object and it is done in the main script.

Hello Christophe!
Those two lines below

if TYPE_CHECKING:
    from __BuildingElementStubFiles.PythonPartConnectionBuildingElement import PythonPartConnectionBuildingElement
else:
    PythonPartConnectionBuildingElement = BuildingElement

have something to do with the new type hinting tool for pylance, we are about to create. As you might already noticed, pylance does not provide you any information about the typing of the properties inside the BuildingElement (which stands for the properties defined in the .pyp-file). We want to solve this problem by a tool, that builds a stub-file containing all the properties from the .pyp file and their types so you get the right type hinting, when referring to these properties in your code, instead of just "Unknown" type.

This if...else statemen basically just imports the stub file, while you are writing your code (TYPE_CHECKING = True) but ignores it, while the script runs (TYPE_CHECKING = False).

As the tool is done, we will upload it here and include it into documentation.

Regarding BuildingElementList:
It is an object, on which basis a PythonPart is created. Creating a PythonPart normally includes building a property palette and displaying it, creating a favorite file, saving the parameter values inside the PythonPart placed in the model, and so one... In general it can be done using single script and singly .pyp file. However you might want to build your PythonPart out of several sub-PythonParts. In this special case the BuildingElementList will have more than one element

Moreover, in this example PythonPartConnection self.build_ele is associated with the 1st element of the list [0], but in PythonPartConnectionHole (sub script) with the second element [1].

As the example PythonPartConnection consists of a main script and one sub script (which is variable, plate or hole) the BuildingElementList contains two BuildingElement objects - the first with the data from PythonPartConnection.pyp and the second from PythonPartConnectionHole/Plate.pyp. Both objects are used to create one palette and one PythonPart object and it is done in the main script.


Verwendung von Cookies:
Um die Webseite optimal gestalten und fortlaufend verbessern zu können, verwendet Allplan Cookies.
Durch die weitere Nutzung der Webseite erklären Sie sich mit der Verwendung von Cookies einverstanden.  -  Mehr Informationen

Schließen