I'm creating a windows form where a user will run a command in Autocad, it will prompt them to select an object(specifically 3d polylines). A 3d polyline can have a very wide range of Vertex's. I want each Vertex to be on/create it's own row. Each row having 5 columns(properties of each Vertex).

What's the proper container to use for this? I am expecting the user to be able to modify(change elevation for example) each and every property in each vertex. Along with actually deleting any vertices that they want to.

Table Layout Panel? Regular Panel? Here's the code of me "getting" the vertices:

        using (AcDb.Transaction oTr = db.TransactionManager.StartTransaction())
        {
            AcDb.ObjectIdCollection ids = new AcDb.ObjectIdCollection();

            AcEd.PromptEntityOptions options = new AcEd.PromptEntityOptions("\nSelect a 3DPolyline:");
            options.SetRejectMessage("That is not select a 3DPolyline" + "\n");
            options.AddAllowedClass(typeof(AcDb.Polyline3d), true);
            AcEd.PromptEntityResult result = ed.GetEntity(options);

            if (result.Status != AcEd.PromptStatus.OK) return;

            AcDb.Polyline3d oEnt = oTr.GetObject(result.ObjectId, AcDb.OpenMode.ForRead) as AcDb.Polyline3d;


            foreach (AcDb.ObjectId oVtId in oEnt)
            {
                AcDb.PolylineVertex3d oVt = oTr.GetObject(oVtId, AcDb.OpenMode.ForRead) as AcDb.PolylineVertex3d;
                //now to populate...something
有帮助吗?

解决方案

A DataTable would make sense when gathering the data.

using (var trans = db.TransactionManager.StartTransaction())
{
    var options = new PromptEntityOptions("\nSelect a 3DPolyline:");
    options.SetRejectMessage("That is not select a 3DPolyline" + "\n");
    options.AddAllowedClass(typeof(Polyline3d), true);
    var result = ed.GetEntity(options);

    if (result.Status != PromptStatus.OK)
        return;

    var poly = (Polyline3d)trans.GetObject(result.ObjectId, OpenMode.ForRead);
    var vertexClass = RXClass.GetClass(typeof(PolylineVertex3d));

    var 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 (ObjectId vertexId in poly)
    {
        if (!vertexId.ObjectClass.IsDerivedFrom(vertexClass))
            continue;

        var vertex = (PolylineVertex3d)trans.GetObject(vertexId, OpenMode.ForRead);
        vertexTable.Rows.Add(vertex.Handle.Value, vertex.Position.X, vertex.Position.Y, vertex.Position.Z);
    }

    trans.Commit();
}

Once you've got your vertex data in a table you can bind it to visual controls very easily.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top