Author Topic: cmdecho Question  (Read 2347 times)

0 Members and 1 Guest are viewing this topic.

Bill Tillman

  • Guest
cmdecho Question
« on: May 11, 2016, 03:16:30 PM »
I maintain an automated project that takes user input, sends that data through some pre-processing then onto a workstation which launches AutoCAD and prepares a drawing. The pre-processing all takes place with a C# project developed in Visual Studio. All has worked well for many months.

Recently a new developer joined the team and his code works in the pre-processing section. As before, we launch AutoCAD from this C# code and then using the SendCommand class we inject a bunch of variables and settings into AutoCAD which LISP programs use to create the drawings. In short, we set OSMODE, PICKBOX to the desired values and that's all cool. But in the past, I was always setting CMDECHO to 0 as well. The new code starts the LISP files which create the drawing and then it (the C# code) closes down the AutoCAD document when it's done. In the past I was using LISP to close the files, but the new method closes the file from C#.

What I started noticing was that there were times when the AutoCAD drawing file was closing down before the drawing was finished. Not a good thing. The new developer told me that his code actually waits until the LISP program is complete before it closes the file. How he is doing this I've not researched yet, but his thinking is that the (setvar 'CMDECHO 0) commands are what is causing this premature shutdown. So to placate the team I set the command for CMDECHO to 1 instead of 0. Well the drawings started finishing but there were some other bugs we fixed at the same time so I cannot be sure this is what fixed it. My limited understanding is that while you can talk to AutoCAD from C#, you can't talk to C# from AutoCAD, especially from LISP. I am not convinced that this setting is what is causing the C# program to wait until the LISP file is finished. The LISP files have no code in them to say "Hey I'm finished!" so is this really what is happening or is it just working as I thought it would from the beginning?

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: cmdecho Question
« Reply #1 on: May 11, 2016, 03:39:29 PM »
LISP by nature concludes with that "Hey, I'm finished" message since LISP functions effectively commandeer the system until finished.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Bill Tillman

  • Guest
Re: cmdecho Question
« Reply #2 on: May 11, 2016, 04:20:22 PM »
Thanks dgorsman,

So by setting the CMDECHO variable to 1 the "Hey, I'm finished" gets announced and by setting CMDECHO to 0 it remains silent. Thus the C# code never gets the word so it just shuts down the drawing file too soon...I'm not sure I get that because if there's never a "Hey, I'm finished" announced, then when would the C# code know to shut things down?

ChrisCarlson

  • Guest
Re: cmdecho Question
« Reply #3 on: May 11, 2016, 04:26:59 PM »
I'm pretty sure CMDECHO does not have an influence in this regard as once the routine is started it takes over AutoCAD.

How are you closing it from C#? I wonder if the C# code is sending the equivalent of a cancel all command?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: cmdecho Question
« Reply #4 on: May 11, 2016, 04:58:47 PM »
Quote
using the SendCommand class...

Depending on the context, SendCommand() method may run synchronously, or not.
Speaking English as a French Frog

Jeff H

  • Needs a day job
  • Posts: 6150
Re: cmdecho Question
« Reply #5 on: May 11, 2016, 05:58:06 PM »
Thanks dgorsman,

So by setting the CMDECHO variable to 1 the "Hey, I'm finished" gets announced and by setting CMDECHO to 0 it remains silent. Thus the C# code never gets the word so it just shuts down the drawing file too soon...I'm not sure I get that because if there's never a "Hey, I'm finished" announced, then when would the C# code know to shut things down?
I thought CMDECHO just determined if prompts and input are printed to command window and had no effect on execution.

Bill Tillman

  • Guest
Re: cmdecho Question
« Reply #6 on: May 12, 2016, 08:53:45 AM »

I thought CMDECHO just determined if prompts and input are printed to command window and had no effect on execution.

That's always been my understanding of it as well. I don't think the C# code or AutoCAD or Windows itself is holding the door open for this process waiting for the LISP code to finish. But my understanding of background stuff is limited so who am I to say. The C# code does a doc.Close() when it gets to the end, (doc is the object created in C#). But again there is no sleep, or anything in between the SendCommands which load the LISP file, assigns the variables and executes the LISP code. The drawings take anywhere from 4 to 10 seconds to complete depending on the complexity of the product they are drawing.

Later this morning I'm going to put a delay in one of the LISP files, about 20 seconds or so and see if the C# code really does wait as this other developer asserts.

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: cmdecho Question
« Reply #7 on: May 12, 2016, 10:15:59 AM »
Forgot about document/application contexts earlier, especially as it applies to LISP.   :oops:

If the LISP code is running AutoCAD should ignore all input on that document.  But an application-level method might be used to force the drawing closed if it doesn't check to see if a LISP function is active in the context of that document.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}