Skip to content

Library elements

Placing in the model

Objects saved in Allplan Library, like:

  • symbols
  • smart symbols
  • fixtures

can be accessed by the Python API and placed in the model. To do that, a LibraryElement object must be instantiated by using the appropriate LibraryElementProperties. The properties are defined differently depending on the type of the library element.

Example

To place a symbol only the library element path is needed.

path = AllplanSettings.AllplanPaths.GetEtcPath() + "Library\\2D Objects\\Exterior\\2D animals\\Cat.sym"

library_element_properties = \
    AllplanBasisElements.LibraryElementProperties(fullPathName=      path,
                                                  elementType=       AllplanBasisElements.LibraryElementType.eSymbol, #(2)!
                                                  placementMatrix=   AllplanGeo.Matrix3D()) #(3)!

library_element = AllplanBasisElements.LibraryElement(library_element_properties) #(1)!
  1. This object can then directly be appended to the list of elements of the CreateElementResult dataclass (in case of Standard PythonPart) or to the CreateElements method (in case of Interactor PythonPart).
  2. In case of a smart symbol, provide the type eSmartSymbol instead of eSymbol here.
  3. Local placement matrix of the element can be defined here, if needed.

For placing a fixture, a path, group and element names must be provided when instantiating the LibraryElementProperties object, because these elements are stored differently in Allplan.

fixture = build_ele.PointFixture.value #(1)!

library_element_properties = \
    AllplanBasisElements.LibraryElementProperties(path=             fixture.Path, #(2)!
                                                  group=            fixture.Group,
                                                  element=          fixture.Element,
                                                  elementType=      AllplanBasisElements.LibraryElementType.eFixture, #(3)!
                                                  placementMatrix=  AllplanGeo.Matrix3D())

library_fixture_element = AllplanBasisElements.LibraryElement(library_element_properties)
  1. The parameter was defined with the tag <Valuetype> set to Fixture. Therefore the returned object will be FixtureProperties. See this chapter to learn more.
  2. In this case path, group and element names must be provided.
  3. Don't forget to set the right library element type!

Placing a line or plane fixture is the same, as placing a point fixture, with the exception that a polyline must be provided in the LibraryElementProperties object.

fixture = build_ele.LineFixture.value

library_element_properties = \
    AllplanBasisElements.LibraryElementProperties(path=             fixture.Path,
                                                  group=            fixture.Group,
                                                  element=          fixture.Element,
                                                  elementType=      AllplanBasisElements.LibraryElementType.eFixture,
                                                  placementMatrix=  AllplanGeo.Matrix3D())

fixture_pol = AllplanGeo.Polyline3D()
fixture_pol += AllplanGeo.Point3D()
fixture_pol += AllplanGeo.Point3D(1500, 0, 0)
fixture_pol += AllplanGeo.Point3D(2500, 2000, 0)
library_element_properties.SetPolyline(fixture_pol)

library_fixture_element = AllplanBasisElements.LibraryElement(library_element_properties)

Appending to a Python Part

The PythonPartUtil offers the method add_library_elements that can add library elements to a PythonPart as child-elements. This allows e.g., to replace multiple symbols with the Update of identical PythonParts functionality.

Warning

Bounding Box

If the PythonPart should solely consists of a library element, it is advisable to create at least a bounding box around it as an unprintable help construction and add it to the PythonPart with add_pythonpart_view_2d3d. As a result, the user is still able to modify the PythonPart by double-click on the bounding box, whereas the library element remains a child-element of the PythonPart.

Example

For a complete usage of LibraryElement, see the example SymbolLibraryElement located in:

  • …\etc\Examples\PythonParts\BasisExamples\UserObjects\ SymbolLibraryElement.pyp
  • …\etc\PythonPartsExampleScripts\BasisExamples\UserObjects\ SymbolLibraryElement.py