Using objectdbx technology in C # never open a graphic to get information about a tile

Source: Internet
Author: User
Tags dbx visual studio
Object| Graphics never open a graphic to get information about a tile? The answer is yes. Here is a description of the implementation of the specific method.
Requirements:

n is programmed with C #

N Read what I wrote "Two development of AutoCAD using C #" (In Csdn)

Begin:

n Create a new C # console program in Visual Studio.NET

n Add the following class libraries to the Reference tab:

L Interop. AutoCAD.dll

L AcadExample.dll

L ObjectDBX16 (In Solution Explorer, right-click the References tab, select Add Reference in the pop-up menu, and in the Add Reference dialog box, select the Autocad/objectdbx Common 16.0 in the Drop-down list box under the COM tab) Type Library "Item)

Then type the following code:

1:using System;

2:using AutoCAD;

3:using dbx = Axdblib;

4:using acadexample;

5:

6:namespace ConsoleApplication1

7: {

8:///<summary>

9:///Summary description for Class1.

Ten:///</summary>

11:class Class1

12: {

:///<summary>

///The main entry point for the application.

:///</summary>

: [STAThread]

17:static void Main (string[] args)

18: {

19:using (autocadconnector connector = new Autocadconnector ())

20: {

21:string ProgID = "objectdbx.axdbdocument.16"/note that this is the AutoCAD2004 writing,

If AutoCAD2002 and autocad2000i are "Objectdbx.axdbdocument.1,"

22:acadapplication Acadapp = connector. Application;

23:dbx. Axdbdocument Dbxdoc;

24:dbxdoc = (dbx. axdbdocument) Acadapp.getinterfaceobject (ProgID);

25:dbxdoc.open (@ "F:\TEST.DWG");

26:foreach (dbx. Acadentity entity in Dbxdoc.modelspace)

27: {

28:if (entity. EntityName = = "Acdbblockreference")//Determine whether the entity is a block reference

29: {

30:dbx. Acadblockreference Blkref;

31:blkref = (dbx. Acadblockreference) entity; Cast the entity that is a block reference to a block reference type

32:object[] Atts = (object[]) blkref.getattributes ()//Get the property in the block reference (for object type)

33:for (int i = 0; i < Atts. Length; i++)//Traverse block Reference properties

34: {

35:dbx. Acadattributereference att;

36:att = (dbx. acadattributereference) atts;//cast a block reference property (object type) to a block reference property type

37:console.writeline ("Tag: {0}\tvalue: {1}\n",

38:att. Tagstring,

39:att. TextString);//Display the value of tag and text for the Block reference property

40:}

41:}

42:}

43:console.readline ();

44:}

45:}

46:}

47:}

The first one to note is the third line, which uses an alias. Because the AutoCAD and Objectdbx namespaces have many of the same class names, you must use the full name instead of the shorthand form, but objectdbx is more cumbersome to write, so use the alias DBX to make the input easier.

The code in the previous part of the program, you can refer to the article I wrote "Two development of AutoCAD using C #". Let's look at line 21st, where the program defines a string ProgID as the getinterfaceobject of the 24th function, which is used to produce a Axdbdocument object. Note, however, that the type returned by the Getinterfaceobject function is object, so you must use the cast to change it to the Axdbdocument class. Then, on line 25th, use the Axdbdocument object generated by line 24 to "open" a. dwg file (which is not actually open), and it should be noted that the path to this file must be correct. This file is the file where we want to get the block information.

Because OBJECTDBX does not have a selection set, only the Block's information (26-28 rows) is obtained by traversing the file's model space.

The statement of the remaining statements I have written in the comments of the program.

You can see that objectdbx's work is similar to VBA in C #, except for the necessary type conversions.


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.