.NET

Reply
Valued Mentor
Posts: 358
Registered: ‎03-31-2005
Message 1 of 6 (416 Views)
Accepted Solution

Simulate CommandFlags.Session from form button

416 Views, 5 Replies
05-10-2012 02:10 PM

I am working on an application that uses map to query data, then saves the data to a file, and repeat.  It works flawlessly when I use a commandmethod with commandflags.session, But, when I try to run the same code from a form button, I get "drawing is busy".  The command from the form button ignores the commandmethod and the commandflags.  I am guessing that "sendstringtoexecute" would work, but I would prefer to not do it that way.

 

What am I missing?  Is there another way to lock the session? 

 

Here is what I am trying to do.

drawing1 is open and the user presses the button

data is queried and saved as 1.dwg

close and discard drawing1

open a new doc drawing2

data is queried and saved as 2.dwg

close and discard drawing2

open a new doc drawing3

.... 

Moderator
Alexander.Rivilis
Posts: 1,346
Registered: ‎04-09-2008
Message 2 of 6 (412 Views)

Re: Simulate CommandFlags.Session from form button

05-10-2012 02:29 PM in reply to: fieldguy

You can try using DocumentCollection.ExecuteInApplicationContext method.


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Mentor
Posts: 358
Registered: ‎03-31-2005
Message 3 of 6 (397 Views)

Re: Simulate CommandFlags.Session from form button

05-10-2012 03:33 PM in reply to: Alexander.Rivilis

That's even better - thank you.  Starting at an empty drawing1, the user presses the button, and the queries start in drawing2.  When it's finished, the user is back at an empty drawing1.

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 4 of 6 (375 Views)

Re: Simulate CommandFlags.Session from form button

05-11-2012 01:20 AM in reply to: fieldguy

Show your code, please,

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Mentor
Posts: 358
Registered: ‎03-31-2005
Message 5 of 6 (360 Views)

Re: Simulate CommandFlags.Session from form button

05-11-2012 08:16 AM in reply to: Hallex

Good idea - sorry.  It took a bit of digging and I was in a rush.  Thanks again Alexander and tony t (again and again...).

 

 <CommandMethod("q19")> _
    Sub q_19()
        Dim acdocmgr As acapp.DocumentCollection = acapp.Application.DocumentManager
        'assume drawing1 is active - it does not matter
        acdocmgr.ExecuteInApplicationContext(AddressOf testsub, Nothing)
    End Sub

    Private Sub testsub(ByVal data As Object)
        'in this example data is not used
        Dim cmddiavalue As Integer = CInt(acapp.Application.GetSystemVariable("CMDDIA"))
        acapp.Application.SetSystemVariable("CMDDIA", 0)
        Dim acdocmgr As acapp.DocumentCollection = acapp.Application.DocumentManager
        Dim acdoc As acapp.Document = acdocmgr.MdiActiveDocument
        Dim templatepath As String = "map2diso.dwt"
        acdoc = acdocmgr.Add(templatepath)
        acdocmgr.MdiActiveDocument = acdoc
        'drawing2 is now active
        Using acdoclock As acapp.DocumentLock = acdoc.LockDocument
            Dim currentobjs As New ObjectIdCollection()
            'query and save 
        End Using
        acdoc.CloseAndDiscard()
        acdoc = acdocmgr.Add(templatepath)
        acdocmgr.MdiActiveDocument = acdoc
        'drawing3
        Using acdoclock As acapp.DocumentLock = acdoc.LockDocument
            Dim currentobjs As New ObjectIdCollection()
            'query and save 
        End Using
        acdoc.CloseAndDiscard()
        acapp.Application.SetSystemVariable("CMDDIA", cmddiavalue)
        Autodesk.AutoCAD.Internal.Utils.PostCommandPrompt()
        'return to drawing1 or whatever doc was before
    End Sub

 

*Expert Elite*
Hallex
Posts: 1,555
Registered: ‎10-08-2008
Message 6 of 6 (350 Views)

Re: Simulate CommandFlags.Session from form button

05-11-2012 11:27 AM in reply to: fieldguy

Thanks for sharing your code

Regards,

 

Oleg

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community