I've had a go at this without using the jig and it works well for a while then throws an error "Internal error scandr 40" This is caused by a combo of the regen and the pline not being kosher. If you add a break at pl.AppendVertex(v); and hover over the pl you will see a list of exceptions. Where do they come from???
class pline3d
{
[CommandMethod("p3d")]
public void pl3d()
{
Document doc=acadApp.DocumentManager.MdiActiveDocument;
Editor ed=doc.Editor;
Matrix3d ucs=ed.CurrentUserCoordinateSystem;
Point3dCollection c = new Point3dCollection();
Point3d baseP,p;
bool bAddVertex=true;
string msg = "\nSelect vertex point for self-Closing Polyline: ";
if (!getpoint(msg, ref p)) return;
baseP=p;
c.Add(p.TransformBy(ucs));
if(!getpoint(msg,baseP,ref p)) return;
c.Add(p.TransformBy(ucs));
ObjectId id= makePline3d(c);
baseP = p;
do
{
if (!getpoint(msg, baseP, ref p)) return;
baseP = p; p = p.TransformBy(ucs);
bAddVertex = addVertex(id, p);
ed.Regen();//Take this out and nothing shows///////////////
}while (bAddVertex);
}
private bool addVertex(ObjectId id, Point3d p)
{
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
AcDb.Database db = ed.Document.Database;
try
{
using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
{
AcDb.Polyline3d pl = tr.GetObject(id, OpenMode.ForWrite) as Polyline3d;
AcDb.PolylineVertex3d v = new PolylineVertex3d(p);
pl.AppendVertex(v); ///////////////////Put a break here///////////////////////////////
// pl.InsertVertexAt(v.Id, v);
//pl.Draw();
tr.Commit();
}
}
catch (System.Exception ex)
{
WinForms.MessageBox.Show(ex.Message,
"Exception",
WinForms.MessageBoxButtons.OK,
WinForms.MessageBoxIcon.Error);
return false;
}
return true;
}
static bool getpoint(string msg, ref Point3d P)
{
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
PromptPointResult res = ed.GetPoint(msg);
if (res.Status != PromptStatus.OK)return false;
P = res.Value;
return true;
}
static bool getpoint(string msg,Point3d baseP,ref Point3d P)
{
Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
PromptPointOptions ppo = new PromptPointOptions(msg);
ppo.UseBasePoint = true;
ppo.BasePoint = baseP;
ppo.AllowArbitraryInput = true;
PromptPointResult res = ed.GetPoint(ppo);
if (res.Status != PromptStatus.OK)return false;
P = res.Value;
return true;
}
static ObjectId makePline3d(Point3dCollection c)
{
Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, c, false);
Database db = HostApplicationServices.WorkingDatabase;
using (AcDb.Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject
(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
btr.AppendEntity(pl);
tr.AddNewlyCreatedDBObject(pl, true);
tr.Commit();
}
return pl.ObjectId;
}
}