CAD two-time development technology based on C # programming language---exhibition measuring point coordinates

Source: Internet
Author: User

First, Introduction

AutoCAD is currently the most powerful drawing software in the world. In the surveying and mapping industry, using AutoCAD Direct drawing, or AutoCAD for the platform to develop a variety of drawing software to draw, greatly improve the accuracy, precision and speed of the drawing. Today, I'll show you how to write a. NET assembly that shows the coordinates of the field survey points into AutoCAD in C #.

Second, knowledge preparation

1, Understanding DAT file format, this time in the common format "name, code, east coordinates, north coordinates, elevation" for example.

2, file read, string processing

3. AutoCAD . NET Development Basics

Three, the need to pay attention to several points

1, mapping Scale (this code does not set the drawing scale function).

2, the difference between the measurement coordinate system and AutoCAD coordinate system: Axis direction, angle rotation.

3, by the way, in computer programming, the angle is the radian system, but the measurement is commonly used is the angle system, when the angle, it will inevitably appear in the angle and radian interchange. When writing the conversion code, it is important to pay attention to the precision of the programming language to avoid loss of precision.

Four

Five, with the source code, I hope you give a lot of advice!!!

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingAutodesk.AutoCAD.ApplicationServices;usingAutodesk.AutoCAD.DatabaseServices;usingAutodesk.AutoCAD.EditorInput;usingAutodesk.AutoCAD.Geometry;usingAutodesk.AutoCAD.Runtime;usingAutodesk.AutoCAD.Internal;usingSystem.Windows.Forms;usingSystem.IO;namespaceCAD exhibition Point { Public classClass1 {[Commandmethod ("Insertpoint")]         Public voidInsertpoint () {//Select the point file. datOpenFileDialog Opendlg =NewOpenFileDialog (); Opendlg.title="point file. dat"; Opendlg.filter="point file (*.dat) |*.dat";            Readdatfile Datfile; if(Opendlg.showdialog () = =DialogResult.OK) {datfile=NewReaddatfile (OpenDlg.FileName.ToString ()); }            Else            {                return; }            //get current document and databaseDocument Acdoc =Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database Accurdb=acdoc.database; //Start a transaction            using(Transaction Actrans =acCurDb.TransactionManager.StartTransaction ()) {                //open block table in read modeblocktable acblktbl; Acblktbl=Actrans.getobject (Accurdb.blocktableid, Openmode.forread) asblocktable; //Open Block table record model space in write modeBlocktablerecord Acblktblrec; Acblktblrec=Actrans.getobject (Acblktbl[blocktablerecord.modelspace], OPENMODE.FORW RITE) asBlocktablerecord; //Create Point                Try                {                    foreach(varIteminchdatfile.result) {//Point Position                        using(Dbpoint pt =NewDbpoint (NewPoint3D (item. X, item. Y, item. H)) {pt. ColorIndex=1; //adding new objects to block table records and transactionsacblktblrec.appendentity (PT); Actrans.addnewlycreateddbobject (PT,true); //releasing the DBObject object                        }                        //Roll Call                        using(Dbtext Actext =Newdbtext ()) {actext.position=NewPoint3D (item. x+0.25, item. Y-0.375, item.                            H); Actext.colorindex=1; Actext.height=1; Actext.widthfactor=0.8; Actext.textstring=item.                            Name;                            Acblktblrec.appendentity (Actext); Actrans.addnewlycreateddbobject (Actext,true); //releasing the DBObject object}} MessageBox.Show ("exhibition Point completed, co-exhibition"+datfile.result.count +"a little bit! "); }                Catch{MessageBox.Show ("Show Point failed! "); return; }                //emptying the collectiondatFile.Result.Clear (); //Change point styleAccurdb.pdmode = *; Accurdb.pdsize=0.5; //to save a new object to the databaseActrans.commit (); }                    }    }    classcoordinates { Public stringName {Get;Set; }  Public DoubleY ZGet;Set; }  Public DoubleYGet;Set; }  Public DoubleHGet;Set; }  PublicCoordinatesstringNameDoubleXDoubleYDoubleh) {Name=name; X=x; Y=y; H=h; }    }    classReaddatfile { Publiclist< coordinates > Result {Get;Set; }  PublicReaddatfile (stringfile) {Result=Newlist< coordinates >(); FileStream FS=NewFileStream (file, FileMode.Open, FileAccess.Read, fileshare.readwrite); StreamReader M_streamreader=NewStreamReader (FS); M_streamReader.BaseStream.Seek (0, Seekorigin.begin); stringStrLine =M_streamreader.readline (); intA1 = Strline.split (','). Length-1; //reads each row from the data stream until the last line of the filecoordinates pt;  while(StrLine! =NULL)            {                string[] s = strline.split (',');//note here that the spacer number in the DAT is a comma of half-width                Try{PT=NewCoordinates (s[0], convert.todouble (s[2]), convert.todouble (s[3]), convert.todouble (s[4]));                    Result.add (PT); StrLine=M_streamreader.readline (); }                Catch{MessageBox.Show ("check that the DAT coordinate format is: Roll Call, Code, East coordinate, North coordinate, elevation"); return; }} fs.            Close ();        M_streamreader.close (); }    }}

CAD two-time development technology based on C # programming language---exhibition measuring point coordinates

Related Article

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.