Total Control in Turning Layers On and Off from Several Layouts in Paperspace

Discussion in 'AutoCAD' started by matt_1ca, Mar 29, 2005.

  1. matt_1ca

    matt_1ca Guest

    If you had say a dozen layouts in paperspace, is it possible to turn off a layer in one layout and have it turned on in another?

    I have written a program that creates a number of layouts in paperspace and with different titleblocks on each layout.

    Right now the program works as expected but then when it is time for plotting we realize that for say a titleblock in layout1 we need the layer for the river turned on, but need it turned off in layout2 .. and the list goes on.

    It is easy to see here that with say two dozen layouts with 58 layers to selectively turn on and off it can really become a nightmare without program intervention.

    Please let me know if what I am trying to achieve is possible or not.

    Thank you so much for all the kind help you can give.

    Matt
     
    matt_1ca, Mar 29, 2005
    #1
  2. matt_1ca

    Oberer Guest

    matt, have you checked out layer states?

    "Please let me know if what I am trying to achieve is possible or not."

    have you check out the AcadDocument_LayoutSwitched event?

    btw, you've posted some rather interesting questions.
    Are we ever going to see your work?

    you should be able to tweak this...

    code in ThisDrawing module
    Code:
    
    Option Explicit
    
    Private mstrLastLayoutName As String
    
    '2/07/05
    'Examine current layout name vs saved layout.
    'If name is different, save the layer state
    
    Private Sub AcadDocument_LayoutSwitched(ByVal LayoutName As String)
    Dim sngLayerStatesToSave As Single
    sngLayerStatesToSave = GetSetting("ODS_UTILITIES", "LLM", "LayerStatesToSave", acLsAll)
    'if the layout was switched
    If LayoutName <> mstrLastLayoutName Then
    'and it's not the first time we've switched
    If mstrLastLayoutName <> vbNullString Then 'And mstrLastLayoutName <> "Model" Then
    Call CreateLayerStates(mstrLastLayoutName, sngLayerStatesToSave)
    End If
    Call RestoreLayerState(LayoutName)
    mstrLastLayoutName = LayoutName
    End If
    End Sub
    
    
    module code
    Code:
    Public Sub RestoreLayerState(LayerStateName As String)
    On Error GoTo myError
    Dim oLayerStateManager As AcadLayerStateManager
    Dim strErrorMsg As String
    Set oLayerStateManager = New AcadLayerStateManager
    oLayerStateManager.SetDatabase ThisDrawing.Database
    oLayerStateManager.Restore LayerStateName
    AcadApplication.Update
    Set oLayerStateManager = Nothing
    myEXIT:
    Exit Sub
    myError:
    Select Case Err.Number
    'Attempted to restore an invalid layer state
    Case -2145386476
    strErrorMsg = "Layer State: " & LayerStateName & " not found." & vbNewLine & _
    "Created Layer State: " & LayerStateName
    'MsgBox strErrorMsg, vbOKOnly, "No Layer State Name Found"
    'this shouldn't be done in the error handler, should it?
    ' CREATE LAYER STATE
    Err.Clear
    oLayerStateManager.Save LayerStateName, acLsAll
    Resume
    Case Else
    MsgBox "Error restoring layer state:" & LayerStateName & _
    vbNewLine & Err.Number & Err.Description
    Resume myEXIT
    End Select
    Resume myEXIT
    
    End Sub
    
    
    Public Sub DeleteLayerState(LayerStateName As String)
    On Error GoTo myError
    
    Dim oLayerStateManager As AcadLayerStateManager
    Set oLayerStateManager = New AcadLayerStateManager
    oLayerStateManager.SetDatabase ThisDrawing.Database
    oLayerStateManager.Delete LayerStateName
    
    AcadApplication.Update
    Set oLayerStateManager = Nothing
    myEXIT:
    Exit Sub
    myError:
    MsgBox "Error deleting layer state:" & LayerStateName & _
    vbNewLine & Err.Number & Err.Description
    Resume myEXIT
    
    End Sub
    
    Sub CreateLayerStates(LayerStateName As String, StatesToSave As Single)
    On Error GoTo myError
    Dim oLayerStateManager As AcadLayerStateManager
    Set oLayerStateManager = New AcadLayerStateManager
    oLayerStateManager.SetDatabase ThisDrawing.Database
    'oLayerStateManager.Delete LayerStateName
    oLayerStateManager.Save LayerStateName, StatesToSave
    Set oLayerStateManager = Nothing
    myEXIT:
    Exit Sub
    myError:
    Select Case Err.Number
    ' Layer state already exists.  delete it and resume
    Case -2145386475
    oLayerStateManager.Delete LayerStateName
    Err.Clear
    Resume
    Case Else
    MsgBox "Error Creating layer state:" & LayerStateName & _
    vbNewLine & Err.Number & Err.Description
    End Select
    Resume myEXIT
    End Sub
    
     
    Oberer, Mar 29, 2005
    #2
  3. You can do that in viewports but not layouts.
     
    Frank Oquendo, Mar 29, 2005
    #3
  4. matt_1ca

    Oberer Guest

    Frank wrote:
    "You can do that in viewports but not layouts"

    Why not? I'd be the first to say my code is NOT pretty, but it does in fact restore layer states (of different colors and visibility) based on layouts, not viewports
     
    Oberer, Mar 29, 2005
    #4
  5. Because there's no such thing as "freeze in current layout". I made no
    comment about your proposed solution. I merely pointed out that a
    workaround is indeed the only workaround.
     
    Frank Oquendo, Mar 29, 2005
    #5
  6. matt_1ca

    Matt W Guest

    That's a great quote. "a workaround is indeed the only workaround".

    I love it. :) Thanks, Frank!
     
    Matt W, Mar 29, 2005
    #6
  7. matt_1ca

    Oberer Guest

    Frank wrote:
    "Because there's no such thing as "freeze in current layout". I made no comment about your proposed solution. I merely pointed out that a workaround is indeed the only workaround."

    Thanks for the lesson in semantics :). I assumed that since he's posting here in the vba group, he's not looking for something thru the front end anyway. When he asked 'is it possible" he obviously didn't mention how to accomplish this :)

    "If you had say a dozen layouts in paperspace, is it possible to turn off a layer in one layout and have it turned on in another"

    best of luck matt, it looks like a doozie...
     
    Oberer, Mar 29, 2005
    #7
  8. You're welcome.
    Never a good idea.
    It's always important to point out what functionality is native as
    opposed to what must be coded. It may very well affect their decision.
     
    Frank Oquendo, Mar 29, 2005
    #8
  9. matt_1ca

    matt_1ca Guest

    I want to thank everyone who took the time to answer my question.

    Forever grateful,
    Matt
     
    matt_1ca, Mar 30, 2005
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.