<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: specifying the layout to activate in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10839337#M81650</link>
    <description>&lt;P&gt;Use with a userform, combobox and two command buttons&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MakCADD_0-1640242987092.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1004325i1CDD3888B1041B92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MakCADD_0-1640242987092.png" alt="MakCADD_0-1640242987092.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Sub CommandButton1_Click()
'set currnet layer
ThisDrawing.ActiveLayout = ThisDrawing.Layouts(ComboBox1.Value)
'you can access other layouts using
    For C = 0 To ComboBox1.ListCount - 1
    If C &amp;lt;&amp;gt; ComboBox1.ListIndex Then ThisDrawing.Layouts(ComboBox1.List(C)).Delete
    Next C
Call update_CMBBox
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim L As Integer

UserForm1.Caption = "Set Current Layout"
CommandButton1.Caption = "OK"
CommandButton2.Caption = "CANCEL"
 
'Adding the layout names to list except Model
Call update_CMBBox
End Sub
Sub update_CMBBox()
ComboBox1.Clear
Dim Lay As AcadLayout
For i = 1 To ThisDrawing.Layouts.Count - 1
    For Each Lay In ThisDrawing.Layouts
        If Lay.TabOrder = i Then
        ComboBox1.AddItem Lay.Name
        End If
    Next
Next
ComboBox1.Value = ThisDrawing.ActiveLayout.Name
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Dec 2021 07:04:53 GMT</pubDate>
    <dc:creator>MakCADD</dc:creator>
    <dc:date>2021-12-23T07:04:53Z</dc:date>
    <item>
      <title>specifying the layout to activate</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343228#M81642</link>
      <description>I'm opening a mechanical desktop file, using VBA, that has several layouts&lt;BR /&gt;
relating to the model. I need to set the current layout to be the one that I&lt;BR /&gt;
want to work on, and I want to delete the layouts that I don't need.&lt;BR /&gt;
I can set the current mode correctly but it defaults to the last layout that&lt;BR /&gt;
was open when the file was saved.&lt;BR /&gt;
Does anyone have code to specify the current layout?</description>
      <pubDate>Sat, 25 Aug 2001 06:37:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343228#M81642</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-08-25T06:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: specifying the layout to activate</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343229#M81643</link>
      <description>Phil,&lt;BR /&gt;
&lt;BR /&gt;
Try setting  the variable CTAB to the desired layout name just after it&lt;BR /&gt;
opens the drawing.&lt;BR /&gt;
&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Thilak&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Phil Tumelty" &lt;PHIL.TUMELTY&gt; wrote in message&lt;BR /&gt;
news:CEB43EE4C79450ADB96F944A6F5E2CC4@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I'm opening a mechanical desktop file, using VBA, that has several layouts&lt;BR /&gt;
&amp;gt; relating to the model. I need to set the current layout to be the one that&lt;BR /&gt;
I&lt;BR /&gt;
&amp;gt; want to work on, and I want to delete the layouts that I don't need.&lt;BR /&gt;
&amp;gt; I can set the current mode correctly but it defaults to the last layout&lt;BR /&gt;
that&lt;BR /&gt;
&amp;gt; was open when the file was saved.&lt;BR /&gt;
&amp;gt; Does anyone have code to specify the current layout?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/PHIL.TUMELTY&gt;</description>
      <pubDate>Mon, 27 Aug 2001 01:29:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343229#M81643</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-08-27T01:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: specifying the layout to activate</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343230#M81644</link>
      <description>ThisDrawing.ActiveLayout = ThisDrawing.Layouts(&lt;LAYOUT&gt;)&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
"That's no ordinary rabbit."&lt;BR /&gt;
http://www.acadx.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Phil Tumelty" &lt;PHIL.TUMELTY&gt; wrote in message&lt;BR /&gt;
news:CEB43EE4C79450ADB96F944A6F5E2CC4@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; I'm opening a mechanical desktop file, using VBA, that has several&lt;BR /&gt;
layouts&lt;BR /&gt;
&amp;gt; relating to the model. I need to set the current layout to be the&lt;BR /&gt;
one that I&lt;BR /&gt;
&amp;gt; want to work on, and I want to delete the layouts that I don't need.&lt;BR /&gt;
&amp;gt; I can set the current mode correctly but it defaults to the last&lt;BR /&gt;
layout that&lt;BR /&gt;
&amp;gt; was open when the file was saved.&lt;BR /&gt;
&amp;gt; Does anyone have code to specify the current layout?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/PHIL.TUMELTY&gt;&lt;/LAYOUT&gt;</description>
      <pubDate>Tue, 28 Aug 2001 21:13:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343230#M81644</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-08-28T21:13:58Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343231#M81645</link>
      <description>Thanks for that Frank.&lt;BR /&gt;
