MicroStation Python: Drop Cell Element


 

Welcome to the world of MicroStation Python! This wiki will walk you through the process of dropping a cell element. A MicroStation cell is a reusable graphic element or group of elements that can be placed into a design file. Cells are like blocks in other CAD software.

 

Drop Cell Element

To get started, refer to the Python Editor wiki for instructions on creating and loading a new Python project. Name your project "DropCellElement.py" and save it in a convenient location. Once created, open the project in your preferred code editor to begin writing your Python script.

 

Here is the complete script.

 

from MSPyBentley import *
from MSPyBentleyGeom import *
from MSPyECObjects import *
from MSPyDgnPlatform import *
from MSPyDgnView import *
from MSPyMstnPlatform import *


def DropComplexElement ():
    elementId = 1111
    eh = ElementHandle(elementId, ISessionMgr.ActiveDgnModelRef)
    disp_handler = eh.DisplayHandler

    elm_agenda = ElementAgenda ()
    dropOptions = DropGeometry()
    dropOptions.SetOptions (DropGeometry.eOPTION_Complex)
    #print (dropOptions.GetOptions())
    status = disp_handler.Drop (eh, elm_agenda, dropOptions)

    if BentleyStatus.eSUCCESS != status:
        print ("Drop Element Failed...")
        return False

    for simpleElem in elm_agenda:
        # Create an EditElementHandle from the ElementHandle
        newEeh = EditElementHandle(simpleElem, True)
        if not newEeh.IsValid():
            print("ElementHandle is not valid...")
            continue
        status = newEeh.AddToModel()
        if status != BentleyStatus.eSUCCESS:
            print("Failed to add dropped elements to model...")

    return True


def main():
    if True == DropComplexElement():
        print("Element dropped and added to model...")


if __name__ == "__main__":
    main()

 

Run/Execute project

Load the project “DropCellElement.py” from the Python Editor dialog and Run/Execute the python script.

 

Happy coding!

 

Python: Documentation | API Presentations | FAQs | GitHub | Samples | Wikis | Blogs