你可以试着从头开始,
比较两个命令的作用
-
- [CommandMethod("ipLine")]
- public void IntersectTestIn()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = acadApp.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
- peo.SetRejectMessage("\nYou have to select the Line only >>");
- peo.AddAllowedClass(typeof(Line), false);
- PromptEntityResult res;
- res = ed.GetEntity(peo);
- if (res.Status != PromptStatus.OK)
- return;
- Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
- if (ent == null)
- return;
- Line line = (Line)ent as Line;
- if (line == null) return;
- peo = new PromptEntityOptions("\nSelect a Rectangle: ");
- peo.SetRejectMessage("\nYou have to select the Polyline only >>");
- peo.AddAllowedClass(typeof(Polyline), false);
- res = ed.GetEntity("\nSelect a Rectangle: ");
- if (res.Status != PromptStatus.OK)
- return;
- ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
- if (ent == null)
- return;
- Polyline pline = (Polyline)ent as Polyline;
- if (line == null) return;
- Point3dCollection pts = new Point3dCollection();
- pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0);
- if (pts.Count == 0) return;
- List<Point3d> points = new List<Point3d>();
- points.Add(line.StartPoint);
- points.Add(line.EndPoint);
- foreach (Point3d p in pts)
- points.Add(p);
- DBObjectCollection objs = line.GetSplitCurves(pts);
- List<DBObject> lstobj = new List<DBObject>();
- foreach (DBObject dbo in objs)
- lstobj.Add(dbo);
- points.Sort(delegate(Point3d p1, Point3d p2)
- {
- return Convert.ToDouble(
- Convert.ToDouble(line.GetParameterAtPoint(p1))).CompareTo(
- Convert.ToDouble(line.GetParameterAtPoint(p2)));
- }
- );
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- Line ln0 = lstobj[1] as Line;// middle
- Line ln1 = new Line(points[0], points[1]);
- Line ln2 = new Line(points[2], points[3]);
- if (!ln0.IsWriteEnabled)
- ln0.UpgradeOpen();
- ln0.Dispose();
- if (!ln1.IsWriteEnabled)
- ln1.UpgradeOpen();
- btr.AppendEntity(ln1);
- tr.AddNewlyCreatedDBObject(ln1, true);
- if (!ln2.IsWriteEnabled)
- ln2.UpgradeOpen();
-
- btr.AppendEntity(ln2);
- tr.AddNewlyCreatedDBObject(ln2, true);
- if (!line.IsWriteEnabled)
- line.UpgradeOpen();
- line.Erase();
- line.Dispose();
- ed.Regen();
- tr.Commit();
- }
- }
- [CommandMethod("opLine")]
- public void IntersectTest()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Document doc = acadApp.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- PromptEntityOptions peo = new PromptEntityOptions("\nSelect a Line >>");
- peo.SetRejectMessage("\nYou have to select the Line only >>");
- peo.AddAllowedClass(typeof(Line), false);
- PromptEntityResult res;
- res = ed.GetEntity(peo);
- if (res.Status != PromptStatus.OK)
- return;
- Entity ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
- if (ent == null)
- return;
- Line line = (Line)ent as Line;
- if (line == null) return;
- peo = new PromptEntityOptions("\nSelect a Rectangle: ");
- peo.SetRejectMessage("\nYou have to select the Polyline only >>");
- peo.AddAllowedClass(typeof(Polyline), false);
- res = ed.GetEntity("\nSelect a Rectangle: ");
- if (res.Status != PromptStatus.OK)
- return;
- ent = (Entity)tr.GetObject(res.ObjectId, OpenMode.ForRead);
- if (ent == null)
- return;
- Polyline pline = (Polyline)ent as Polyline;
- if (line == null) return;
- Point3dCollection pts = new Point3dCollection();
- pline.IntersectWith(line, Intersect.ExtendArgument, pts, 0, 0);
- if (pts.Count == 0) return;
- DBObjectCollection lstobj = line.GetSplitCurves(pts);
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- Line ln0 = lstobj[1] as Line;// middle
- Line ln1 = lstobj[0] as Line;
-
- Line ln2 = lstobj[2] as Line;
|