Skip to content

Element modification

Modifying the existing elements in the DF can be done in two ways.

  • General modification


    Modifying some generic data, like attributes or format properties, is easy as it requires only a BaseElementAdapter, but limited to certain types of operations.

    Learn how.

  • Specific modification


    Manipulation of specific element data gives you more flexibility, but it requires getting the instance of a specific python class and is therefore limited to only certain types of elements.

    Learn how.

General modification

ALLPLAN Python API offers some possibilities of modifying elements in a generic way. Generic means in this case performing operations, that can be applied to any element, like moving, rotating or changing format properties.

Transformation

The function CopyElements can be used to copy existing elements within the current document. The function needs a list of element adapters.

Tip

The fromPoint argument can be by default set to Point3D(). It becomes relevant only if the elements need to be rotated. In this case the fromPoint is used as the rotation center point.

Example on GitHub

The complete implementation is shown in the example CopyElements ( PYP | PY)

Specific modification

To modify specific properties of an element, you have to get the python object representing this element in the API out of the BaseElementAdapter. We explain, how to do it here.

Once you have the python object, you can modify any of its properties. After you are done, you write the modified element back to the data base using the function ModifyElements. Here's how the script flow should look like

flowchart LR
    Start((Start))
    ElementSelection["Select\nelement"]
    EleAdapter[(BaseElementAdapter)]
    GetElement["GetElement()"]
    PythonObject[("Python\nobject")]
    Modification["Element\nmodification"]
    ModifyEle["ModifyElements()"]
    End((End))

    Start --> ElementSelection
    ElementSelection --> EleAdapter
    EleAdapter --> GetElement
    GetElement --> PythonObject
    PythonObject --> Modification
    Modification --> ModifyEle
    ModifyEle --> End

Warning

As writing elements into the database is a relatively slow process, limit the number of ModifyElements function calls. You can do that by preparing a list of objects you want to modify and modify them once, at the end of the script.

Info

The method goes the python objects one by one and tries to use the most performant internal function to modify them. If there is no internal modification function implemented for the kind of modification, you are trying to perform, the function won't do anything.

We are constantly developing the API, so inform us if your kind of modification is not supported.

Example

Let's continue the example shown in the article about read access. To modify the selected text element, get the python object out of the BaseElementAdapter. Then you can modify any of its properties. E.g., to modify the text content modify the Text property, like.

text_element = AllplanBaseEle.GetElement(selected_text)
text_element.Text += "Foo"

You can also modify the text properties, e.g. the font style:

text_props              = text_ele.TextProperties
text_props.Font         = 20        #(1)!
text_ele.TextProperties = text_props
  1. When modifying properties of objects composing other objects, it is important to do it in three steps:

    • get the properties
    • modify the desired property
    • assign the modified properties to the element

    Doing in in a pythonic way, like text_ele.TextProperties.Font = 20 won't work!

At the end, write the modified data back to the database (drawing file) with ModifyElements:

AllplanBaseElements.ModifyElements(doc, [text_ele])

Example on GitHub

An example implementation of the ModifyElements function is shown in the example ModifyPlaneReferences ( PYP | PY).

Placeholder