马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[ 本帖最后由 csharp 于 2014-4-26 10:25 编辑 ]\n\n[ 本帖最后由 csharp 于 2014-4-26 10:20 编辑 ]
- [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)]
- public void MyCommand() // This method can have any name
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- Transaction tr = db.TransactionManager.StartTransaction();
- BlockTableRecord Spase = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- PromptSelectionOptions selectionOptions = new PromptSelectionOptions();
- selectionOptions.RejectObjectsOnLockedLayers = true;
- SelectionFilter selectionFilter = new SelectionFilter(
- new TypedValue[] {new TypedValue(0, "*line")}
- );
- selectionOptions.MessageForAdding = "\n选择线: ";
- PromptSelectionResult ssResult = ed.GetSelection(selectionOptions, selectionFilter);
- if (ssResult.Status != PromptStatus.OK) return;
- ObjectId oId = ssResult.Value.GetObjectIds()[0];
- using (tr)
- {
- try
- {
- Point3dCollection pts = new Point3dCollection();
- Entity cvEntity = (Entity) tr.GetObject(ssResult.Value.GetObjectIds()[0], OpenMode.ForRead);
- cvEntity.GetStretchPoints(pts);
- PromptSelectionResult ssSet = ed.SelectFence(pts, selectionFilter);
- if (ssSet.Status != PromptStatus.OK) return;
- SelectionSet selectionSet = ssSet.Value;
- var ids = ssSet.Value .GetObjectIds() ;
- for (int i = 0; i < ids .Length ; i++)
- {
- ObjectId id = ids[i];
- if (id != oId)//排除断开线
- {
- FenceSelectedObject fsSelectedObject = selectionSet[i] as FenceSelectedObject;
- Point3d pt = fsSelectedObject.GetIntersectionPoints()[0].PointOnLine;
- Curve cv = (Curve)tr.GetObject(id, OpenMode.ForWrite);
- Point3d pt1 = cv.GetClosestPointTo(pt, true);
- double pam = cv.GetParameterAtPoint(pt1);
- if (pam > 1e-6)
- {
- DoubleCollection pamDoubleCollection = new DoubleCollection();
- pamDoubleCollection.Add(pam);
- DBObjectCollection cvsCollection = cv.GetSplitCurves(pamDoubleCollection);
- foreach (DBObject o in cvsCollection)
- {
- Spase.AppendEntity((Entity)o);
- tr.AddNewlyCreatedDBObject(o, true);
- }
- }
- }
- }
- tr.Commit();
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
网上看了几个类似功能程序,都是用的IntersectWith,上面的程序用了 GetInterselectionPoints(),但是只取了一个交点,不适合有多个交点情况,以后改进,这个和 ssnamex 中取得穿越点一样,但是不适合Z值不同的 3D 线,标高要在一个平面上
另外不知道和UCS有无关系,仅在 WCS测试Ok
选择线要在可见范围内 |