- 积分
- 1052
- 明经币
- 个
- 注册时间
- 2010-9-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2011-7-13 16:23:06
|
显示全部楼层
public DBObjectCollection polylink(DBObjectCollection ids)
{
DBObjectCollection polyIds = new DBObjectCollection();
bool IsEmpty = false;
if (ids.Count < 1)
{
IsEmpty = true;
return polyIds;
}
while(!IsEmpty)
{
Polyline pl0 = ids[0] as Polyline;
Polyline pl = new Polyline();
Point2d plst = pl0.GetPoint2dAt(0);
Point2d plet = pl0.GetPoint2dAt(1);
pl.AddVertexAt(pl.NumberOfVertices, plst, 0, 0, 0);
pl.AddVertexAt(pl.NumberOfVertices, plet, 0, 0, 0);
ids.RemoveAt(0);
bool close=false;
while (!close)
{
foreach (DBObject polyid in ids)
{
Polyline poly = polyid as Polyline;
if (poly.Length == 0)
{
ids.Remove(polyid);
}
if (pl.EndPoint == poly.StartPoint)
{
pl.AddVertexAt(pl.NumberOfVertices, new Point2d(poly.EndPoint.X, poly.EndPoint.Y), 0, 0, 0);
ids.Remove(polyid);
}
else if (pl.EndPoint == poly.EndPoint)
{
pl.AddVertexAt(pl.NumberOfVertices, new Point2d(poly.StartPoint.X, poly.StartPoint.Y), 0, 0, 0);
ids.Remove(polyid);
}
if (pl.EndPoint == pl.StartPoint)
{
close=true;
pl.Closed=true;
}
}
if (ids.Count<1)
{
close = true;
}
}
if (pl.EndParam >= 2)
{
pl.ColorIndex = 2;
polyIds.Add(pl);
}
if (ids.Count<1)
{
IsEmpty = true;
}
}
return polyIds;
}
[CommandMethod("linkTst")]
public void linkTst()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
TypedValue[] fillist = new TypedValue[] { new TypedValue((int)DxfCode.Start, "Lwpolyline") };
SelectionFilter filter = new SelectionFilter(fillist);
PromptSelectionResult polyRes = ed.GetSelection(filter);
using (Transaction trans = db.TransactionManager.StartTransaction())
{
if (polyRes.Status == PromptStatus.Cancel)
{
return;
}
else if (polyRes.Status==PromptStatus.OK||polyRes.Status==PromptStatus.None)
{
SelectionSet polyset = polyRes.Value;
DBObjectCollection ids = new DBObjectCollection();
for (int i = 0; i < polyset.Count;i++ )
{
Polyline pl = trans.GetObject(polyset[i].ObjectId, OpenMode.ForWrite) as Polyline;
ids.Add(pl);
}
DBObjectCollection polyids= polylink(ids);
jinhe.ObjectARX.Tools.AddEntities(polyids);
}
trans.Commit();
}
}
这样测试就是正确滴喽,可能有错误没有测试出来吧!!!
|
|