用曲线选择集A,于交点处打断选择集B
程序功能:用曲线选择集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;
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;
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.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;
for (int i = ssbrk.Count - 1; i > -1; i--)
{
Curve cv = tr.GetObject(ssbrk.ObjectId, OpenMode.ForWrite) as Curve;
cvs = cv; objpts.Add(cv, new List<double>());
}
for (int cur = cvs.Length - 1; cur > -1; cur--)
{
Curve cv1 = cvs;
List<double> cv1ps = objpts;
for (int n = cur - 1; n > -1; n--)
{
Curve cv2 = cvs;
List<double> cv2ps = objpts;
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.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();
}
}
}
}
还要去找那么多库函数dll,在C#里编译,封装到dll 回帖是一种美德!感谢楼主的无私分享 谢谢 回帖是一种美德!感谢楼主的无私分享 谢谢 <p>这个文件的后缀名是什么啊?.dll吗?</p> 收到了。飞诗兄 <p>不错!!!!</p> 有代码,但是怎么使用呢?新手诚心求教!! 飞诗是个不错的工具集。我用过,不过我想自己学习学习 有LISP的吗? 好东东 顶起来! 好东西,感谢分享 这是.dll 还是运行.exe
?