Welcome to the world of MicroStation Python! This wiki will walk you through the process of creating 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.
Create Cell Element
To get started, refer to the Python Manager wiki for instructions on creating and loading a new Python project. Name your project "CreateNCell.py" and save it in a convenient location. Once created, open the project in your preferred code editor to begin writing your Python script.
To construct a cell element, you start with a cell header element, then add components, tell MicroStation when done, and finally add the completed cell element to a DGN model.
Here is the complete script.
from MSPyBentley import * from MSPyBentleyGeom import * from MSPyECObjects import * from MSPyDgnPlatform import * from MSPyDgnView import * from MSPyMstnPlatform import * # Create Normal Cell Element def CreateNormalCellElm(): global dgn_model m_eeh= EditElementHandle () NormalCellHeaderHandler.CreateOrphanCellElement (m_eeh, "test", dgn_model.Is3d(), dgn_model) NUM_LINES = 3 segmentList = [DSegment3d() for _ in range(NUM_LINES)] for i in range( 0 ,NUM_LINES): start = i * 1000.0 end = (i+1) * 1000.0 segmentList[i].point = [(start,start,start),(end,end,end)] m_eehLines = EditElementHandle () for j in range(0,NUM_LINES): LineHandler.CreateLineElement (m_eehLines, None, segmentList[j], dgn_model.Is3d(), dgn_model) if (BentleyStatus.eSUCCESS != NormalCellHeaderHandler.AddChildElement (m_eeh, m_eehLines)): return False if (BentleyStatus.eSUCCESS != NormalCellHeaderHandler.AddChildComplete (m_eeh)): return False if (BentleyStatus.eSUCCESS != m_eeh.AddToModel ()): return False return True # Main Function def main(): global ACTIVEMODEL global dgn_model global dgn_file global uor # Globals ACTIVEMODEL = ISessionMgr.ActiveDgnModelRef dgn_model = ACTIVEMODEL.GetDgnModel() dgn_file = dgn_model.GetDgnFile() model_info = dgn_model.GetModelInfo() uor = model_info.GetUorPerStorage() if True != CreateNormalCellElm(): print("Normal Cell not created...") # Main if __name__ == "__main__": print ("***** Create Normal Cell *****") main()
Load the project “CreateNCell.py” from the Python Manager dialog and Run/Execute the python script.
The Python script above creates a cell element named "test" and is added to the active model of the design file.
Happy coding!
Python: Documentation | API Presentations | FAQs | GitHub | Samples | Wikis | Blogs