Welcome to the world of MicroStation Python! This wiki will guide you through the process of iterating over Cell element.
Iterate Cell Element
To get started, refer to the Python Manager wiki for instructions on creating and loading a new Python project. Name your project "ScanCellElements.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 * # Read Cell Elements function def ReadCellElement(elmId): global dgn_model global numChildren eeh = EditElementHandle(elmId, dgn_model) child = ChildElemIter(eeh) while(child.IsValid()): elm = child.GetElement () numChildren +=1 if (False == elm.IsComplexHeader()): print(f"*** [{numChildren}] - Type: {child.GetElementType()} - ID: {elm.GetID()}") else: print(f"*** [{numChildren}] - Type: {child.GetElementType()} - ID: {elm.GetID()} - Complex Elements Count: {elm.GetComplexComponentCount()}") ReadCellElement(elm.GetID()) child = child.ToNext() # Main function def main(): global ACTIVEMODEL global dgn_model global dgn_file global uor global numChildren # Globals ACTIVEMODEL = ISessionMgr.ActiveDgnModelRef dgn_model = ACTIVEMODEL.GetDgnModel() dgn_file = dgn_model.GetDgnFile() model_info = dgn_model.GetModelInfo() uor = model_info.GetUorPerStorage() numChildren = 0 #elementId = 1557 elementId = 1542 ReadCellElement(elementId) print(f"Total Elements : {numChildren}") # Main if __name__ == "__main__": print("***** Cell Elements *****") main()
Run/Execute project
Load the project "ScanCellElements.py" from the Python Manager dialog and Run/Execute the python script.
The above python code, identifies a Cell element by its ID. Iterates through all child elements (via ChildElemIter), outputting their TYPE, ID, and the TOTAL NUMBER of child elements within the cell.
File:
Happy coding!
Python: Documentation | API Presentations | FAQs | GitHub | Samples | Wikis | Blogs