Using SendCommand twice results in a run-time error "Invalid execution context"

Using SendCommand twice results in a run-time error "Invalid execution context"

Anonymous
Not applicable
4,864 Views
27 Replies
Message 1 of 28

Using SendCommand twice results in a run-time error "Invalid execution context"

Anonymous
Not applicable

I'm really hoping that someone can help.

 

I just upgraded from AutoCAD 2015 to AutoCAD 2016 and now my VBA App (which I spent the last several months developing) won't work. Here is the issue. Keep in mind that this all ran flawlessly in AutoCAD 2015.

 

There are a couple of places whereI have to use the SendCommand function due to a VBA method not being available or the users wanting visual feedback (gohsting and what-not) that you can't do in VBA. Whenever I use the SendComman more than once it results in this run-time error.

 

Error.JPG

 

Here is some example code:

 

Sub test()
    ThisDrawing.SendCommand "(command ""PLINE"")" & vbCr
    
    ThisDrawing.SendCommand "(command ""PLINE"")" & vbCr '<- This line errors
End Sub

If i run this from AutoCAD using:

-VBARUN "test"
or
(vl-vbarun "test")

it results in the error above whne trying to run the second SendCommand. The first SendCommand run fine. I've tried seperating them out into different sub routines but the result is the same.

 

Here is the intersting part. If I exectur this code from the VBAIDE it runs perfectly fine. The error only occurs when I execute it from AutoCAD.

 

Any help would be greatly apriciated. Thanks!

 

0 Likes
Accepted solutions (2)
4,865 Views
27 Replies
Replies (27)
Message 2 of 28

Anonymous
Not applicable
I guess at the very least, can someone confirm that they see the same behavior on AutoCAD 2016?
That way I know it's not something local to me or my organization's environment?
0 Likes
Message 3 of 28

Anonymous
Not applicable
Accepted solution

I seem to have solved the problem.

I did a clean uninstall of ALL Autodesk products. Reinstalled 2015. Renistalled 2016. Uninstalled 2015.

And now it seems to be working.

0 Likes
Message 4 of 28

Anonymous
Not applicable
Accepted solution

I found out what is causing the SendCommand error.

It is the AutoCAD 2016 service pack 1 (AutoCAD_2016_SP1_64bit.exe)

I started to have the issue after I installed it.

I rolled back the SP1 and now it works fine; although I lose all the 2016 bug fixes.

0 Likes
Message 5 of 28

Anonymous
Not applicable

Michael,

 

Interesting. I thought I had installed the service pack as part of my reinstall process. But I just checked the Autodesk Application Manager and it looks like I haven't.

 

If I'm adventurous I may install it to see what happens but after fighting so long to get it to work I'm not too keen on that.

0 Likes
Message 6 of 28

Anonymous
Not applicable

Has anyone figured out a fix or at least a work around besides uninstalling 2016 SP1?

 

I'm desparate I have multiple clients with many installations using thousands of lines of code with the occasional, unavoidable use of two sendcommands in the same macro.

 

David

0 Likes
Message 7 of 28

Balaji_Ram
Alumni
Alumni

Hi All,

 

Sorry that the SP1 has broken a basic functionality.

 

We have this behavior logged with our engineering team and they are looking into it.

 

From what i see in the case notes of that request, this is already assigned high priority.

 

At present, i do not know how the fix for it will be provided - whether as a service pack or a hotfix.

If there is any more information on this request, i will let you know.

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 28

Anonymous
Not applicable

Hello All,

 

I have found a work around this problem.

In stead of Using "ThisDrawing.SendCommand" with a parameter list, you can use "ThisDrawing.PostCommand" with the same parameter list.

The command will then be processed asynchronously in stead of synchronously, but with the same parameter list it will behave the same way.

I used this work around in a macro where I print multiple drawing views, using a loop.

 

I hope this is some helpfull information for you all.

 

Kind regards

Ronald Gilissen

 

Message 9 of 28