&lt;BR /&gt;
The code that you posted expects an index for the layout. Is there any way&lt;BR /&gt;
to use the layout name ?&lt;BR /&gt;
&lt;BR /&gt;
Phil&lt;BR /&gt;
&lt;BR /&gt;
"Frank Oquendo" &lt;FRANKO&gt; wrote in message&lt;BR /&gt;
news:D508018BAEEECFB1E93083153F0EC67A@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; ThisDrawing.ActiveLayout = ThisDrawing.Layouts(&lt;LAYOUT&gt;)&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; --&lt;BR /&gt;
&amp;gt; "That's no ordinary rabbit."&lt;BR /&gt;
&amp;gt; http://www.acadx.com&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; "Phil Tumelty" &lt;PHIL.TUMELTY&gt; wrote in message&lt;BR /&gt;
&amp;gt; news:CEB43EE4C79450ADB96F944A6F5E2CC4@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; &amp;gt; I'm opening a mechanical desktop file, using VBA, that has several&lt;BR /&gt;
&amp;gt; layouts&lt;BR /&gt;
&amp;gt; &amp;gt; relating to the model. I need to set the current layout to be the&lt;BR /&gt;
&amp;gt; one that I&lt;BR /&gt;
&amp;gt; &amp;gt; want to work on, and I want to delete the layouts that I don't need.&lt;BR /&gt;
&amp;gt; &amp;gt; I can set the current mode correctly but it defaults to the last&lt;BR /&gt;
&amp;gt; layout that&lt;BR /&gt;
&amp;gt; &amp;gt; was open when the file was saved.&lt;BR /&gt;
&amp;gt; &amp;gt; Does anyone have code to specify the current layout?&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt; &amp;gt;&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt;&lt;/PHIL.TUMELTY&gt;&lt;/LAYOUT&gt;&lt;/FRANKO&gt;</description>
      <pubDate>Wed, 29 Aug 2001 08:27:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343231#M81645</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-08-29T08:27:58Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343232#M81646</link>
      <description>Yep. Just pass a string containg the layout's name and you'll be set&lt;BR /&gt;
to go.&lt;BR /&gt;
&lt;BR /&gt;
--&lt;BR /&gt;
"That's no ordinary rabbit."&lt;BR /&gt;
http://www.acadx.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"Phil Tumelty" &lt;PHIL.TUMELTY&gt; wrote in message&lt;BR /&gt;
news:6AB143EE62D8A75AED4D964D72C86F9D@in.WebX.maYIadrTaRb...&lt;BR /&gt;
&amp;gt; Thanks for that Frank.&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; The code that you posted expects an index for the layout. Is there&lt;BR /&gt;
any way&lt;BR /&gt;
&amp;gt; to use the layout name ?&lt;BR /&gt;
&amp;gt;&lt;BR /&gt;
&amp;gt; Phil&lt;/PHIL.TUMELTY&gt;</description>
      <pubDate>Wed, 29 Aug 2001 09:46:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343232#M81646</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2001-08-29T09:46:08Z</dc:date>
    </item>
    <item>
      <title>Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343233#M81647</link>
      <description>Dim Ctab&lt;BR /&gt;
Ctab = ThisDrawing.GetVariable("CTAB")&lt;BR /&gt;
ThisDrawing.ActiveLayout = ThisDrawing.Layouts(Ctab)</description>
      <pubDate>Tue, 13 Sep 2005 18:29:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/343233#M81647</guid>
      <dc:creator>arcticad</dc:creator>
      <dc:date>2005-09-13T18:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10833658#M81648</link>
      <description>&lt;LI-CODE lang="general"&gt;Sub TB0106CreatNewFromRefDrawing()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    
'Setting
    Dim ColumnNo As Integer: ColumnNo = 1
    

'Set WS
    Dim WS As Worksheet
    Set WS = Sheets("16.GetText")
    Dim EndRow As Integer
    EndRow = WS.Cells(Rows.Count, ColumnNo).End(xlUp).Row

'Creat TextArr
    Dim RNo As Integer
    Dim CNo As Integer
    Dim TextArr() As String
    ReDim TextArr(1 To EndRow, ColumnNo To ColumnNo + 2)
    Dim EachContent As String
    Dim EachType As String
    For RNo = 1 To EndRow
        EachContent = WS.Cells(RNo, ColumnNo)
        EachType = WS.Cells(RNo, ColumnNo + 1)
        TextArr(RNo, ColumnNo) = EachContent
        TextArr(RNo, ColumnNo + 1) = EachType
    Next

    
'Startup BricsCad
    Dim Thisdrawing As AcadDocument
    Set Thisdrawing = KhoidongAutoCad()

