Chapter 4 database basics: create our own Employee object
Open the Lab3 project file in the Lab3 folder, or run the Lab2 code.
In this chapter, we will create a 'employee object' (including a circle, an ellipse, and a multiline text object ), this object belongs to a custom employeeblock' block (this block resides in the 'emptyayer' layer. When this block is inserted in the model space, the 'ployeelayer' layer will have a block index for this block ). The code in each step in this chapter can be run, so that you can better understand the functions completed by each part of the code. The first step briefly describes how to create a circle in the model space.
<! -- [If! Vml] --> <! -- [Endif] -->
This chapter focuses on accessing the database in AutoCAD. The main contents include Transaction, ObjectId, symbol tables, block table BlockTable and layer table LayerTable, and object reference. Other Objects used, such as Color, Point3d, and Vector3d, are related to their respective steps, but the focus should be on the database.
1) CREATE a command named 'create', which calls the CreateEmployee () function (). This function is used to create a circle with a radius of 2.0 at (10, 10, 0) points of the model space (MODELSPACE:
<CommandMethod ("CREATE")> _
Public Function CreateEmployee ()
'First declare the object we want to use
Dim circle As Circle 'is the circle we want to add to the model space.
Dim btr As BlockTableRecord 'to add a circle, we must open the model space
Dim bt As BlockTable to open the model space, we must access it through the block table.
'Let's use an object named 'Transaction' to encapsulate database operations in the function.
Dim trans As Transaction
'Use the StartTransaction () Member of TransactionManager to start transaction processing.
Trans = HostApplicationServices. WorkingDatabase (). TransactionManager. StartTransaction ()