Hello again!
My try to create a new 3dPolyline doesnīt create 3dPolyline in Drawing. allPoint3d-collection is true, not Exception callback ... whatīs wrong?!
public static Point3dCollection GetVertex(PromptEntityResult res)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Point3dCollection coll = new Point3dCollection();
using (Transaction tr = doc.TransactionManager.StartTransaction())
{
Polyline3d pl3d = tr.GetObject(res.ObjectId, OpenMode.ForRead) as Polyline3d;
ObjectId[] verts = pl3d.Cast<ObjectId>().ToArray();
ed.WriteMessage("\nNumber of vertexes: {0}", verts.Length);
for (int i = 0; i < verts.Length; i++)
{
PolylineVertex3d vt = tr.GetObject(verts[i], OpenMode.ForRead) as PolylineVertex3d;
coll.Add(new Point3d(vt.Position[0], vt.Position[1], vt.Position[2]));
}
tr.Commit();
}
return coll;
}
[CommandMethod("xx")]
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[BlockTableRecord.ModelSpace], 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();
}
}