specifying the layout to activate

specifying the layout to activate

Anonymous
Not applicable
5,960 Views
8 Replies
Message 1 of 9

specifying the layout to activate

Anonymous
Not applicable
I'm opening a mechanical desktop file, using VBA, that has several layouts
relating to the model. I need to set the current layout to be the one that I
want to work on, and I want to delete the layouts that I don't need.
I can set the current mode correctly but it defaults to the last layout that
was open when the file was saved.
Does anyone have code to specify the current layout?
0 Likes
5,961 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Phil,

Try setting the variable CTAB to the desired layout name just after it
opens the drawing.

Cheers,
Thilak


"Phil Tumelty" wrote in message
news:[email protected]...
> I'm opening a mechanical desktop file, using VBA, that has several layouts
> relating to the model. I need to set the current layout to be the one that
I
> want to work on, and I want to delete the layouts that I don't need.
> I can set the current mode correctly but it defaults to the last layout
that
> was open when the file was saved.
> Does anyone have code to specify the current layout?
>
>
>
0 Likes
Message 3 of 9

Anonymous
Not applicable
ThisDrawing.ActiveLayout = ThisDrawing.Layouts()

--
"That's no ordinary rabbit."
http://www.acadx.com


"Phil Tumelty" wrote in message
news:[email protected]...
> I'm opening a mechanical desktop file, using VBA, that has several
layouts
> relating to the model. I need to set the current layout to be the
one that I
> want to work on, and I want to delete the layouts that I don't need.
> I can set the current mode correctly but it defaults to the last
layout that
> was open when the file was saved.
> Does anyone have code to specify the current layout?
>
>
>
Message 4 of 9

Anonymous
Not applicable
Thanks for that Frank.

The code that you posted expects an index for the layout. Is there any way
to use the layout name ?

Phil

"Frank Oquendo" wrote in message
news:[email protected]...
> ThisDrawing.ActiveLayout = ThisDrawing.Layouts()
>
> --
> "That's no ordinary rabbit."
> http://www.acadx.com
>
>
> "Phil Tumelty" wrote in message
> news:[email protected]...
> > I'm opening a mechanical desktop file, using VBA, that has several
> layouts
> > relating to the model. I need to set the current layout to be the
> one that I
> > want to work on, and I want to delete the layouts that I don't need.
> > I can set the current mode correctly but it defaults to the last
> layout that
> > was open when the file was saved.
> > Does anyone have code to specify the current layout?
> >
> >
> >
>
>
0 Likes
Message 5 of 9

Anonymous
Not applicable
Yep. Just pass a string containg the layout's name and you'll be set
to go.

--
"That's no ordinary rabbit."
http://www.acadx.com


"Phil Tumelty" wrote in message
news:[email protected]...
> Thanks for that Frank.
>
> The code that you posted expects an index for the layout. Is there
any way
> to use the layout name ?
>
> Phil
0 Likes
Message 6 of 9

arcticad
Advisor
Advisor
Dim Ctab
Ctab = ThisDrawing.GetVariable("CTAB")
ThisDrawing.ActiveLayout = ThisDrawing.Layouts(Ctab)
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 7 of 9

buianhtuan.cdt
Enthusiast
Enthusiast
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 <> "Model" Then
            Thisdrawing.ActiveLayout = EachLayout
        End If
    Next
    
'Set SS
    Dim SS As AcadSelectionSet: Set SS = Thisdrawing.SelectionSets.ADD("SS" & Now)
    Dim FT(3) As Integer: Dim FD(3) As Variant
    FT(0) = -4:     FD(0) = "<OR"
    FT(1) = 0:      FD(1) = "TEXT"
    FT(2) = 0:      FD(2) = "MTEXT"
    FT(3) = -4:     FD(3) = "OR>"
    
'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 & EachContent)
        SS.SelectOnScreen FT, FD
        If SS.Count <> 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

0 Likes
Message 8 of 9

buianhtuan.cdt
Enthusiast
Enthusiast
Sub CreateAfile()
    Dim lk As String
    Dim outem As String
    lk = "D:\"
    lk = lk & "Log_CuttedFromMasterBOM_" & Format(Now, "yymmddhhmmss") & ".txt"
    outem = "2222" & vbNewLine & "333" & vbTab & "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
0 Likes
Message 9 of 9

MakCADD
Advocate
Advocate

Use with a userform, combobox and two command buttons

MakCADD_0-1640242987092.png

 

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 <> 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

 

0 Likes