'Active Layout
    Dim EachLayout As AcadLayout
    Dim EachLayoutName As String
    For Each EachLayout In Thisdrawing.Layouts
        EachLayoutName = EachLayout.Name
        If EachLayoutName &amp;lt;&amp;gt; "Model" Then
            Thisdrawing.ActiveLayout = EachLayout
        End If
    Next
    
'Set SS
    Dim SS As AcadSelectionSet: Set SS = Thisdrawing.SelectionSets.ADD("SS" &amp;amp; Now)
    Dim FT(3) As Integer: Dim FD(3) As Variant
    FT(0) = -4:     FD(0) = "&amp;lt;OR"
    FT(1) = 0:      FD(1) = "TEXT"
    FT(2) = 0:      FD(2) = "MTEXT"
    FT(3) = -4:     FD(3) = "OR&amp;gt;"
    
'Process
    Dim EachEntity As AcadEntity
    Dim EachMText As AcadMText
    Dim EachText As AcadText
    Dim EachString As String
    For RNo = LBound(TextArr) To UBound(TextArr)
        EachContent = TextArr(RNo, ColumnNo)
        If EachContent = "" Then GoTo Skip
        Thisdrawing.Utility.Prompt (vbCrLf &amp;amp; EachContent)
        SS.SelectOnScreen FT, FD
        If SS.Count &amp;lt;&amp;gt; 1 Then
            SS.Clear
            GoTo Skip
        End If
        For Each EachEntity In SS
            Select Case EachEntity.ObjectName
                Case "AcDbMText"
                    Set EachMText = EachEntity
                    EachString = EachMText.TextString
                Case "AcDbText"
                    Set EachText = EachEntity
                    EachString = EachText.TextString
            End Select
        Next
        TextArr(RNo, ColumnNo + 2) = EachString
        SS.Clear
Skip:
    Next
    
'Write to Excel
    For RNo = LBound(TextArr) To UBound(TextArr)
        EachString = TextArr(RNo, ColumnNo + 2)
        WS.Cells(RNo, ColumnNo + 2) = EachString
    Next
    
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    
End Sub

&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Dec 2021 13:53:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10833658#M81648</guid>
      <dc:creator>buianhtuan.cdt</dc:creator>
      <dc:date>2021-12-20T13:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Re:</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10834622#M81649</link>
      <description>&lt;LI-CODE lang="general"&gt;Sub CreateAfile()
    Dim lk As String
    Dim outem As String
    lk = "D:\"
    lk = lk &amp;amp; "Log_CuttedFromMasterBOM_" &amp;amp; Format(Now, "yymmddhhmmss") &amp;amp; ".txt"
    outem = "2222" &amp;amp; vbNewLine &amp;amp; "333" &amp;amp; vbTab &amp;amp; "4444"
    Dim fso As Object, MyFile  As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Set MyFile = fso.CreateTextFile(lk, True, True)
    MyFile.Write outem
    MyFile.Open
'    MyFile.Close
    Set fso = Nothing
End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Dec 2021 22:21:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10834622#M81649</guid>
      <dc:creator>buianhtuan.cdt</dc:creator>
      <dc:date>2021-12-20T22:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: specifying the layout to activate</title>
      <link>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10839337#M81650</link>
      <description>&lt;P&gt;Use with a userform, combobox and two command buttons&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MakCADD_0-1640242987092.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1004325i1CDD3888B1041B92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MakCADD_0-1640242987092.png" alt="MakCADD_0-1640242987092.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Sub CommandButton1_Click()
'set currnet layer
ThisDrawing.ActiveLayout = ThisDrawing.Layouts(ComboBox1.Value)
'you can access other layouts using
    For C = 0 To ComboBox1.ListCount - 1
    If C &amp;lt;&amp;gt; ComboBox1.ListIndex Then ThisDrawing.Layouts(ComboBox1.List(C)).Delete
    Next C
Call update_CMBBox
End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub

Private Sub UserForm_Initialize()
Dim L As Integer

UserForm1.Caption = "Set Current Layout"
CommandButton1.Caption = "OK"
CommandButton2.Caption = "CANCEL"
 
'Adding the layout names to list except Model
Call update_CMBBox
End Sub
Sub update_CMBBox()
ComboBox1.Clear
Dim Lay As AcadLayout
For i = 1 To ThisDrawing.Layouts.Count - 1
    For Each Lay In ThisDrawing.Layouts
        If Lay.TabOrder = i Then
        ComboBox1.AddItem Lay.Name
        End If
    Next
Next
ComboBox1.Value = ThisDrawing.ActiveLayout.Name
End Sub&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Dec 2021 07:04:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/specifying-the-layout-to-activate/m-p/10839337#M81650</guid>
      <dc:creator>MakCADD</dc:creator>
      <dc:date>2021-12-23T07:04:53Z</dc:date>
    </item>
  </channel>
</rss>

