.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CloseAndDiscard problem

3 REPLIES 3
Reply
Message 1 of 4
moabiker31
704 Views, 3 Replies

CloseAndDiscard problem

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()
3 REPLIES 3
Message 2 of 4
Anonymous
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()
Message 3 of 4
moabiker31
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.
Message 4 of 4
Anonymous
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost