- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[ 本帖最后由 csharp 于 2014-5-7 06:25 编辑 ]\n\n改编自 飞诗 程序,原帖地址 [url=http://bbs.mjtd.com/thread-79764-1-1.html]http://bbs.mjtd.com/thread-79764-1-1.html[/url]
原本想尝试返回断开后的曲线选择集,对 DBObject 转 ObjectId 不得要领,继续学习
曲线在 ssget 过滤
(ssbrk (ssget '((0 . "*line,arc,circle,ray"))))
- [LispFunction ("ssbrk")]
- public void BlkInt(ResultBuffer rb)
- {
- if (rb != null)
- {
- TypedValue[] values = rb.AsArray();
- if (values.Count() == 1 && values[0].TypeCode == (int) LispDataType.SelectionSet)
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- Transaction tr = doc.TransactionManager.StartTransaction();
- BlockTableRecord Spase = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- using ( tr)
- {
- try
- {
- SelectionSet ssSet = (SelectionSet)values[0].Value;
- ObjectId[] ssbrk = ssSet.GetObjectIds();
- Dictionary<Curve, List<double>> objpts;
- objpts = new Dictionary<Curve, List<double>>(ssbrk.Length);
- Curve[] cvs = new Curve[ssbrk.Length];
- Entity[] ents = new Entity[ssbrk.Length];
- for (int i = 0; i < ssbrk.Length; i++)
- {
- ents[i] = ssbrk[i].GetObject(OpenMode.ForRead) as Entity;
- }
- for (int i = ssbrk.Length - 1; i > -1; i--)
- {
- //Curve cv = tr.GetObject(ssbrk[i], OpenMode.ForWrite) as Curve;
- Curve cv = ssbrk[i].GetObject(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];
- Entity ent1 = ents[cur];
- List<double> cv1ps = objpts[cv1];
- for (int n = cur - 1; n > -1; n--)
- {
- Curve cv2 = cvs[n];
- Entity ent2 = ents[n];
- List<double> cv2ps = objpts[cv2];
- Point3dCollection points = new Point3dCollection();
- //cv1.IntersectWith(cv2, Intersect.OnBothOperands, points, 0, 0);
- ent1.IntersectWith(ent2, Intersect.OnBothOperands, points, IntPtr.Zero, IntPtr.Zero);
- foreach (Point3d pt in points)
- {
- cv1ps.Add(cv1.GetParameterAtPoint(pt));
- cv2ps.Add(cv2.GetParameterAtPoint(pt));
- }
- }
- }
- foreach (KeyValuePair<Curve, List<double>> var in objpts)
- {
- Curve cv = var.Key;
- if (var.Value.Count == 0)//没有交点
- {
- continue;
- }
- else
- {
- 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++;
- Entity ent = (Entity)dbobj;
- Spase.AppendEntity(ent);
- tr.AddNewlyCreatedDBObject(ent, true);
- }
- }
- cv.Erase();
- }
- }
- tr.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
- }
|
|