AutoCAD Architecture Customization
Welcome to Autodesk’s AutoCAD Architecture Customization Forums. Share your knowledge, ask questions, and explore popular AutoCAD Architecture Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setxdata & Getxdata w/ Visual Studio.net

10 REPLIES 10
Reply
Message 1 of 11
Anonymous
4092 Views, 10 Replies

Setxdata & Getxdata w/ Visual Studio.net

I am trying to use the setxdata & getxdata commands in Visual Studio.net and they error out every time. I was able to get them to work in VBA, but they won't work in visual studio.
I noticed that in VBA it doesn't like it when you put parenthesis around the parameters. The help file tells you to set it up the following way:

"object.SetXData XDataType, XData"

The problem may be in the fact that visual studio won't accept the parameters unless you have parenthesis around them. You are not allowed to build the project.

I can't just develop in VBA because I am designing it to work with another program. I haven't found an easy way to pass parameters back and forth with an outside program using VBA.

Has anyone else had this problem with "Setxdata" and "Getxdata" using visual studio.net? If so, did you find a solution to make it work?

I am having the same problem with the xrecord commands. I am sure they are related.
10 REPLIES 10
Message 2 of 11
Anonymous
in reply to: Anonymous

Matt, I'm am the worst person to answer this question because I know almost nothing about .NET. But, just about every time I've seen a post about .NET and parameters, the solution is that the type is incorrect. If you dimmed XData as a Variant (as you would in VBA), that's your issue, as .NET doesn't have that type. I would strongly suggest you post this in the VBA group, as they know much more than me. Also include the actual error. HTH, Danny Polkinhorn Matt Howland wrote: > I am trying to use the setxdata & getxdata commands in Visual Studio.net and they error out every time. I was able to get them to work in VBA, but they won't work in visual studio. > I noticed that in VBA it doesn't like it when you put parenthesis around the parameters. The help file tells you to set it up the following way: > > "object.SetXData XDataType, XData" > > The problem may be in the fact that visual studio won't accept the parameters unless you have parenthesis around them. You are not allowed to build the project. > > I can't just develop in VBA because I am designing it to work with another program. I haven't found an easy way to pass parameters back and forth with an outside program using VBA. > > Has anyone else had this problem with "Setxdata" and "Getxdata" using visual studio.net? If so, did you find a solution to make it work? > > I am having the same problem with the xrecord commands. I am sure they are related.
Message 3 of 11
Anonymous
in reply to: Anonymous

