- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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?
Solved! Go to Solution.

