Author Topic: Close current drawing.  (Read 2096 times)

0 Members and 1 Guest are viewing this topic.

ProfWolfMan

  • Guest
Close current drawing.
« on: July 09, 2012, 04:03:25 AM »
Hi all,

I am trying to close current drawing without save and open existing drawing.
I arrived below code.
Code: [Select]
Public Shared Sub OpenDrawing(ByVal strFileName As String)
            Dim acDocMgr As DocumentCollection = Application.DocumentManager
            Dim doc As Document = acDocMgr.MdiActiveDocument
            Try
                If (File.Exists(strFileName)) Then
                    doc.CloseAndDiscard()
                    Dim acdoc As Document = acDocMgr.Open(strFileName, False)
                    acDocMgr.MdiActiveDocument = acdoc
                Else
                    Throw New Exception("File " & strFileName & " does not exist.")
                End If
            Catch ex As Exception
                Throw New Exception("Error occured when open drawing " & strFileName, ex)
            End Try
        End Sub

But when i calling from <CommandMethod(.... , i got "Com exception error : Drawing is busy."
So, i tried to open existing drawing and make it current. But after making it current i lost my control over that drawing because my command running on first drawing.

How do i solve this?   :cry:
Any help / hint greatly appreciated.

Thanks for reading.


gile

  • Gator
  • Posts: 2520
  • Marseille, France
Re: Close current drawing.
« Reply #1 on: July 09, 2012, 04:25:32 AM »
Hi, did you try using CommandFlags.Session ?
Speaking English as a French Frog

ProfWolfMan

  • Guest
Re: Close current drawing.
« Reply #2 on: July 09, 2012, 05:13:57 AM »
Hi gile,

Even i am using 'Imports Autodesk.AutoCAD.Runtime', I can not use commandflags enum.
I got 'Type is not defined' error.

how do i?

thanks.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Close current drawing.
« Reply #3 on: July 09, 2012, 08:56:42 AM »
See this thread:

http://www.theswamp.org/index.php?topic=39669.0

Your function needs to run at session, otherwise the code is available only at document level. Meaning that the document cannot close because the code that is attempting to close the document is running inside that document.

You must use commandflags.session

See this page for a decent explanation of commandflags.session
http://spiderinnet1.typepad.com/blog/2011/12/autocad-net-commandflag-session.html
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ProfWolfMan

  • Guest
Re: Close current drawing.
« Reply #4 on: July 09, 2012, 08:17:03 PM »
Hi keith & gile!

Thanks for your useful information.
Now i know what is commandflags and where i need to use. :-)