Question

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.

Was it helpful?

Solution

The error message is telling you one or both the data types in your call to method SetXData is not correct.

I don't have personal experience with what you're trying to do but I suggest changing the data type of xDataStrings to an array of objects:

object[] xDataStrings;

Check out this thread on the autodesk forums. Sample .NET code is posted which may help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top