It's hard to say what your exact problem is without seeing your code. As Danny noted, it's very important to have your data types set correctly. Here's an example from my C# class at AU last year. It's iterating over a selection set and printing xdata values. Possibly it will help you spot where you went wrong. const string regAppName = "AU2003"; foreach (AutoCAD.AcadEntity ent in ss) { //Save the xdata with each selected entity ent.SetXData(XDataKey, XDataValue); //Retrieve the xdata //The data is saved as two out parameters of the type "object" object xDataKeysOut; object xDataValueOut; ent.GetXData(regAppName, out xDataKeysOut, out xDataValueOut); //cast the object types to arrays short[] xDataKeys = (short[]) xDataKeysOut; object[] xDataValue = (object[]) xDataValueOut; //Iterate the arrays and display the data for (int i = 0; i < xDataKeys.Length; i++) { Debug.WriteLine(xDataKeys + ": " + xDataValue); } } -- Bobby C. Jones "Matt Howland" wrote in message news:12134473.1081277385860.JavaMail.jive@jiveforum2.autodesk.com... > I am trying to use the setxdata & getxdata commands in Visual Studio.net and they error out every time. I was able to get them to work in VBA, but they won't work in visual studio. > I noticed that in VBA it doesn't like it when you put parenthesis around the parameters. The help file tells you to set it up the following way: > > "object.SetXData XDataType, XData" > > The problem may be in the fact that visual studio won't accept the parameters unless you have parenthesis around them. You are not allowed to build the project. > > I can't just develop in VBA because I am designing it to work with another program. I haven't found an easy way to pass parameters back and forth with an outside program using VBA. > > Has anyone else had this problem with "Setxdata" and "Getxdata" using visual studio.net? If so, did you find a solution to make it work? > > I am having the same problem with the xrecord commands. I am sure they are related.
Message 4 of 11
Anonymous
in reply to: Anonymous

Oops...got a little jiggy with my cut -n- paste. I left out the arrays that contained the xdata that's being set. const string regAppName = "AU2003"; short[] XDataKey = {1001, 1000, 1070}; object[] XDataValue = {regAppName, "Autodesk University!", 11}; And in the end, this is what will be printed for each entity selected: 1001: AU2003 1000: Autodesk University! 1070: 11 -- Bobby C. Jones "Bobby C. Jones" wrote in message news:40743832_1@newsprd01... > It's hard to say what your exact problem is without seeing your code. As > Danny noted, it's very important to have your data types set correctly. > Here's an example from my C# class at AU last year. It's iterating over a > selection set and printing xdata values. Possibly it will help you spot > where you went wrong. > > const string regAppName = "AU2003"; > > foreach (AutoCAD.AcadEntity ent in ss) > { > //Save the xdata with each selected entity > ent.SetXData(XDataKey, XDataValue); > > //Retrieve the xdata > //The data is saved as two out parameters of the type "object" > object xDataKeysOut; > object xDataValueOut; > ent.GetXData(regAppName, out xDataKeysOut, out xDataValueOut); > > //cast the object types to arrays > short[] xDataKeys = (short[]) xDataKeysOut; > object[] xDataValue = (object[]) xDataValueOut; > > //Iterate the arrays and display the data > for (int i = 0; i < xDataKeys.Length; i++) > { > Debug.WriteLine(xDataKeys + ": " + xDataValue); > } > } > -- > Bobby C. Jones > > "Matt Howland" wrote in message > news:12134473.1081277385860.JavaMail.jive@jiveforum2.autodesk.com... > > I am trying to use the setxdata & getxdata commands in Visual Studio.net > and they error out every time. I was able to get them to work in VBA, but > they won't work in visual studio. > > I noticed that in VBA it doesn't like it when you put parenthesis around > the parameters. The help file tells you to set it up the following way: > > > > "object.SetXData XDataType, XData" > > > > The problem may be in the fact that visual studio won't accept the > parameters unless you have parenthesis around them. You are not allowed to > build the project. > > > > I can't just develop in VBA because I am designing it to work with another > program. I haven't found an easy way to pass parameters back and forth with > an outside program using VBA. > > > > Has anyone else had this problem with "Setxdata" and "Getxdata" using > visual studio.net? If so, did you find a solution to make it work? > > > > I am having the same problem with the xrecord commands. I am sure they > are related. > >
Message 5 of 11
Anonymous
in reply to: Anonymous

Thank you for the reply. I am attaching my code so that you can take a look at it and let me know what you think. I am showing you both the VBA code and the VB.net code. The VBA code worked without any problems.

VBA Code:

Sub xdata()
Dim line As AcadLine
Dim pt1(2) As Double
Dim pt2(2) As Double
pt2(0) = 100: pt2(1) = 100
Dim xdatatype(0 To 1) As Integer
Dim xdata(0 To 1) As Variant
xdatatype(0) = 1001: xdatatype(1) = 1000
xdata(0) = "LineData": xdata(1) = "Data"
Set line = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
line.SetXData xdatatype, xdata
Dim xdatatyperet As Variant
Dim xdataret As Variant
line.GetXData "LineData", xdatatyperet, xdataret
Dim i
For Each i In xdataret
MsgBox (i)
Next
End Sub


Here is the code in VB.net with minor changes to accomodate the differences between the two. Directly below is the error message that I received.

"An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in AutocadChanges.exe

Additional information: Invalid argument type in SetXData method"

VB.net Code:

Sub xdata()
Dim line As AutoCAD.AcadLine
Dim pt1(2) As Double
Dim pt2(2) As Double
pt2(0) = 100 : pt2(1) = 100
Dim xdatatype(1) As Integer
Dim xdata(1) As Object
xdatatype(0) = 1001 : xdatatype(1) = 1000
xdata(0) = "LineData" : xdata(1) = "Data"
line = acaddoc.ModelSpace.AddLine(pt1, pt2)
line.SetXData(xdatatype, xdata)
Dim xdatatyperet As Object
Dim xdataret As Object
line.GetXData("LineData", xdatatyperet, xdataret)
Dim i
For Each i In xdataret
MsgBox(i)
Next
End Sub

Any help you can give would be much appreciated. Thanks.
Message 6 of 11
Anonymous
in reply to: Anonymous

Shortly after I posted this last reply, I stumbled across the answer. The problem was a data type problem. For VB.net the xdatatype has to be set to Int16 not Integer.

dim xdatatype as Int16

Thanks again for the help.
Message 7 of 11
Anonymous
in reply to: Anonymous

Dim xdatatype(1) As Short That should fix the problem. In VB6, which is what VBA in AutoCAD is based on, the Integer type is a 16 bit signed integer. In .NET the Integer type is a 32 bit signed integer. The 16 bit signed integer type in VB.NET, and C# btw, is the Short type. Well, if you want to get real picky it's System.Int16, but who's that anal :-) -- Bobby C. Jones "Matt Howland" wrote in message news:27497870.1081859645404.JavaMail.jive@jiveforum1.autodesk.com... > Thank you for the reply. I am attaching my code so that you can take a look at it and let me know what you think. I am showing you both the VBA code and the VB.net code. The VBA code worked without any problems. > > VBA Code: > > Sub xdata() > Dim line As AcadLine > Dim pt1(2) As Double > Dim pt2(2) As Double > pt2(0) = 100: pt2(1) = 100 > Dim xdatatype(0 To 1) As Integer > Dim xdata(0 To 1) As Variant > xdatatype(0) = 1001: xdatatype(1) = 1000 > xdata(0) = "LineData": xdata(1) = "Data" > Set line = ThisDrawing.ModelSpace.AddLine(pt1, pt2) > line.SetXData xdatatype, xdata > Dim xdatatyperet As Variant > Dim xdataret As Variant > line.GetXData "LineData", xdatatyperet, xdataret > Dim i > For Each i In xdataret > MsgBox (i) > Next > End Sub > > > Here is the code in VB.net with minor changes to accomodate the differences between the two. Directly below is the error message that I received. > > "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in AutocadChanges.exe > > Additional information: Invalid argument type in SetXData method" > > VB.net Code: > > Sub xdata() > Dim line As AutoCAD.AcadLine > Dim pt1(2) As Double > Dim pt2(2) As Double > pt2(0) = 100 : pt2(1) = 100 > Dim xdatatype(1) As Integer > Dim xdata(1) As Object > xdatatype(0) = 1001 : xdatatype(1) = 1000 > xdata(0) = "LineData" : xdata(1) = "Data" > line = acaddoc.ModelSpace.AddLine(pt1, pt2) > line.SetXData(xdatatype, xdata) > Dim xdatatyperet As Object > Dim xdataret As Object > line.GetXData("LineData", xdatatyperet, xdataret) > Dim i > For Each i In xdataret > MsgBox(i) > Next > End Sub > > Any help you can give would be much appreciated. Thanks.
Message 8 of 11
CodeBug
in reply to: Anonymous

Hi Matt/All,

 

Even I am stuck with "Invalid argument type in SetXData method" error even though set the datatype to int16 as explained in the replies here.

 

Have you been able to get through this ?

 

Please help..

 

 

Message 9 of 11
optimistms
in reply to: Anonymous

today i faced the same problem, but after changing to int16, the problem got solved. Please can you explain further if your need help.Smiley Happy

Message 10 of 11
CodeBug
in reply to: Anonymous

Optimistms,

 

The issue got resolved once I changed to int16 and object type for xdatatype and xdata respectively.
Smiley Happy

 

Thank you

Message 11 of 11
optimistms
in reply to: CodeBug

Nice and Welcome

--
Thanks and regards

OptimistMS

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost