Results 1 to 5 of 5

Thread: Creating a new layout and setting it current

  1. #1
    Member
    Join Date
    2003-06
    Posts
    13
    Login to Give a bone
    0

    Default Creating a new layout and setting it current

    I have a section of code that creates a new layout and sets if current. It works in 2014 AutoCAD but I cannot get it to work in 2016 AutoCAD. I combed through this several times and cannot figure out why it keeps erring out. It catches the error at the line "LayoutManager.Current.CurrentLayout = acLayout2.LayoutName"

    Any help would be greatly appreciated.

    Code:
        Public Sub CreateLayout(ByVal db As Database, ByVal ed As Editor, ByVal doc As Document, ByVal LayName As String, ByVal myPSxrefs As ArrayList)
    
            Using tr As Transaction = db.TransactionManager.StartTransaction()
    
                Try
    
                    Using layouts As DBDictionary = DirectCast(tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite), DBDictionary)
                        ' Add a number at the end of layout name if already exists 
                        Dim i As Integer = 0
                        Dim OriginalName As String = LayName
                        Dim x As Double = 25.4 * CDbl(TB_X.Text)
                        Dim y As Double = 25.4 * CDbl(TB_Y.Text)
                        Dim myPlotOrigin As Point2d = New Point2d(y, x)
                        ' Create and activate the new layout  
                        Using myLockDoc As DocumentLock = doc.LockDocument()
    
                            Dim acLayoutMgr As LayoutManager = LayoutManager.Current
    
                            Dim layoutId As ObjectId = acLayoutMgr.CreateLayout(LayName)
    
                            Dim acLayout2 As Layout = tr.GetObject(layoutId,
                                                       OpenMode.ForRead)
    
    
    
                            If acLayout2.TabSelected = False Then
                                LayoutManager.Current.CurrentLayout = acLayout2.LayoutName
                            End If
    
                            'Plot Settings                
                            '' Get the PlotInfo from the layout                
                            Using acLayout As Layout = DirectCast(tr.GetObject(layoutId, OpenMode.ForWrite), Layout)
                                Dim acPlInfo As PlotInfo = New PlotInfo()
                                acPlInfo.Layout = acLayout.ObjectId
                                '' Get a copy of the PlotSettings from the layout                
                                Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
                                acPlSet.CopyFrom(acLayout)
                                '' Update some properties of the PlotSettings object                
                                Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
                                Dim myCTB As String = "LBI-Full.ctb"
                                Dim device As String = "Bluebeam PDF"
                                acPlSetVdr.SetCurrentStyleSheet(acPlSet, myCTB)
                                acPlSetVdr.SetPlotConfigurationName(acPlSet, device, myMediaCanonical)
                                If CB_SheetRotation.Text = "LANDSCAPE" Then
                                    acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees090)
                                End If
                                If CB_SheetRotation.Text = "PORTRAIT" Then
                                    acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000)
                                End If
                                If CB_SheetRotation.Text = "LANDSCAPE(Upside Down)" Then
                                    acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees180)
                                End If
                                If CB_SheetRotation.Text = "PORTRAIT(Upside Down)" Then
                                    acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees270)
                                End If
    
                                acPlSetVdr.SetPlotType(acPlSet, DatabaseServices.PlotType.Layout)
                                acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, True)
                                acPlSetVdr.SetPlotOrigin(acPlSet, myPlotOrigin)
                                acPlSetVdr.SetUseStandardScale(acPlSet, True)
                                If myPSxrefs.Count > 0 Then
                                    attachXrefsTypes(myPSxrefs, "TTBL")
                                End If
    
                                ed.Regen()
    
                                '' Update the layout   
    
                                acLayout.CopyFrom(acPlSet)
                            End Using
    
                        End Using
                        tr.Commit()
                    End Using
    
                Catch ex As System.Exception
                    Dim Msg As String = "Error in function Create Layout"
                    Dim Title As String = "Operation cancelled"
                    MessageBox.Show(Msg, Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
                    MsgBox(ex.Message & Err.Number)
    
                    tr.Abort()
                End Try
    
    
            End Using
    
    
        End Sub
    Last edited by BlackBox; 2016-03-07 at 03:01 PM. Reason: Fixed a [CODE] tag, and moved to .NET forum

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Creating a new layout and setting it current

    What does the Exception say?

    Try:
    Code:
    '' <snip>
          acLayoutMgr.CurrentLayout = acLayout2.LayoutName
    '' <snip>

    Also, for reference:

    Creating an AutoCAD layout with custom plot and viewport settings using .NET



    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

  3. #3
    Member
    Join Date
    2003-06
    Posts
    13
    Login to Give a bone
    0

    Default Re: Creating a new layout and setting it current

    Thanks, but it didn't work. I guess I forgot to mention the error I am getting which is error #5, esetfailed. Best I can tell by searching what this error is, is that I am trying to set a layout current that doesn't exist.

  4. #4
    Member
    Join Date
    2003-06
    Posts
    13
    Login to Give a bone
    0

    Default Re: Creating a new layout and setting it current

    Playing around with the order of the code and it seems if I create the layer and set it current before the "USING" call, it works again.

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Creating a new layout and setting it current

    Glad you got it sorted.

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000

Similar Threads

  1. Blocks in current layout
    By timlane in forum VBA/COM Interop
    Replies: 3
    Last Post: 2009-03-26, 07:37 PM
  2. Setting a drawing current.
    By kdayman in forum VBA/COM Interop
    Replies: 6
    Last Post: 2008-08-28, 09:18 PM
  3. REFEDIT to follow current SaveAs Setting
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2005-12-05, 02:55 PM
  4. Setting the Current Plot Configuration Programatically
    By Marshal_Rosenberg60828 in forum VBA/COM Interop
    Replies: 2
    Last Post: 2004-06-18, 03:56 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •