Welcome to the world of MicroStation Python! This wiki provides a Python code snippet that demonstrates how to create and place a Note element.
Let us dive into, creating and placing a Note element. Refer to the Python Manager wiki to create and load a python project. Name your project as "NoteElement.py" and save it to your preferred directory. Open the project in the editor for writing your Python script.
Prerequisites:
Here is the complete script.
from MSPyBentley import * from MSPyBentleyGeom import * from MSPyECObjects import * from MSPyDgnPlatform import * from MSPyDgnView import * from MSPyMstnPlatform import * noteStyleName = "NoteStyle" # GetText function def GetText(text, File, model): textStyle = DgnTextStyle.GetByName(noteStyleName, File) if (None == textStyle): print (f"Text Style: <{noteStyleName}> not found") return None textBlock = TextBlock(textStyle, model) textBlock.AppendText(text) return textBlock # CreateNote function def CreateNote(leader, noteElem, File, model): text = GetText("Note Test\nLine 2\nLine 3", File, model) if (None == text): print (f"Text Block creation failed...") return None dimStyle = DimensionStyle.GetByName(noteStyleName, File) if (None == dimStyle): print (f"Dimension Style: <{noteStyleName}> not found") return None points= DPoint3dArray() points.append(DPoint3d(10000, 0, 0)) points.append(DPoint3d(150000, 50000, 0)) return NoteCellHeaderHandler.CreateNote(noteElem, leader, text, dimStyle, model.Is3d(), model, points) # CreateNoteElement function def CreateNoteElement(): dgn_model = ISessionMgr.ActiveDgnModel dgn_file = ISessionMgr.GetActiveDgnFile() noteElem = EditElementHandle() leader = EditElementHandle() status = CreateNote(leader, noteElem, dgn_file, dgn_model) if (BentleyStatus.eSUCCESS != status): print("Note element creation failed...") return if (BentleyStatus.eSUCCESS != NoteCellHeaderHandler.AddToModel(noteElem, leader, dgn_model)): print("Note element not added to model...") return dgn_file.ProcessChanges(DgnSaveReason.eFileClose) # main function def main(): CreateNoteElement() # main if __name__ == "__main__": print ("***** Place Note *****") main()
Load the project "NoteElement.py" from the Python Manager dialog and Run/Execute the python script.
Note element is created and placed into the DGN file.
This script offers a simple and efficient method for creating a Note element. Customize the script to suit your requirements and integrate into your workflows.
Happy coding!
Python: Documentation | API Presentations | FAQs | GitHub | Samples | Wikis | Blogs