Anonymous
Not applicable

Thanks for the tip. Unfortunately I need my command to process synchronously. So the PostCommand would not work in my case.

0 Likes
Message 10 of 28

Anonymous
Not applicable

Hello,

 

I have added the exact same parameter list to the postcommand, as i dit with the sedmcommand. In my case the program runs exacly the same way

as it dit with the sendcommand. see code example below.

 

'ThisDrawing.SendCommand "-plot" & vbCr & "y" & vbCr & "Model" & vbCr & Printer & vbCr & "A4" _
'& vbCr & "M" & vbCr & "P" & vbCr & "Y" & vbCr & "W" & vbCr & SPntLO & vbCr & SPntRB & vbCr & "F" & vbCr & "C" _
'& vbCr & "Y" & vbCr & "COEK.ctb" & vbCr & "Y" & vbCr & "A" & vbCr & "N" & vbCr & "N" & vbCr & "Y" & vbCr

 

ThisDrawing.PostCommand "-plot" & vbCr & "y" & vbCr & "Model" & vbCr & Printer & vbCr & "A4" _
& vbCr & "M" & vbCr & "P" & vbCr & "N" & vbCr & "W" & vbCr & SPntLO & vbCr & SPntRB & vbCr & "F" & vbCr & "C" _
& vbCr & "Y" & vbCr & "COEK.ctb" & vbCr & "Y" & vbCr & "A" & vbCr & "N" & vbCr & "N" & vbCr & "Y" & vbCr

 

Kind regards,

Ronald

 

0 Likes
Message 11 of 28

Anonymous
Not applicable

Hi Ronald-

I did a "find & replace" of sendcommand to postcommand in my code.

Although the error message is gone, the end result was different. My module is not working as intended with postcommand. 

I will wait for Autodesk to fix sendcommand.

0 Likes
Message 12 of 28

Anonymous
Not applicable

I wonder if there would be a way to use the pause to wait until the asynchronous command is done.  Is there a way to check and see if an asynchronous command is done?

 

David

0 Likes
Message 13 of 28

Anonymous
Not applicable

Hi Michael,

 

Michael, I'm sorry to hear that it didn't work for you. 

Some websites mension that you should add an "& VbCr" at the end of the command, maybe this works for you,

otherwise I don't think there is any other solution except waiting for the autocad fix. I hope it comes soon!

 

Kind regards

Ronald

0 Likes
Message 14 of 28

Anonymous
Not applicable

Hi dlford,

 

I am not aware of any way to check if the assynchronous command has ended.

Try adding the "& VbCr" at the end of the command (see previous post)

 

Kind regards

Ronald

 

0 Likes
Message 15 of 28

Anonymous
Not applicable

Ronald,

 

All the "& vbCr" does is add a carriage return to the command string. It's the same thing as pressing enter into the command line.

In all my research and testing there is no way to force an asynchronous coammand (PostCommand) to be synchronous.

The only thing I have found to solve this issue is to roll back the install of SP1. I have been running for several months now (as with everyone else in my orginiization) without SP1 with no issues.

 

Cheers!

0 Likes
Message 16 of 28

Anonymous
Not applicable

Does anyone know if this also happens in VB.net as well as VBA?

 

David

0 Likes
Message 17 of 28

Anonymous
Not applicable

Is now a solution available?

0 Likes
Message 18 of 28

Anonymous
Not applicable

Is there any solution for this?  I have clients that I've done programming for really mad because they can't install SP1.  Will AutoCAD 2017 have this problem?

 

David

0 Likes
Message 19 of 28

paulleinweber
Participant
Participant

I am experiencing the same issue when installing from a trial install that included Service Pac 1, as part of the install.

0 Likes
Message 20 of 28

danipon71
Enthusiast
Enthusiast

Hi Balaji,

 

Is now avaliable an hotfix for the problem ? We have a lot hot drawbacks with SP1 of Autocad 2016.

 

Keep me informed,

 

Daniele.

0 Likes