Error when submitting resultbuffer to xdata

Error when submitting resultbuffer to xdata

Anonymous
Not applicable
1,875 Views
2 Replies
Message 1 of 3

Error when submitting resultbuffer to xdata

Anonymous
Not applicable

I'm still new to AutoCAD programming.  I'm taking over some code from a developer that is no longer here.  Right now when the code saved a resultbuffer object to xdata, I get an eregappidnotfound.  Due to various forums, I believe this is because the ID is not being registered with the database before it's beign inserted.

 

The error is thrown on this line: XData.ToXData(partCollection);

using (Autodesk.AutoCAD.DatabaseServices.DBObject dbObj = t.GetObject(objId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite))
{
DeviceName.SetDeviceName((Autodesk.AutoCAD.DatabaseServices.BlockReference)dbObj, txtDeviceName.Text);
dbObj.XData = XData.ToXData(partCollection); t.Commit(); }

 The code for the ToXData function is here: 

public static ResultBuffer ToXData(PartCollection Parts)
    {
        //Write out some header information
        ResultBuffer rb = new ResultBuffer(new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataRegAppName), XDATA_APP_NAME), new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataInteger16), XDATA_TYPE), new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataInteger16), XDATA_SUBTYPE), new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataRegAppName), XDATA_Part_NAME), new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataInteger16), Parts.Count));

        //Write the individual Parts
        for (int i = 0; i <= Parts.Count - 1; i++)
        {
            rb.Add(new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataRegAppName), XDATA_Part_NAME + (i + 1)));
            rb.Add(new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataInteger16), Parts[i].Quantity));
            rb.Add(new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataAsciiString), Parts[i].IdentNumber));
            rb.Add(new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataAsciiString), Parts[i].Description));
            rb.Add(new TypedValue(System.Convert.ToInt32(DxfCode.ExtendedDataAsciiString), Parts[i].Location));
            rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, System.ComponentModel.TypeDescriptor.GetProperties(typeof(Part))["Purchase"].Converter.ConvertToString(Parts[i].Purchase)));
            rb.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, System.ComponentModel.TypeDescriptor.GetProperties(typeof(Part))["SpareWear"].Converter.ConvertToString(Parts[i].SpareWear)));
        }
        return rb;
    }

 I realize that's a lot of code, but in short it takes a list of Part objects, iterates through each, then adds them to a resultbuffer.  The code works when only 1 or 2 parts are in the partCollection.  If 3 or more parts are in the collection, I get the eregappidnotfound error.  

 

Can anyone point em in the right direction?

0 Likes
Accepted solutions (1)
1,876 Views
2 Replies
Replies (2)
Message 2 of 3

Alexander.Rivilis
Mentor
Mentor
Accepted solution

eregappidnotfound error means that there is no record in RegAppTable RegAppTableRecord. Check it out. If you want to add Xdata Parts [i] then RegAppTableRecord named XDATA_Part_NAME + (i + 1) should already be in RegAppTable.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you.  That confirms what I had guessed. Combining your code snippet with the code from the documentation, I was able to create a working solution. Documentation code

0 Likes