2.1 create a straight line

Source: Internet
Author: User

Create a project createline. The procedure is the same as that of 1.4helloworld. Register a command and define its own name. I use it as createline just like Miss Zhang Fan.

Mode has two options. Although I do not know the differences between the two options, follow the instructions of instructor Zhang Fan. If anyone knows, please tell me, thank you first. After the command is created, a defined function static void xbcreateline (void) is also obtained. Add the code to draw a straight line.

1 # include "stdafx. H "2 # include" resource. H "3 4 // Release 5 # define szrds _ rxst (" XB ") 6 7 // release 8 // ----- ObjectARX entrypoint 9 class cmy21createlineapp: Public acrxarxapp {10 11 public: 12 cmy21createlineapp (): acrxarxapp () {} 13 14 virtual acrx: appretcode on_kinitappmsg (void * Pkt) {15 // todo: load dependencies here16 17 // you * Must * Call on_kinitappmsg here18 acrx: appretcode retcode = acrxarxapp: on_kinitappmsg (Pkt); 19 20 // todo: add your initialization code here21 22 return (retcode); 23} 24 25 virtual acrx: appretcode on_kunloadappmsg (void * Pkt) {26 // todo: add your code here27 28 // you * Must * Call on_kunloadappmsg here29 acrx: appretcode retcode = acrxarxapp: on_kunloadappmsg (Pkt); 30 31 // todo: unload dependencies here32 33 return (retcode); 34} 35 36 virtual void registerservercomponents () {37} 38 39 40 //-xB. createline command (do not rename) 41 // draw a line command, draw a line 42 static void xbcreateline (void) with the start point (100,100, 0) and the end point (, 0) 43 {44 // Add your code for command XB. createline here45 46 // Step 1: Create a New acdbline object 47 acgepoint3d ptstart (100,100, 0) in the memory; // start point 48 acgepoint3d ptend (, 0 ); // terminal 49 acdbline * pline = new acdbline (ptstart, ptend); 50 51 // step 2, obtain the pointer to the table block 52 acdbblocktable * pblocktable; 53 acdbhostapplicationservices () -> workingdatabase () 54-> getblocktable (pblocktable, ACDB: kforread); 55 56 // step 3, obtain records pointing to a specific block table (model space) pointer 57 acdbblocktablerecord * pblocktablerecord; 58 pblocktable-> getat (acdb_model_space, pblocktablerecord, 59 ACDB: kforwrite); 60 61 // Step 4, add the acdbline object to the block table record 62 acdbobjectid lineid; 63 pblocktablerecord-> appendacdbentity (lineid, pline); 64 65 // step 5, close various objects in the database 66 pblocktable-> close (); 67 pblocktablerecord-> close (); 68 pline-> close (); 69 70} 71 }; 72 73 // 74 implement_arx_entrypoint (cmy21createlineapp) 75 76 aced_arxcommand_entry_auto (cmy21createlineapp, XB, createline, createline, acrx_assist_modal, null)

You must also include the header file dbents. H of the acdbline class in stdafx. cpp. Otherwise, the acdbline class object cannot be recognized.

Finally, set the EXE path of CAD (the operation method is the same as the setting in 1.4helloworld), compile and run the command, load the command, and display a straight line after entering the command on the command line. Finished!

 

My personal summary on the content of this section:

1. Understand the basic terms of the database:

Table: A table is a component of a database. A database must contain at least one table.

Record: a record is the unit of a table. A table may contain multiple records or contain no records.

2. basic steps to create a graphic object

(1) determine the Graphic Database of the object to be created;
(2) obtain the block table of the graphic database;
(3) Obtain a block table record for storing entities. All the entities in the model space are stored in the specific records of the model space.

(4) create an object of the object class and append the object to a specific block table record.

3. Why is acdbline * pline = new acdbline (ptstart, ptend) instead of acdbline (ptstart, ptend );?

A: Because, based on the internal implementation mechanism of AutoCAD (I am not sure about the mechanism), you must create an object (new) on the stack ).

4. Why is the created object not displayed?

A: Because the created object is only created in the memory, you must add it to the database if you want to display it.

 

2.1 create a straight line

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.