- 积分
- 11049
- 明经币
- 个
- 注册时间
- 2005-2-6
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
程序功能:
用曲线选择集A,于交点处打断选择集B(当A,B相同则自相打断)
程序在2006,2010上测试通过。
请多指教!- using System.Collections.Generic;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Runtime;
- using Acad = Autodesk.AutoCAD.ApplicationServices.Application;
- [assembly:CommandClass(typeof (FsxmAcad.BrkAtInt))]
- namespace FsxmAcad
- {
- public class BrkAtInt : IExtensionApplication
- {
- #region IExtensionApplication 成員
- void IExtensionApplication.Initialize()
- {
- ed.WriteMessage("\n飞诗CAD - 交点打断(BrkInt)");
- }
- void IExtensionApplication.Terminate() { }
- #endregion
-
- Document doc = Acad.DocumentManager.MdiActiveDocument;
- Editor ed = Acad.DocumentManager.MdiActiveDocument.Editor;
- [CommandMethod("BrkInt", CommandFlags.UsePickSet)]
- public void BlkInt()
- {
- PromptSelectionOptions sop = new PromptSelectionOptions();
- try { sop.RejectObjectsOnLockedLayers = true; }
- catch { }
- SelectionFilter fil = new SelectionFilter
- (new TypedValue[] { new TypedValue(0, "*line,arc,circle,ellipse,ray") });
- sop.MessageForAdding = "\n选择边界曲线集:";
- PromptSelectionResult ss1 = ed.GetSelection(sop, fil);
- if (ss1.Status != PromptStatus.OK) return;
- sop.MessageForAdding = "\n选择要打断的曲线集<同边界>:";
- PromptSelectionResult ss2 = ed.GetSelection(sop, fil);
- if (ss2.Status == PromptStatus.Error)
- ss2 = ss1;
- else if (ss2.Status != PromptStatus.OK)
- return;
- SelectionSet ssbrk = ss2.Value;
- SelectionSet ssedge = ss1.Value;
- ed.WriteMessage("\n程序正在执行请稍候...");
- using (Transaction tr = doc.TransactionManager.StartTransaction())
- {
- ObjectId id = tr.GetObject(ss2.Value[0].ObjectId, OpenMode.ForRead).OwnerId;
- BlockTableRecord Spase = (BlockTableRecord)tr.GetObject(id, OpenMode.ForWrite);
- Dictionary<Curve, List<double>> objpts;
- objpts = new Dictionary<Curve, List<double>>(ssbrk.Count);
- if (ss1 != ss2)
- {
- #region 边界与打断不同
- foreach (ObjectId sid in ssbrk.GetObjectIds())
- {
- Curve cv1 = tr.GetObject(sid, OpenMode.ForWrite) as Curve;
- List<double> pas = new List<double>();
- objpts.Add(cv1, pas);
- foreach (SelectedObject sobj2 in ssedge)
- {
- Curve cv2 = tr.GetObject(sobj2.ObjectId, OpenMode.ForRead) as Curve;
- Point3dCollection points = new Point3dCollection();
- cv1.IntersectWith(cv2, Intersect.OnBothOperands, points, 0, 0);
- foreach (Point3d pt in points)
- {
- pas.Add(cv1.GetParameterAtPoint(pt));
- }
- }
- }
- #endregion
- }
- else
- {
- #region 边界与打断相同(优化)
- Curve[] cvs = new Curve[ssbrk.Count];
- for (int i = ssbrk.Count - 1; i > -1; i--)
- {
- Curve cv = tr.GetObject(ssbrk[i].ObjectId, OpenMode.ForWrite) as Curve;
- cvs[i] = cv; objpts.Add(cv, new List<double>());
- }
- for (int cur = cvs.Length - 1; cur > -1; cur--)
- {
- Curve cv1 = cvs[cur];
- List<double> cv1ps = objpts[cv1];
- for (int n = cur - 1; n > -1; n--)
- {
- Curve cv2 = cvs[n];
- List<double> cv2ps = objpts[cv2];
- Point3dCollection points = new Point3dCollection();
- cv1.IntersectWith(cv2, Intersect.OnBothOperands, points, 0, 0);
- foreach (Point3d pt in points)
- {
- cv1ps.Add(cv1.GetParameterAtPoint(pt));
- cv2ps.Add(cv2.GetParameterAtPoint(pt));
- }
- }
- }
- #endregion
- }
- foreach (KeyValuePair<Curve, List<double>> var in objpts)
- {
- Curve cv = var.Key;
- if (var.Value.Count == 0) continue;
- if (var.Value.Count == 1 && cv.IsPeriodic && cv.IsPersistent)
- continue;
- var.Value.Sort();
- double[] arrpt = new double[var.Value.Count];
- var.Value.CopyTo(arrpt);
- DoubleCollection pts = new DoubleCollection(arrpt);
- DBObjectCollection objs = cv.GetSplitCurves(pts);
- int brkn = 0;
- foreach (DBObject dbobj in objs)
- {
- Curve brks = (Curve)dbobj;
- if (cv.GetDistanceAtParameter(brks.EndParam) > 1e-6)
- {
- brkn++;
- Spase.AppendEntity(brks);
- tr.AddNewlyCreatedDBObject(brks, true);
- }
- }
- cv.Erase();
- }
- tr.Commit();
- }
- }
- }
- }
|
评分
-
参与人数 1 | 威望 +1 |
明经币 +2 |
金钱 +20 |
贡献 +5 |
激情 +5 |
收起
理由
|
雪山飞狐_lzh
| + 1 |
+ 2 |
+ 20 |
+ 5 |
+ 5 |
【精华】好程序 |
查看全部评分
|