Use C # to perform AutoCAD secondary development (3)

zhaozj2021-02-16  52

Using C # to perform AutoCAD Secondary Development (3) The main content of this C # talents This is an introduction to the AutoCAD object model. If you develop AutoCAD for VBA, this part of this part should be super simple. The object is the main construction block of the AutoCAD ActiveX interface, each displayed objectively represents an AutoCAD component. The main objects of the AutoCAD ActiveX interface are: • Drawings such as straight lines, arcs, texts, and labels. • Line type and labeling style and other organizational objects • Layers, groups, and blocks. • Views and viewports. • Graphics, the AutoCAD application itself is also the root object of all objects of all objects is the AutoCAD application itself, which is represented by the AcadApplication class. Gets currently running AcadApplication objects can be obtained using the methods described in the previous lecture. There are four sub-objects under AcadApplication objects, namely:  AcadpReferences object, can access and set the relevant options object in the "Options" dialog, which represents the AutoCAD graphic AcadMenuBar object, which represents AutoCAD main menu bar (Note Not AcadMenubars, because the application has only one main menu bar)  AcadMenuGroups object, which indicates that the AutoCAD menu and toolbar describes the approximate composition of the AutoCAD Activex interface object model, which focuses on the AcadDocuments object, because most of the programming is It is related. First of all, everyone sees it is a plural form, so it is a collection of all graphics of AutoCad, which is called a collection object (huh, it seems to be nonsense). Collective objects have some more important methods and features. The most important one is: count features are used to get the number of objects (from zero) in the collection; the ITEM method is used to get any objects in the collection. I will introduce them in the examples below. ACADDocuments' singular form acaddocument represents an AutoCAD graphic currently open. AcadDocument object consists of the following main objects:  AcadModelSpace collection and AcadpaPerspace collection, providing access to graphic objects (straight lines, circles, etc.) Acadlayers, AcadlineTypes, and AcadTextStyles, provide non-graphic objects (layer, line style, Text style, etc.) Access  Acadplot object provides access to the "Print" dialog box, and provides the application process with various methods of printing graphics, Acadutility objects provide user input and conversion function graphics objects.

Methods, for example, to create a circle, use the AddCircle method, not the creation of the graphics object, using the Add method.

The following describes the contents described above by a simple example. This example is a new layer in AutoCAD and then draws a red circle and a green straight line in this layer. This is the source code of the program: (please include the interop.autocad.dll and autocadexample.dll files generated in the previous lecture) in the project)

Using system;

Using acadexample;

Using AutoCAD;

Namespace Circleline

{

///

/// Class1 summary description. /// Class Class1 {/// // The primary invested point of the application. /// [stathread] static void main (string [] args) {//// Todo: Add code here to start the application // use (AutoCadConnector Connector = new autocadConnector ()) // Connect AutoCAD {Acaddocument Adocuments = Connector.Application.ActiveDocument; // get the current autocad activity graphic object double [] center = new double [3] {20, 20, 0}; // Set the center Double Radius = 20; // Set the circular radius Double [ ] startpoint = new double [3] {0,0,0}; // Set the starting point Double [] endpoint = new double [3] {40, 40, 0}; // Set the straight line of the line acadlayer new, = adocument .Layers.add ("circleline"); // Create a new layer called CircleLine Adocument.AntiveLayer = NewLayer; // Set the CircleLine layer to the current layer acadcircle Circle = adocument.modelspace.addcircle (Center, RADIUS); / / Join circular acadline line = adocument.modelspace.addline (startpoint, endpoint); // Add straight line Circle.Color = acad_color.acred; // Turn round to red line.color = acad_color.acgreen; // Transform straight line Green Connector.Application.Update (); // Update Display for (INT i = 0; iconLe.writeline ("This is the {0} object: {1}", i 1, adocument.modelspace.Item (i ))); // Traverse the current graphics

}

Console.readline ();

}

}

}

Ok, I am here today.

转载请注明原文地址:https://www.9cbs.com/read-22174.html

New Post(0)