从选择集中加入实体
public void start(){
Document acadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database acadDb = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
int i = 1, z = 1;
using (Transaction tr = acadDoc.TransactionManager.StartTransaction())
{
try
{
ObjectIdCollection coll = clsSelection.Sset3dPolyline();
foreach (ObjectId id in coll)
{
//ed.WriteMessage("\n" + i++ + " Entiy: " + id.ObjectClass.DxfName + " Typ: " + id.ObjectClass.Name);
Polyline3d pol = id.GetObject(OpenMode.ForRead) as Polyline3d;
ObjectId oId = pol.ObjectId;
Point3d sPt = pol.StartPoint;
Point3d ePt = pol.EndPoint;
foreach (ObjectId id2 in coll)
{
Polyline3d pol2 = id2.GetObject(OpenMode.ForRead) as Polyline3d;
Point3d sPt2 = pol.StartPoint;
Point3d ePt2 = pol.EndPoint;
bool test1 = id != id2;
bool test2 = sPt.Equals(sPt2);
bool test3 = sPt2.Equals(ePt);
bool test4 = ePt2.Equals(sPt);
//if (test1 && test2 || test3 || test4)
//{
//pol.JoinEntity(pol2);
大家好!
我想尝试用JoinEntity()方法连接多段线。我的想法是在一个选择集中收集所有的三维折线,然后函数寻找在不同三维折线的起点或/和终点的实体(三维折线)。我在想什么,在Lisp中,它有能力通过ssget-function选择不同的对象。我不知道,怎么办。网?!所以也许有可能找到正确的三维折线来连接它们?!
**** Hidden Message ***** 您好,
也许您可以从PolylineSegmentCollection中获得一些灵感。GeometryExtensions中的Join()方法。 嗨,Gile!
谢谢。
我在C:\Windows\Microsoft.NET\Framework中没有找到引用Geometry扩展。我必须在哪里寻找它们?!
对不起,瞎了 点击我回复中的链接。 伟大的工作Gile,我必须阅读 - 它非常适合2D绘图对象 - 我尝试了你的函数“mjoin”与GeometryExtensions 嗨,吉尔!
1...它有什么理由为什么不在以下位置使用 JoinEntity:Autodesk.AutoCAD.DatabaseServices.Entity.JoinEntity(Autodesk.AutoCAD.DatabaseServices.Entity)
2...对我来说很难理解(在Acad API中有几个月的时间经验)类GeometryExtensions中的所有metods,你能解释一下,你如何加入例如Polylines(在你的情况下2d)
3...如果我尝试为Polyline3d设置PolylineSegmentCollection,我必须收集哪些属性我不确定
如何在AcadDB中命令“mjoin”中加入新的Polylines, 您是否正在删除并构建新的Polyline2d?!
抱歉有不好的问题,我是新手
A 第一次试用
public PolylineSegmentCollection(Polyline3d pline)
{
ObjectId[] vertices = pline.Cast().ToArray();
//PolylineVertex3d[] vertices = pline.Cast().ToArray();
int n = vertices.Length - 1;
for (int i = 0; i ().ToArray();
ed.WriteMessage("\nNumber of vertexes: {0}", verts.Length);
for (int i = 0; i < verts.Length; i++)
{
PolylineVertex3d vt = tr.GetObject(verts, OpenMode.ForRead) as PolylineVertex3d;
coll.Add(new Point3d(vt.Position, vt.Position, vt.Position));
}
tr.Commit();
}
return coll;
}
static public void Append3dPolylines()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Point3dCollection collPoint3d = null;
Point3dCollection allPoint3d = null;
PromptEntityOptions peo1 = new PromptEntityOptions("\nSelect source polyline : ");
peo1.SetRejectMessage("\nInvalid selection...");
peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
PromptEntityResult res = ed.GetEntity(peo1);
if (PromptStatus.OK != res.Status)
return;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable BlkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord BlkTblRec = trans.GetObject(BlkTbl, OpenMode.ForWrite) as BlockTableRecord;
Polyline3d newPoly = new Polyline3d();
BlkTblRec.AppendEntity(newPoly);
trans.AddNewlyCreatedDBObject(newPoly, true);
try
{
collPoint3d = GetVertex(res);
allPoint3d = new Point3dCollection();
foreach (Point3d pt in collPoint3d)
{
allPoint3d.Add(pt);
}
while (true)
{
PromptEntityOptions peo2 = new PromptEntityOptions("\nSelect polyline to join : ");
peo2.SetRejectMessage("\nInvalid selection...");
peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
res = ed.GetEntity(peo2);
switch (res.Status)
{
case PromptStatus.OK:
collPoint3d = GetVertex(res);
foreach (Point3d pt in collPoint3d)
{
allPoint3d.Add(pt);
}
break;
case PromptStatus.Cancel:
foreach (Point3d pt in allPoint3d)
{
PolylineVertex3d vertex = new PolylineVertex3d(pt);
newPoly.AppendVertex(vertex);
trans.AddNewlyCreatedDBObject(vertex, true);
}
ed.WriteMessage("\nNew 3dPolyline created!");
return;
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
trans.Commit();
}
}
也许这个试验也应该在Selectionset中工作。选择3dPolyline简单,如果在start或endpoint
之后选择3dPolyline也没关系。请测试它,也许您知道它如何在Selectionset中工作。在那里,它必须检查start或endpoint
static public void join3d()
{
Document document = Application.DocumentManager.MdiActiveDocument;
Editor ed = document.Editor;
Database db = document.Database;
PromptEntityOptions peo1 = new PromptEntityOptions("\nSelect source polyline : ");
peo1.SetRejectMessage("\nInvalid selection...");
peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), true);
peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline2d), true);
peo1.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
PromptEntityResult res = ed.GetEntity(peo1);
if (PromptStatus.OK != res.Status)
return;
ObjectId srcId = res.ObjectId;
while (true)
{
PromptEntityOptions peo2 = new PromptEntityOptions("\nSelect polyline to join : ");
peo2.SetRejectMessage("\nInvalid selection...");
peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), true);
peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline2d), true);
peo2.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline3d), true);
res = ed.GetEntity(peo2);
switch (res.Status)
{
case PromptStatus.OK:
ObjectId joinId = res.ObjectId;
try
{
using (Transaction trans = db.TransactionManager.StartTransaction())
{
Entity srcPLine = trans.GetObject(srcId, OpenMode.ForRead) as Entity;
Entity addPLine = trans.GetObject(joinId, OpenMode.ForRead) as Entity;
srcPLine.UpgradeOpen();
srcPLine.JoinEntity(addPLine);
addPLine.UpgradeOpen();
addPLine.Erase();
trans.Commit();
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
break;
case PromptStatus.Cancel:
ed.WriteMessage("\nFinished!");
return;
}
}
}
中的3dPolyline ErrorStatus=AlreadyInDB
我收到此异常,无法理解。有人能理解并解决吗
在poly中。附加顶点(vex3d);不对劲。
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Polyline3d poly = new Polyline3d();
btr.AppendEntity(poly);
tr.AddNewlyCreatedDBObject(poly, true);
foreach (Polyline3DPoints segs in psc)
{
Entity pline = (Entity)tr.GetObject(segs.ObjectID, OpenMode.ForWrite);
foreach (ObjectId vId in (Polyline3d)pline)
{
PolylineVertex3d vex3d = (PolylineVertex3d)tr.GetObject(vId, OpenMode.ForRead);
poly.AppendVertex(vex3d);
tr.AddNewlyCreatedDBObject(vex3d, true);
}
}
}
catch (System.Exception ex)
{ }
tr.Commit();
您好,
您必须为新的Polyline3d(多边形)创建新的polylinevertex3d。现在,您正在尝试将不同的多段线(psc、pline)顶点(vId)设置为新的
我不知道psc集合中有什么,但我预计会有Polyline3d的集合。
-Veli
页:
[1]