AutoCAD 2010/2011/2012

Reply
Contributor
pderuiter77
Posts: 14
Registered: ‎01-09-2013
Message 1 of 14 (842 Views)
Accepted Solution

vb.net + COM GetEntity gives type mismatch

842 Views, 13 Replies
01-09-2013 03:48 AM

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")

 

Patrick

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 2 of 14 (838 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 04:15 AM in reply to: pderuiter77

Hi,

 

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.

 

Try that

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())
catch
'err-msg if you need one
end try

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 -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
pderuiter77
Posts: 14
Registered: ‎01-09-2013
Message 3 of 14 (837 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 04:29 AM in reply to: Alfred.NESWADBA

Thank you for your reply.

 

I did try it as an object first, but that didn't work either :smileyhappy:

 

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 4 of 14 (831 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 04:37 AM in reply to: pderuiter77

Hi,

 

animierte smilies erstaunt überraschung überrascht  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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
pderuiter77
Posts: 14
Registered: ‎01-09-2013
Message 5 of 14 (830 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 04:40 AM in reply to: Alfred.NESWADBA

Strange

 

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 6 of 14 (822 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 04:46 AM in reply to: pderuiter77

Hi,

 

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
pderuiter77
Posts: 14
Registered: ‎01-09-2013
Message 7 of 14 (821 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 04:52 AM in reply to: Alfred.NESWADBA

Autocad 2012

 

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

 

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 8 of 14 (819 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 05:05 AM in reply to: pderuiter77

Hi,

 

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Contributor
pderuiter77
Posts: 14
Registered: ‎01-09-2013
Message 9 of 14 (817 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 05:22 AM in reply to: Alfred.NESWADBA

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

*Expert Elite*
Alfred.NESWADBA
Posts: 8,866
Registered: ‎06-29-2007
Message 10 of 14 (815 Views)

Re: vb.net + COM GetEntity gives type mismatch

01-09-2013 05:34 AM in reply to: pderuiter77

Hi,

 

>> 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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community




Connect with AutoCAD

Twitter

Facebook

Blogs

Pinterest

Youtube