Total Control in Turning Layers On and Off from Several Lay
CADForums.net Forum Index CADForums.net
Discussion of AutoCAD and other CAD software.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web cadforums.net
Total Control in Turning Layers On and Off from Several Lay

 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA
Author Message
matt_1ca
Guest





Posted: Tue Mar 29, 2005 9:19 pm    Post subject: Total Control in Turning Layers On and Off from Several Lay Reply with quote

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

Back to top
Oberer
Guest





Posted: Tue Mar 29, 2005 10:53 pm    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

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
Back to top
Frank Oquendo
Guest





Posted: Tue Mar 29, 2005 10:56 pm    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

matt_1ca wrote:
Quote:
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?

You can do that in viewports but not layouts.

Back to top
Oberer
Guest





Posted: Wed Mar 30, 2005 12:37 am    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

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
Back to top
Frank Oquendo
Guest





Posted: Wed Mar 30, 2005 12:51 am    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

Oberer wrote:

Quote:
Why not?

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.
Back to top
Matt W
Guest





Posted: Wed Mar 30, 2005 1:01 am    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

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

I love it. :) Thanks, Frank!

--
I support two teams: The Red Sox and whoever beats the Yankees.

"Frank Oquendo" <foquendo@gmail.com> wrote in message
news:4249b1b9$1_3@newsprd01...
Quote:
Oberer wrote:

Why not?

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.
Back to top
Oberer
Guest





Posted: Wed Mar 30, 2005 2:34 am    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

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...
Back to top
Frank Oquendo
Guest





Posted: Wed Mar 30, 2005 2:43 am    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

Oberer wrote:

Quote:
Thanks for the lesson in semantics :).

You're welcome.

Quote:
I assumed

Never a good idea.

Quote:
When he asked 'is it possible" he obviously
didn't mention how to accomplish this :)

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.
Back to top
matt_1ca
Guest





Posted: Wed Mar 30, 2005 3:24 pm    Post subject: Re: Total Control in Turning Layers On and Off from Several Reply with quote

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

Forever grateful,
Matt
Back to top
 
Post new topic   Reply to topic    CADForums.net Forum Index -> VBA All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




Windows Server DSP VoIP Electronics New Topics
Powered by phpBB