.NET

Reply
Active Member
moabiker31
Posts: 10
Registered: ‎03-08-2006
Message 1 of 4 (523 Views)

CloseAndDiscard problem

523 Views, 3 Replies
09-22-2006 11:59 AM
VB.net 2005 exe and AutoCAD 2006

I need to open a drawing, run a lisp script, and close AutoCAD without saving the drawing. The lisp script runs anywhere from 30 seconds to several hours.

The problem I'm having is that AutoCAD is not closing after the script has completed. If I remove the call to start the script, AutoCAD exits, but not after running the script. Must be a timing issue. Can someone help me? Here's the code I'm using:

Application.DocumentManager.Open("C:\myDrawing.dwg")
Application.SetSystemVariable("filedia", 0)
acedPostCommand("(load ""\\script"") ")
Application.SetSystemVariable("filedia", 0)

Application.DocumentManager.MdiActiveDocument.CloseAndDiscard()
Application.Quit()
*Tony Tanzillo
Message 2 of 4 (523 Views)

Re: CloseAndDiscard problem

09-22-2006 06:41 PM in reply to: moabiker31
What you are trying to do is generally considered
unsound. Are you expecting your code to pause
and wait for the script to complete?

The call to acedPostCommand() passes the
input to the command line, and returns before
AutoCAD executes the command input. Hence
your code continues to run asynchronously, it
does not stop and wait for the script to finish.

One obvious problem you have is that opening
and closing documents are things that cannot be
done from the document execution context.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5338535@discussion.autodesk.com...
VB.net 2005 exe and AutoCAD 2006

I need to open a drawing, run a lisp script, and close AutoCAD without saving the drawing. The lisp script runs anywhere from 30 seconds to several hours.

The problem I'm having is that AutoCAD is not closing after the script has completed. If I remove the call to start the script, AutoCAD exits, but not after running the script. Must be a timing issue. Can someone help me? Here's the code I'm using:

Application.DocumentManager.Open("C:\myDrawing.dwg")
Application.SetSystemVariable("filedia", 0)
acedPostCommand("(load ""\\script"") ")
Application.SetSystemVariable("filedia", 0)

Application.DocumentManager.MdiActiveDocument.CloseAndDiscard()
Application.Quit()
Active Member
moabiker31
Posts: 10
Registered: ‎03-08-2006
Message 3 of 4 (523 Views)

Re: CloseAndDiscard problem

09-25-2006 07:11 AM in reply to: moabiker31
Thanks for the reply Tony. Yeah I was hoping the code would wait for the script to complete. I searched this forum for book recommendations but they stated there aren't any regarding AutoCAD and the .net api, preferably vb.net. Is that still the case or has there been a book published?

I originally tried using SendStringToExecute but the strings wouldn't execute until I clicked into AutoCAD and started moving the mouse around. Searched for that problem within this forum and it suggested to use acedPostCommand. That's how I got to where I am.

What steps do I need to take to get it to behave the way I want? I don't expect the code to be handed to me, but some tips to nudge me along would be appreciated. Thanks.
*Tony Tanzillo
Message 4 of 4 (523 Views)

Re: CloseAndDiscard problem

09-25-2006 06:20 PM in reply to: moabiker31
The easiest way to start AutoCAD and run a script,
is to do it from an outside process.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5339778@discussion.autodesk.com...
Thanks for the reply Tony. Yeah I was hoping the code would wait for the script to complete. I searched this forum for book recommendations but they stated there aren't any regarding AutoCAD and the .net api, preferably vb.net. Is that still the case or has there been a book published?

I originally tried using SendStringToExecute but the strings wouldn't execute until I clicked into AutoCAD and started moving the mouse around. Searched for that problem within this forum and it suggested to use acedPostCommand. That's how I got to where I am.

What steps do I need to take to get it to behave the way I want? I don't expect the code to be handed to me, but some tips to nudge me along would be appreciated. Thanks.
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 or visit the Installation and Licensing Forum to get help installing your software.