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