Error eRegappIdNotFound is getting when i am submitting resultbuffer to Xdata

Error eRegappIdNotFound is getting when i am submitting resultbuffer to Xdata

manohar2375
Advocate Advocate
2,555 Views
6 Replies
Message 1 of 7

Error eRegappIdNotFound is getting when i am submitting resultbuffer to Xdata

manohar2375
Advocate
Advocate

Hello All,

I am trying to attached XData to polyline but getting error Message = "eRegappIdNotFound" and please see the below code which i have written.

 

private void addXdataToPolyline(Polyline pline)
{
try
{
ResultBuffer plineXData = new ResultBuffer();
plineXData.Add(BaseXData.ApplicationName());
plineXData.Add(new TypedValue((int)DxfCode.ExtendedDataInteger16, 1002));
plineXData.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "MyLayerName"));
using (Transaction tran = pline.ObjectId.Database.TransactionManager.StartTransaction())
{
Entity ent = (Entity)tran.GetObject(pline.ObjectId, OpenMode.ForWrite);
ent.XData = plineXData;
tran.Commit();
}
}
catch (System.Exception ex)
{
var ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage($"{ex.Message}\n{ex.StackTrace}");
}

 

BaseXData.ApplicationName() is the function which will return [0]|{1001,ABC)} and plineXdata object contains below values:

 

[0]|{(1001,ABC}
[1]|{(1070,1002}
[2]|{(1002,MyLayerName}

 

Kindly help me where i did mistake then i will learn and proceed my work.

 

Thanks in Advance.

0 Likes
Accepted solutions (1)
2,556 Views
6 Replies
Replies (6)
Message 2 of 7

_gile
Consultant
Consultant

Hi,

 

You have to check if the regap already exists and, if not, create it.

 

private void AddXdataToPolyline(Polyline pline)
{
    var db = pline.Database;
    using (var tr = db.TransactionManager.StartTransaction())
    {
        var regAppTable = (RegAppTable)tr.GetObject(db.RegAppTableId, OpenMode.ForRead);
        if (!regAppTable.Has("ABC"))
        {
            var regApp = new RegAppTableRecord();
            regApp.Name = "ABC";
            tr.GetObject(db.RegAppTableId, OpenMode.ForWrite);
            regAppTable.Add(regApp);
        }
        var xdata = new ResultBuffer(
            new TypedValue(1001, "ABC"),
            new TypedValue(1017, 1002),
            new TypedValue(1002, YourLayerName));
        pline.XData = xdata;
        tr.Commit();
    }
}


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 7

manohar2375
Advocate
Advocate

Hello gile,

Good morning.

Thanks for your support and i have used above source code but i am getting error message ex.Message = "eInvalidResBuf".

 

Could you please suggest on this.

 

Thanks in Advance.

0 Likes
Message 4 of 7

_gile
Consultant
Consultant

Oops!... A typo.

replace; new TypedValue(1017, 1002) with: new TypedValue(1070, 1002)



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 7

manohar2375
Advocate
Advocate

Hello gile,

I have done this 'new TypedValue(1070, 1002)' then tried but it was hang at pline.XData = xdata;

 

Kindly help on this.

 

Thanks in Advance.

 

 

0 Likes
Message 6 of 7

_gile
Consultant
Consultant
Accepted solution

You did not show the code related to the polyline. the polyline have to be opened for write.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 7

manohar2375
Advocate
Advocate

Hi Sir,

Sorry for delay response and thanks for your support.

And i found my mistake and i am good to move further.

 

Again thanks for your valuable support.

0 Likes