I have a form that will allow a user to select a 3d Polyline from a drawing, and have it populate a DataTable(DataGrid inside DataTable). My seemingly simple task right now that I am struggling with is after changing the values in the DataGrid, pushing them BACK to Autocad(via Accept/Done button). I've tried a lot of different things attemping to get this working with no luck. I'm sure I'm missing something fundamentally. Any help would be greatly appreciated.
#if ACAD using AcRx = Autodesk.AutoCAD.Runtime; using AcTrx = Autodesk.AutoCAD.Runtime; using AcAp = Autodesk.AutoCAD.ApplicationServices; using AcDb = Autodesk.AutoCAD.DatabaseServices; using AcGe = Autodesk.AutoCAD.Geometry; using AcEd = Autodesk.AutoCAD.EditorInput; using AcGi = Autodesk.AutoCAD.GraphicsInterface; using AcClr = Autodesk.AutoCAD.Colors; using AcWnd = Autodesk.AutoCAD.Windows; using AcApP = Autodesk.AutoCAD.ApplicationServices.Application; using AcP = Autodesk.AutoCAD.Interop; #endif namespace PolylineEditor { public partial class Form1 : Form { private static System.Data.DataTable vertexTable; public Form1() { InitializeComponent(); ChangeVertex(); BindToDataGrid(); } static public void ChangeVertex() { AcAp.Document doc = AcAp.Application.DocumentManager.MdiActiveDocument; AcDb.Database db = doc.Database; AcEd.Editor ed = doc.Editor; using (var trans = db.TransactionManager.StartTransaction()) { var options = new AcEd.PromptEntityOptions("\nSelect a 3DPolyline:"); options.SetRejectMessage("That is not select a 3DPolyline" + "\n"); options.AddAllowedClass(typeof(AcDb.Polyline3d), true); var result = ed.GetEntity(options); if (result.Status != AcEd.PromptStatus.OK) return; var poly = (AcDb.Polyline3d)trans.GetObject(result.ObjectId, AcDb.OpenMode.ForWrite); var vertexClass = AcTrx.RXClass.GetClass(typeof(AcDb.PolylineVertex3d)); vertexTable = new System.Data.DataTable("Vertices"); vertexTable.Columns.Add("HandleId", typeof(long)); vertexTable.Columns.Add("PositionX", typeof(double)); vertexTable.Columns.Add("PositionY", typeof(double)); vertexTable.Columns.Add("PositionZ", typeof(double)); foreach (AcDb.ObjectId vertexId in poly) { if (!vertexId.ObjectClass.IsDerivedFrom(vertexClass)) continue; var vertex = (AcDb.PolylineVertex3d)trans.GetObject(vertexId, AcDb.OpenMode.ForWrite); vertexTable.Rows.Add(vertex.Handle.Value, vertex.Position.X, vertex.Position.Y, vertex.Position.Z); } } } private void BindToDataGrid() { dataGridView1.DataSource = vertexTable; } private void toolStripButton1_Click(object sender, EventArgs e) { ChangeVertex(); } private void btnApply_Click(object sender, EventArgs e) { } private void btnDone_Click(object sender, EventArgs e) { Form.ActiveForm.Close(); } } }
Solved! Go to Solution.
Solved by Hallex. Go to Solution.
Hi cshildmeier,
Try compile all files in to project (class library include Form1)
Tested in A2010 only
Oleg
I have a lot of other functionality to add, and adding/moving things around on the form. Other than that it works great. You're a life saver sir.
Can't thank you enough for your help.
-Chris
You're welcome, Chris
Knock my door again
Cheers 🙂