Author Topic: break command can not work, coordinates are too far away from the origin.  (Read 1427 times)

0 Members and 1 Guest are viewing this topic.

Tutulisper

  • Mosquito
  • Posts: 11
break command can not work, coordinates are too far away from the origin.
if move the line to ‘(0 0 0) point,it can break well.
Can you write a program to solve this problem   c# or lisp code.

Tutulisper

  • Mosquito
  • Posts: 11
Code - C#: [Select]
  1.      [CommandMethod("BRKPL")]
  2.         public void BreakLineOrPolyline()
  3.         {
  4.             var doc = Acad.DocumentManager.MdiActiveDocument;
  5.             var db = doc.Database;
  6.             var ed = doc.Editor;
  7.             var entityOptions = new PromptEntityOptions("\nSelect line or polyline: ");
  8.             entityOptions.SetRejectMessage("Selected object is neither a line nor a polyline.");
  9.             entityOptions.AddAllowedClass(typeof(Polyline), true);
  10.             entityOptions.AddAllowedClass(typeof(Line), true);
  11.             var entityResult = ed.GetEntity(entityOptions);
  12.             if (entityResult.Status != PromptStatus.OK)
  13.                 return;
  14.             Point3d pt1, pt2;
  15.             var ucs = ed.CurrentUserCoordinateSystem;
  16.             var pointOptions = new PromptPointOptions("\nSpecify second point or [First point]: ", "First");
  17.             var pointResult = ed.GetPoint(pointOptions);
  18.             if (pointResult.Status == PromptStatus.Keyword)
  19.             {
  20.                 pointOptions.Message = "\nSpecify first point: ";
  21.                 pointOptions.Keywords.Clear();
  22.                 pointResult = ed.GetPoint(pointOptions);
  23.                 if (pointResult.Status != PromptStatus.OK)
  24.                     return;
  25.                 pt1 = pointResult.Value.TransformBy(ucs);
  26.                 pointOptions.Message = "\nSpecify second point: ";
  27.                 pointResult = ed.GetPoint(pointOptions);
  28.                 if (pointResult.Status != PromptStatus.OK)
  29.                     return;
  30.                 pt2 = pointResult.Value.TransformBy(ucs);
  31.             }
  32.             else if (pointResult.Status == PromptStatus.OK)
  33.             {
  34.                 pt1 = entityResult.PickedPoint.TransformBy(ucs);
  35.                 pt2 = pointResult.Value.TransformBy(ucs);
  36.             }
  37.             else return;
  38.  
  39.             using (var tr = db.TransactionManager.StartTransaction())
  40.             {
  41.                 var curve = (Curve)tr.GetObject(entityResult.ObjectId, OpenMode.ForWrite);
  42.                 double param1 = curve.GetParameterAtPoint(curve.GetClosestPointTo(pt1, false));
  43.                 double param2 = curve.GetParameterAtPoint(curve.GetClosestPointTo(pt2, false));
  44.                 var parameters = new DoubleCollection
  45.                     (new[] { param1, param2 }
  46.                     .Distinct()
  47.                     .OrderBy(x => x)
  48.                     .ToArray());
  49.                 var curves = curve.GetSplitCurves(parameters);
  50.                 var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
  51.                 switch (curves.Count)
  52.                 {
  53.                     case 3:
  54.                         curSpace.AppendEntity((Entity)curves[0]);
  55.                         tr.AddNewlyCreatedDBObject(curves[0], true);
  56.                         curSpace.AppendEntity((Entity)curves[2]);
  57.                         tr.AddNewlyCreatedDBObject(curves[2], true);
  58.                         curves[1].Dispose();
  59.                         curve.Erase();
  60.                         break;
  61.                     case 2:
  62.                         curSpace.AppendEntity((Entity)curves[0]);
  63.                         tr.AddNewlyCreatedDBObject(curves[0], true);
  64.                         curSpace.AppendEntity((Entity)curves[1]);
  65.                         tr.AddNewlyCreatedDBObject(curves[1], true);
  66.                         curve.Erase();
  67.                         break;
  68.                     default:
  69.                         break;
  70.                 }
  71.                 tr.Commit();
  72.             }
  73.         }
  74.  
the code in the "test.dwg" can not work  if move the line to '(0 0 0) can work well.