Storing entities using XRecords

Storing entities using XRecords

youssefGC
Advocate Advocate
739 Views
6 Replies
Message 1 of 7

Storing entities using XRecords

youssefGC
Advocate
Advocate

Hello everyone,

I am working on data storage with XRecords. Currently, I am facing an issue: I want to store a list of polylines "List<Polyline>" within an entity (for example, a dimension). However, this is not possible because the nature of the storage does not allow storing entities. The current solution I have is to store, for each polyline, the list of vertices and bulges. In cases where we need to retrieve the polylines, we directly plot the points with the bulges. Is there another solution?

 

0 Likes
740 Views
6 Replies
Replies (6)
Message 2 of 7

_gile
Consultant
Consultant

Hi,

You can store entities (ObjectId) in xrecords as SoftPointers (or HardPointers) by using the SoftPointerId (330) (or HardPointerId (340))  DxfCodes.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 7

youssefGC
Advocate
Advocate

Thank you for the reply,

In my case, the entities are not added to the drawing database and never appear (these are polylines that are used later in other processes with the program).

 

0 Likes
Message 4 of 7

ActivistInvestor
Mentor
Mentor

Hi, you can add the entities to an anonymous block.

Message 5 of 7

_gile
Consultant
Consultant

@youssefGC wrote:

In my case, the entities are not added to the drawing database.


If so, you can only store the polyline data (e.g., vertices and bulges).

You could organize these data into an AutoCAD DataTable which can be directly attached to a DBDictionary.

Here's a simple example of methods to create a DataTable from a Polyline and create back a Polyline from a DataTable.

        static DataTable CreateDataTable(Polyline pline, string tableName)
        {
            var table = new DataTable();
            table.TableName = tableName;
            table.AppendColumn(CellType.Double, "X");
            table.AppendColumn(CellType.Double, "Y");
            table.AppendColumn(CellType.Double, "Bulge");
            for (int i = 0; i < pline.NumberOfVertices; i++)
            {
                var point = pline.GetPoint2dAt(i);
                var x = new DataCell();
                x.SetDouble(point.X);
                var y = new DataCell();
                y.SetDouble(point.Y);
                var bulge = new DataCell();
                bulge.SetDouble(pline.GetBulgeAt(i));
                var row = new DataCellCollection { x, y, bulge };
                table.AppendRow(row, true);
            }
            return table;
        }

        static Polyline CreatePolyline(DataTable table)
        {
            var pline = new Polyline();
            for (int i = 0; i < table.NumRows; i++)
            {
                double x = (double)table.GetCellAt(i, 0).Value;
                double y = (double)table.GetCellAt(i, 1).Value;
                double bulge = (double)table.GetCellAt(i, 2).Value;
                pline.AddVertexAt(i, new Point2d(x, y), bulge, 0.0, 0.0);
            }
            return pline;
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 6 of 7

youssefGC
Advocate
Advocate

Thank you very much for the code.

One question remains: what is the storage mechanism in the xrecords (DxfCode does not support data as "DataTable") ?

 

0 Likes
Message 7 of 7

_gile
Consultant
Consultant

You do not need an Xrecord with a DataTable, you add it to the DBDictionary the same way as with Xrecord:

var dataTable = CreateDataTable(pline, "Polyline 1");
dictionary.SetAt("PolylineTable1", dataTable);

And you get it the same way:

var table = (DataTable)tr.GetObject(dictionary.GetAt("PolylineTable1"), OpenMode.ForRead);
var pline = CreatePolyline(table);


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub