.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change 3d Polyline data via Datatable

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
cschildmeier
1508 Views, 4 Replies

Change 3d Polyline data via Datatable

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();
        }
    }
}

 

4 REPLIES 4
Message 2 of 5
Hallex
in reply to: cschildmeier

Hi cshildmeier,

Try compile all files in to project (class library include Form1)

Tested in A2010 only

Oleg

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 5
cschildmeier
in reply to: Hallex

It was a busy weekend Hallex, sorry for the late response. I'm going to give this a go now, thank you very much.



-Chris
Message 4 of 5
cschildmeier
in reply to: Hallex

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

Message 5 of 5
Hallex
in reply to: cschildmeier

Smiley HappyYou're welcome, Chris

Knock my door again

Cheers 🙂

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost