CAD databases create simple objects

Source: Internet
Author: User

1. Introduction
Each AutoCAD drawing represents a structured database that stores several types of objects. When you open a new drawing, AutoCAD will create an organized and efficient database in the background. This database has data that allows you to create at least basic images.
This minimal data is basically represented by objects such as the image layer, line type, and text style. In this way, you have layer 0, standard text style, continuous line type and others.
Since AutoCAD 2000, you can work with multiple images at the same time. This is what we call the multi-Document Interface (MDI) environment. This feature brings more flexibility and makes processing of multiple images more complicated. We will not discuss the multi-Document Interface in this course, but this may be required by the ObjectARX application in the future.

2. How to access data
The database saves a pattern to display all types of objects required. These objects are stored in appropriate containers, which are special objects used to manage similar objects. In this way, we have appropriate methods and procedures for accessing entities, layers, text styles, and so on. Each object stored in the database has an identifier called objectid. This identifier is unique in the same AutoCAD session and is valid within the lifecycle of each object. Objectid is generated by the database. We don't have to worry about how to create it.

In ObjectARX, we have three basic objects:
Object: the object used to represent the image (line, arc, text ......);
Container: Special Objects used to store and manage a set (layer table, line table ......);
Object: No graphic display objects (group, layout ......)

3. Data Structure of AutoCAD
A. Create an object
There are some ways to create an object through ObjectARX, depending on which object you want to create and where you want to store it (in most cases, we save the object in its specific container ). But basically, you will follow the order below:

Define a pointer for the object type you want to create and call its new operation;
This pointer calls the appropriate method of this object to change its features;
Obtain the database pointer of the object you want to create (most of the cases are the current database );
Open the appropriate container for storing it;
Call a specific container method, pass its pointer, and store it.
Automatically receives the objectid created by the container;
Complete the operation to close all open objects, including the container and the object you just created.

Obviously, you need to create some convenient classes to automate the process, because they are so similar and easy to reuse. The main idea is to create a practical database method, such as addlayer, addline, addcircle, addtextstyle, and so on.
* Closing open objects is very important because it will lead to the termination of running of AutoCAD.

B. Simple code for creating a straight line (acdbline)
This code is used to illustrate how to create a simple line between two points. The process is simple and there is no error handling. This code needs to be put into the ObjectARX application structure to work. The main idea is to show you some concepts. Here we will create code that can work. Pay attention to the order in which close operations are enabled.

// Now we need to instantiate an acdbline pointer
// In this example, its constructor allows me to pass parameters of two vertices
Acdbline * pline = new acdbline (startpt, endpt );
// Now you need to open the appropriate container, that is, blocktable
Acdbblocktable * pblocktable = NULL;
// First obtain the current database and then obtain the blcoktable
Acdbdatabase * PDB = acdbhostapplicationservices ()-> workingdatabase ();
PDB-> getsymboltable (pblocktable, ACDB: kforread );
// Open modelspace in blocktable
Acdbblocktablerecord * pblocktablerecord = NULL;
Pblocktable-> getat (acdb_model_space, pblocktablerecord, ACDB: kforwrite );
// After modelspace is obtained, we can disable blocktable.
Pblocktable-> close ();
// Using the modelspace pointer, we can add our new direct
Acdbobjectid lineid = acdbobjectid: knull;
Pblocktablerecord-> appendacdbentity (lineid, pline );
// Finally, to complete the processing, we need to disable modelspace and Entity
Pblocktablerecord-> close ();
Pline-> close ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.