Use C # To compile a line in AutoCAD

Source: Internet
Author: User

Labels: CAD debugging vs2005

1) Open vs2005 and select Visual C # -- class library -- the name is line2, as shown below:

Figure (1) create a C # class library

2) Reference three DLL files for the project line2: acdbmgd. dll, acmgd. dll, and dotnetarx. dll. Acdbmgd. dll and acdmgd. dll are managed and encapsulated by autoccad. dotnetarx. dll is a class library used for. Net to develop AutoCAD programs. The first two DLL files can be found in the installation file of AutoCAD. dotnetarx. dll can be placed on the Internet, and I use dotnetarx6.0. The attributes of acdbmgd. dll and acdmgd. dll include "Copy to local": false.


Figure (2) Add three DLL references


Figure (3) set "Copy local" of cdbmgd. dll and acdmgd. DLL to false

3) Disable loaderlock. Click "debug" -- "exception --" managed debugging radians --> remove the check mark before "loaderlock.


Figure (4) Disable loaderlock

4) Enable the external program: C: \ Program Files \ AutoCAD 2006 \ acad.exe.

Right-click the project "line2" -- "properties --" Debug -- "and select" enable external program ". As follows:


Figure (5.exe open external acad.exe

5) C # Write the following code:

Using system; using system. collections. generic; using system. text; Using Autodesk. autoCAD. databaseservices; Using Autodesk. autoCAD. geometry; Using Autodesk. autoCAD. runtime; namespace line2 {public class line2 {[commandmethod ("firstline")] public static void firstline () {// obtain the currently active graph database DB = hostapplicationservices. workingdatabase; point3d startpoint = new point3d (500,500, 0); // start point of a straight line point3d endpoint = new point3d (700,500, 0); // line end line = new line (startpoint, endpoint); // create a Persistent Object // define a transaction to point to the current database to add a straight line using (transaction trans = dB. transactionmanager. starttransaction () {blocktable bt = (blocktable) trans. getObject (dB. blocktableid, openmode. forread); // read the block table. // open the block Table Record of the model space in write mode. blocktablerecord BTR = (blocktablerecord) trans. getObject (BT [blocktablerecord. modelspace], openmode. forwrite); // Add the information of the graphic object to the block Table Record and return the objectid object. BTR. appendentity (line); Trans. addnewlycreateddbobject (line, true); // Add the object to the transaction. trans. commit (); // submit transaction processing }}}}


6) Press F5 to start debugging and enter the following command in the command line window of AutoCAD:

Netload
Find line2.dll (usually in the DEBUG directory of the project), open line2.dll, and enter the custom command in the command line window of AutoCAD:
Firstline

The effect is as follows:


Figure (6) Input netload and load line2.dll


Figure (7) enter the custom command firstline and draw 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.