Cad.net Two development--find the 2 closest entities to a development point

Source: Internet
Author: User

 
Public Static classClass2 { Public Staticobjectid[] Fun (Point3D point) {Database db=hostapplicationservices.workingdatabase; Editor Ed=Application.DocumentManager.MdiActiveDocument.Editor; Point3dcollection points=Newpoint3dcollection (); List<string> Wenben =Newlist<string>(); List<Double> distance =Newlist<Double>(); Objectid[] s=Newobjectid[2]; Objectidcollection Textids=Newobjectidcollection (); Typedvalue[] Values=Newtypedvalue[] {NewTypedvalue ((int) Dxfcode.layername,"TK"), NewTypedvalue ((int) Dxfcode.start,"TEXT") }; Selectionfilter Selfilter=NewSelectionfilter (values); Promptselectionresult PSR=ed. SelectAll (Selfilter); if(PSR. Status = =Promptstatus.ok) {selectionset ss=PSR. Value; using(Transaction trans =db. Transactionmanager.starttransaction ()) {foreach(ObjectId IDinchSS. Getobjectids ()) {dbtext mytext= trans. GetObject (ID, Openmode.forread) asdbtext; if(MyText! =NULL) {points. ADD (MyText. Position); Wenben. ADD (MyText. TextString); //MyText. TextString = "";Textids. ADD (ID); Distance. ADD (point. Distanceto (MyText. Position)); }} trans.commit (); } } Else{ed. Writemessage ("Error");returns;} ////Bubbling Doubletemp =0;stringWenbentemp =""; ObjectId Tempid=NewObjectId (); for(inti = distance. Count; i >0; i--) { for(intj =0; J < i-1; J + +) { if(Distance[j] > distance[j +1]) {temp= Distance[j]; Wenbentemp = Wenben[j]; Tempid =Textids[j]; DISTANCE[J]= Distance[j +1]; WENBEN[J] = wenben[j +1]; TEXTIDS[J] = textids[j +1]; Distance[j+1] = temp; Wenben[j +1] = wenbentemp; Textids[j +1] =Tempid; } } } /////Bubble Ends[0] = textids[0]; s[1] = textids[1]; returns; } }


Learning points: Find the ID of the 2 entities closest to the set point, bubble Sort, selection set, and basic CAD two-time development process

Cad.net Two development--find the 2 closest entities to a development point

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.