.NET

Reply
Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 1 of 3 (374 Views)
Accepted Solution

Error when submitting resultbuffer to xdata

374 Views, 2 Replies
02-21-2013 07:02 AM

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?

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1

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.

Moderator
Alexander.Rivilis
Posts: 1,417
Registered: ‎04-09-2008
Message 2 of 3 (357 Views)

Re: Error when submitting resultbuffer to xdata

02-21-2013 07:39 AM in reply to: bsee1

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.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 3 of 3 (328 Views)

Re: Error when submitting resultbuffer to xdata

02-21-2013 01:48 PM in reply to: Alexander.Rivilis

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

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.