.NET Interface with AutoCAD -- SetXData errors.

Posted by Jerry on Stack Overflow See other posts from Stack Overflow or by Jerry
Published on 2010-04-01T16:38:54Z Indexed on 2010/04/01 16:43 UTC
Read the original article Hit count: 736

Filed under:
|
|

I am trying to use the SetXData method on the AutoCAD 2007 COM object, but it is throwing errors.

Example Test:

    public AcadEntity getAcadEntity()
    {
        /// ... Basic code to return a single AutoCAD entity...
    }

    private void btnTagItem_Click(object sender, EventArgs e)
    {
        AcadEntity ent = getAcadEntity();

        short[] xDataType;
        string[] xDataStrings;

        DrawingXData xData = new DrawingXData();

        xData.field1 = "Some Text Goes here";
        xData.field2 = 1;
        xData.field3 = 100;
        xData.field4 = 1509.2;
        xData.field5 = "More Text";

        BuildXData("AutoCad_App_Name", xData, out xDataType, out xDataStrings);

        ent.SetXData(xDataType, xDataStrings); // This line crashes.
    }

    private void BuildXData(string applicationName, DrawingXData xData, 
        out short[] xDataType, out string[] xDataStrings)
    {
        List<short> dataTypes = new List<short>();
        List<string> dataStrings = new List<string>();

        /// Code types...
        /// 1000 == String up to 255 bytes
        /// 1001 == Application Name

        // Set Applicaiton Name
        dataTypes.Add(1001); dataStrings.Add(applicationName);

        // Set Application Data
        dataTypes.Add(1000); dataStrings.Add(xData.field1.ToString());
        dataTypes.Add(1000); dataStrings.Add(xData.field2.ToString());
        dataTypes.Add(1000); dataStrings.Add(xData.field3.ToString());
        dataTypes.Add(1000); dataStrings.Add(xData.field4.ToString());
        dataTypes.Add(1000); dataStrings.Add(xData.field5.ToString());

        // ... etc.

        xDataType = dataTypes.ToArray();
        xDataStrings = dataStrings.ToArray();
    }

The error I get is "Invalid argument data in SetXData method".

The error code (if this helps anyone) is -2145320939.

The main reason I'm posting is because the same code in a very old VB6 application works just fine. I'm stumped.

© Stack Overflow or respective owner

Related posts about autocad

Related posts about xdata