.NET

Reply
Contributor
classof
Posts: 14
Registered: ‎06-26-2010
Message 1 of 6 (391 Views)
Accepted Solution

How to change all the DOCUMENTS of the TileMode to 0.

391 Views, 5 Replies
05-16-2013 08:35 PM

Hello
I would like to change all the DOCUMENTS of the TileMode to 0.
But, the following code the ActiveDocument changes only.
How can I modify the code?

 

Dim acdc As DocumentCollection = Application.DocumentManager
        Dim acdoc As Document = acdc.MdiActiveDocument
        Dim acTile As Integer = Application.GetSystemVariable("TileMode")

        For Each acdoc In acdc

            If acTile = 1 Then
                Application.SetSystemVariable("TILEMODE", 0)
            End If

        Next

    End Sub

 

Take a look at the article

 'See article here:
'http://adndevblog.typepad.com/autocad/2012/05/when-to-lock-the-document.html?cid=6a0167607c2431970b0177443a993b970d
<CommandMethod("stile")> _
Public Sub switchTileMode()
Try
For Each doc As Document In Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
If doc <> Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Then
' switch the active document
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = doc
' If you do not lock the document
' then the below code just simply has no effect
' whereas "doc.Database.TileMode =
' !doc.Database.TileMode;"
' would even crash AutoCAD
' If you lock the document then both should work fine
Using doc.LockDocument()
Dim tm As Short = CShort(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("TILEMODE"))
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", (tm + 1) Mod 2)
End Using
Exit For
End If
Next
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(("Exception: " + ex.Message))
Finally
' Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CloseAll() 'to your needs
End Try
End Sub

 

 

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

Re: How to change all the DOCUMENTS of the TileMode to 0.

05-18-2013 04:39 AM in reply to: classof

Take a look at the article

        'See article here:
        'http://adndevblog.typepad.com/autocad/2012/05/when-to-lock-the-document.html?cid=6a0167607c2431970b0...
        <CommandMethod("stile")> _
        Public Sub switchTileMode()

            Try
                For Each doc As Document In Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager

                    If doc <> Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument Then

                        ' switch the active document 

                        Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = doc

                        ' If you do not lock the document 

                        ' then the below code just simply has no effect 

                        ' whereas "doc.Database.TileMode = 

                        ' !doc.Database.TileMode;"  

                        ' would even crash AutoCAD       

                        ' If you lock the document then both should  work fine 

                        Using doc.LockDocument()

                            Dim tm As Short = CShort(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("TILEMODE"))

                            Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("TILEMODE", (tm + 1) Mod 2)

                        End Using

                        Exit For

                    End If
                Next

            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(("Exception: " + ex.Message))
            Finally
                ' Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.CloseAll() 'to your needs

            End Try
        End Sub

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
classof
Posts: 14
Registered: ‎06-26-2010
Message 3 of 6 (339 Views)

Re: How to change all the DOCUMENTS of the TileMode to 0.

06-05-2013 04:11 AM in reply to: Hallex

Hallex

Thank you for your reply.

So, I made the following code.. but, Tilemod of all document does not change the value to 0.

Please help me.. 

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.ApplicationServices

Public Class fsfaf

    <CommandMethod("ss")> _
    Public Sub ypf()

        Dim acdc As DocumentCollection = Application.DocumentManager

        For Each acdoc As Document In acdc

            If acdoc <> acdc.MdiActiveDocument Then
                acdc.MdiActiveDocument = acdoc
            End If

            Using acdoc.LockDocument()
                Dim acTile As Short = Application.GetSystemVariable("TileMode")
                If acTile = 1 Then
                    Application.SetSystemVariable("TILEMODE", 0)
                End If
            End Using
        Next
    End Sub
End Class

 

 

Distinguished Mentor
BlackBox_
Posts: 785
Registered: ‎02-25-2013
Message 4 of 6 (331 Views)

Re: How to change all the DOCUMENTS of the TileMode to 0.

06-05-2013 07:25 AM in reply to: Hallex

Hallex wrote:

Take a look at the article

        'See article here:
        'http://adndevblog.typepad.com/autocad/2012/05/when-to-lock-the-document.html?cid=6a0167607c2431970b0...
        <CommandMethod("stile")> _
        Public Sub switchTileMode()
            '' <snip>
        End Sub

 

 




Hallex,

 

Doesn't the article say that CommandFlags.Session is needed?

 

Example code snippet from the article you linked above:

 

// <snip>
[CommandMethod("MyTest", CommandFlags.Session)] public void MyTestNet() { // <snip> }

 

Cheers



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security


AutoCAD® 2014, and Civil 3D® 2014 Certified Professional ~ Autodesk® Authorized Developer

Contributor
classof
Posts: 14
Registered: ‎06-26-2010
Message 5 of 6 (307 Views)

Re: How to change all the DOCUMENTS of the TileMode to 0.

06-05-2013 06:42 PM in reply to: classof

I have solved this problem. :smileyhappy:

I have added the CommandFlags.Session.

thank you~

Distinguished Mentor
BlackBox_
Posts: 785
Registered: ‎02-25-2013
Message 6 of 6 (298 Views)

Re: How to change all the DOCUMENTS of the TileMode to 0.

06-05-2013 09:37 PM in reply to: classof

classof wrote:

I have solved this problem. :smileyhappy:

I have added the CommandFlags.Session.

thank you~


If only someone had suggested that before... Regardless, glad you got it sorted.

 

Cheers



"Potential has a shelf life." - Margaret Atwood


Autodesk Exchange Apps ~ Autoloader ~ AutoCAD Security


AutoCAD® 2014, and Civil 3D® 2014 Certified Professional ~ Autodesk® Authorized Developer

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!