Im rewriting an application from vb6 to vb.net, using the Autocad COM interface (the refactoring for the .net sdk will come in the future)
I have a connection to the drawing, i can read entities, xdata, etc.
The following code (late binding) gives a type mismatch error. What am i doing wroing?
Dim obj As Object = Nothing Dim pnt(2) As Double doc.Utility.GetEntity(obj, pnt, "Select something")
Solved! Go to Solution.
if you look to the signature of .GetEntity you find:
Sub GetEntity(ByRef Object As Object, ByRef PickedPoint As Object, Optional Prompt As Object = Nothing)
So you have to pass a variable of type Object to the function, after the function returned you can cast it to an array of doubles.
Dim obj As Object = Nothing Dim pnt() as double
try Dim pntObj as Object = Nothing
doc.Utility.GetEntity(obj, pntObj, "Select something")
pnt = ctype(pntObj, double())
'err-msg if you need one
The try-catch is just done to make sure that a <ESC> done by the user instead of selecting an object does not crash your code.
FYI: there is a special dotNET-for-AutoCAD forum >>>here<<<.
HTH, - alfred -
Thank you for your reply.
I did try it as an object first, but that didn't work either
I keep getting a type mismatch
Dim obj As Object = Nothing Try Dim pnt As Object = Nothing doc.Utility.GetEntity(obj, pnt, "test") Catch ex As Exception Return False End Try
I thought the other forum was for the autocad .net sdk. i'll try it as well
It should work (and it does work for me/within my code)
Have you tried to create a mini sample command and use this lines? Just to make shure you have no conflicts with anything in your code before.
At the moment I have no other idea what's going on here.
- alfred -
The following sample gives the same error:
Dim obj as Object = Nothing
Try Dim pnt As Object = Nothing doc.Utility.GetEntity(obj) Catch ex As Exception Return False End Try
When i give no parameters i get an error that the number of parameters is not correct. That's fine, but that would imply
- that there is an overload accepting 1 parameter
- that the 'obj' parameter is of the wrong type
Calling doc.Utility.Prompt("test") does work
What AutoCAD version do you work with? When I look to the object-catalog (don't know if that is the same name in the english version) I can't see any overload for .GetEntity (looking to Autodesk.AutoCAD.Interop for AutoCAD 2012).
Are you sure that you referenced the correct version (matching to your AutoCAD release)?
- alfred -
I know there is no documentation of an overload. Maybe i'm complicating the issue here:
The original call 'GetEntity(obj, pnt, "Select")) failed with a type mismatch, but i don't know which of the 3 parameters is of the wrong type. That is why i tried calling GetEntity with 0 and 1 parameter
0 parameters gave an error that i needed more parameters, while 1 parameter gave the type mismatch
I see only one signature and that defines the third parameter as optional. So you can try to use 2 parameters (entity and point) or three parameters as you had tried it.
Have you tried to define a small command just for testing that line?
- alfred -
After i connect to Autocad, this code is when i press a button, so i can't get much cleaner than that i think
One thing i can think of: Does the Autocad window have to be in front the moment this code is executed?
My application obviously has focus when i rpess the button
>> this code is when i press a button
So you have a form or usercontrol in a palette from where you are starting this code?
If you have a form, is this defined to be started in modal-state?
- alfred -
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register