资源简介
添加两个dll引用,CAD安装文件夹下的acdb,acmgd;设置启动程序为acad.exe
代码片段和文件信息
/* Author:hyb
* Tele:18323432139
* Time:2014-8-11
* Discribtion:凸边界搜索函数
* */
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using System.Collections.Generic;
using System.Linq;
namespace Search
{
public class Class1
{
[CommandMethod(“hyb_T“)]
public void search()
{
DBPoint Ap;
DBPoint temp;
//获取图纸点集,并进行排序
DBobjectCollection dbc= Collection();
List pts = new List();
foreach (DBobject dbo in dbc)
{
if (dbo.GetType().Name.ToString() == “DBPoint“)
{
DBPoint pt = (DBPoint)dbo;
pts.Add(pt);
}
}
var m= pts.OrderBy(i => i.Position.X);
pts = m.ToList();
DBPoint[] DBps = pts.ToArray();
//计算临近边界点集,并绘制边界
Ap = pts[0];
temp = pts[1];
List ls=new List();
DBPoint End=new DBPoint();
do{
End = select(Ap temp DBps);
ls.Add(new Line(Ap.Position End.Position));
temp = Ap;
Ap = End;
} while (End != pts[0]);
foreach (Line l in ls)
{
ToModelSpace(l);
}
}
///
/// 选择集合
///
///
public static DBobjectCollection Collection()
{
Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Entity entity = null;
DBobjectCollection EntityCollection = new DBobjectCollection();
PromptSelectionResult ents = ed.GetSelection();
if (ents.Status == PromptStatus.OK)
{
using (Transaction transaction = db.TransactionManager.StartTransaction())
{
SelectionSet SS = ents.Value;
foreach (objectId id in SS.GetobjectIds())
{
entity = (Entity)transaction.Getobject(id OpenMode.ForWrite true);
if (entity != null)
EntityCollection.Add(entity);
}
transaction.Commit();
}
}
return EntityCollection;
}
///
/// 计算临近边界点
///
/// 起点
/// 终点
/// 点集
///
private DBPoint select(DBPoint spDBPoin
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7680 2014-08-12 10:08 Search\Search\bin\Debug\Search.dll
文件 15872 2014-08-12 10:08 Search\Search\bin\Debug\Search.pdb
文件 4718 2014-08-11 16:43 Search\Search\Class1.cs
文件 5819 2014-08-12 10:08 Search\Search\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 83467 2014-08-11 13:34 Search\Search\obj\Debug\ResolveAssemblyReference.cache
文件 7680 2014-08-12 10:08 Search\Search\obj\Debug\Search.dll
文件 15872 2014-08-12 10:08 Search\Search\obj\Debug\Search.pdb
文件 320 2014-08-11 14:42 Search\Search\obj\Debug\Search_T.csproj.FileListAbsolute.txt
文件 1362 2014-08-11 12:59 Search\Search\Properties\AssemblyInfo.cs
文件 2690 2014-08-11 13:34 Search\Search\Search_T.csproj
文件 386 2014-08-11 13:34 Search\Search\Search_T.csproj.user
文件 912 2014-08-11 13:34 Search\Search.sln
..A..H. 17920 2014-08-12 17:32 Search\Search.suo
文件 10 2014-08-12 10:23 Search\说明.txt
目录 0 2014-08-11 12:59 Search\Search\obj\Debug\TempPE
目录 0 2014-08-11 13:34 Search\Search\bin\Debug
目录 0 2014-08-12 10:08 Search\Search\obj\Debug
目录 0 2014-08-11 12:59 Search\Search\bin
目录 0 2014-08-11 12:59 Search\Search\obj
目录 0 2014-08-11 12:59 Search\Search\Properties
目录 0 2014-08-11 13:00 Search\Search
目录 0 2014-08-12 10:23 Search
----------- --------- ---------- ----- ----
164708 22
评论
共有 条评论