.NET

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

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

363 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 (339 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 (311 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: 768
Registered: ‎02-25-2013
Message 4 of 6 (303 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

Contributor
classof
Posts: 14
Registered: ‎06-26-2010
Message 5 of 6 (279 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: 768
Registered: ‎02-25-2013
Message 6 of 6 (270 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

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.