Author Topic: write description for all polyline  (Read 1393 times)

0 Members and 1 Guest are viewing this topic.

A-SABER

  • Mosquito
  • Posts: 11
write description for all polyline
« on: February 05, 2021, 07:36:51 PM »
the folwing code to write polyline name in each polyline the result is the same pic it's ok
I need to write a description for all parcels using code
same like this
PH 101
NORTH ---
SOUTH PH 105
EAST PH 103
WEST ---

anther example
PH 106
NORTH PH 103 
SOUT PH 109
EAST PH 106
WEST PH 105


check each parcel if has parcel in north ok write it, not has parcel, not written.
 and the same check-in (SOUTH - EAST - WEST )


Code - C#: [Select]
  1.  public static void polylinenumber()
  2.         {
  3.             double txth = 1;
  4.             int snumber = 101;
  5.             Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  6.             Database db = doc.Database;
  7.             Editor ed = doc.Editor;
  8.             using (Transaction trans = db.TransactionManager.StartTransaction())
  9.             {
  10.                 try
  11.                 {
  12.                     BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  13.                     BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  14.                     TypedValue[] tv = new TypedValue[1];
  15.                     tv.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 0);
  16.                     SelectionFilter filter = new SelectionFilter(tv);
  17.                     PromptSelectionResult ssPrompt;
  18.                     ssPrompt = ed.GetSelection(filter);
  19.                     if (ssPrompt.Status == PromptStatus.OK)
  20.                     {
  21.                         SelectionSet ss = ssPrompt.Value;
  22.                         List<Polyline> lspl = new List<Polyline>();
  23.                         foreach (SelectedObject sObj in ss)
  24.                         {
  25.                             Polyline poly = trans.GetObject(sObj.ObjectId, OpenMode.ForWrite) as Polyline;
  26.                             lspl.Add(poly);
  27.                            
  28.                         }
  29.                         var sortedpolyList = lspl.OrderByDescending(p => p.StartPoint.Y).ThenBy(p => p.StartPoint.X);
  30.                         //var sortedpolyList = lspl.OrderByDescending(p => p.StartPoint.Y).ThenBy(p => p.StartPoint.X);
  31.                         foreach (Polyline item in sortedpolyList)
  32.                         {                          
  33.  
  34.                                 DBText txtpl = new DBText();
  35.                                 txtpl.SetDatabaseDefaults();
  36.                                 txtpl.TextString = "PH "+ snumber.ToString();
  37.                            //Point3d p2 = PolylineExtensions.Centroid(item);
  38.                                 txtpl.Position = PolylineExtensions.Centroid(item);
  39.                             txtpl.Rotation = 0;
  40.                                 txtpl.Height = txth;
  41.                                 btr.AppendEntity(txtpl);
  42.                                 trans.AddNewlyCreatedDBObject(txtpl, true);
  43.                                 snumber++;                            
  44.                         }
  45.                         trans.Commit();
  46.                     }
  47.                 }
  48.                 catch (System.Exception ex)
  49.                 {
  50.                     ed.WriteMessage("Error pls chek " + ex.Message);
  51.                     trans.Abort();
  52.                 }
  53.             }
  54.         }
« Last Edit: February 13, 2021, 12:40:37 AM by A-SABER »