Author Topic: How do you delete a LayerState?  (Read 2959 times)

0 Members and 1 Guest are viewing this topic.

Matersammichman

  • Guest
How do you delete a LayerState?
« on: September 07, 2006, 12:08:44 PM »
I have a named LayerState (Temp).
How can I make vba delete this?

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: How do you delete a LayerState?
« Reply #1 on: September 07, 2006, 12:33:29 PM »
i dont think you can.  From what I remember, LayerStates are not exposed to VBA
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

DaveW

  • Guest
Re: How do you delete a LayerState?
« Reply #2 on: September 07, 2006, 12:38:40 PM »
You can automate it via the command line.

You can bring up the layer manager, then sendkeys, the letter "r" will open the state manager.
Once inside tere you can access the commands with alt and sndkeys, as the letters are underlined.

Should work.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: How do you delete a LayerState?
« Reply #3 on: September 07, 2006, 12:40:02 PM »
Here is how I got a list of them in lisp (ActiveX) which I think you can make into VBA pretty easliy
Code: [Select]
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(setq LayCol (vla-get-Layers ActDoc))
(setq LayDict (vla-GetExtensionDictionary LayCol))
(setq LayStDict (vl-catch-all-apply 'vla-Item (list LayDict "ACAD_LAYERSTATES")))
If 'LayStDict' isn't an error, then you have layer states in the current drawing.  Hope that helps.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

DaveW

  • Guest
Re: How do you delete a LayerState?
« Reply #4 on: September 07, 2006, 12:46:10 PM »
Quick stab at the command line one:

Code: [Select]
Public Sub DeleteLaterStateTemp()

        ThisDrawing.SendCommand "-layer" & vbCr
        ThisDrawing.SendCommand "a" & vbCr
        ThisDrawing.SendCommand "d" & vbCr
        ThisDrawing.SendCommand "temp" & vbCr & vbCr & vbCr
        
End Sub

SomeCallMeDave

  • Guest
Re: How do you delete a LayerState?
« Reply #5 on: September 07, 2006, 10:25:00 PM »
This seems to work in v2004.  Maybe it will help

Code: [Select]

Public Sub DelLayerState()
    Dim colLayers As AcadLayers
    Dim objDict As AcadDictionary
    Dim objLayerStates As AcadDictionary
    Dim objXrec As AcadXRecord
   
    Set colLayers = Me.Layers
    If colLayers.HasExtensionDictionary Then
       Set objDict = colLayers.GetExtensionDictionary
       Set objLayerStates = objDict("Acad_LayerStates")
       objLayerStates("temp").Delete
   End If

End Sub



Needs more error checking and hasn't been fully tested
« Last Edit: September 07, 2006, 10:27:29 PM by SomeCallMeDave »

DaveW

  • Guest
Re: How do you delete a LayerState?
« Reply #6 on: September 07, 2006, 11:03:23 PM »
Nice!

Matersammichman

  • Guest
Re: How do you delete a LayerState?
« Reply #7 on: September 08, 2006, 08:50:39 AM »
Dave,
Thanks for the help, but... Vba choked on "Me.Layers"

ideas?

SomeCallMeDave

  • Guest
Re: How do you delete a LayerState?
« Reply #8 on: September 08, 2006, 09:01:21 AM »
Try 
 
Code: [Select]
ThisDrawing.Layers

Matersammichman

  • Guest
Re: How do you delete a LayerState?
« Reply #9 on: September 11, 2006, 04:17:33 PM »
Worked beautifully!
Thanks!

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: How do you delete a LayerState?
« Reply #10 on: September 11, 2006, 04:40:13 PM »
Learn something everyday!!!
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: How do you delete a LayerState?
« Reply #11 on: September 11, 2006, 04:40:55 PM »
So my question is can you create a layerstate through code?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: How do you delete a LayerState?
« Reply #12 on: September 11, 2006, 04:52:10 PM »
Look into the LayerStateManager object.......saves from having to mess with Dictionaries, it does all the work for you.

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: How do you delete a LayerState?
« Reply #13 on: September 11, 2006, 05:07:37 PM »
I cant get the delete part to work in 07
Code: [Select]
Public Sub DelLayerState()
    Dim colLayers As AcadLayers
    Dim objDict As AcadDictionary
    Dim objLayerStates As AcadDictionary
    Dim objXrec As AcadXRecord
   
    Set colLayers = ThisDrawing.Layers
    If colLayers.HasExtensionDictionary Then
       Set objDict = colLayers.GetExtensionDictionary
       Set objLayerStates = objDict("ACAD_LAYERFILTERS")
       objLayerStates("adf").Delete
   End If

End Sub
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: How do you delete a LayerState?
« Reply #14 on: September 11, 2006, 05:08:12 PM »
How do I find that?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

T.Willey

  • Needs a day job
  • Posts: 5218
Re: How do you delete a LayerState?
« Reply #15 on: September 11, 2006, 05:21:46 PM »
How do I find that?
In the help, developers guide, VBA ActiveX reference, objects, LayerStateManager
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 3946
  • C3D user & customizer
Re: How do you delete a LayerState?
« Reply #16 on: September 11, 2006, 05:24:18 PM »
Here's a quick example for 2007:
Code: [Select]
Sub LS_test()
    Dim oLSM As AcadLayerStateManager

    Set oLSM = ThisDrawing.Application. _
       GetInterfaceObject("AutoCAD.AcadLayerStateManager.17")

    oLSM.SetDatabase ThisDrawing.Database
    On Error Resume Next
    oLSM.Delete "abcd"
    If Err Then
        MsgBox "Layerstate not found...."
        Err.Clear
    Else
        ThisDrawing.Utility.Prompt vbCr & "Layerstate {abcd} deleted."
    End If
       
End Sub

CmdrDuh

  • Automatic Duh Generator
  • King Gator
  • Posts: 4039
Re: How do you delete a LayerState?
« Reply #17 on: September 11, 2006, 05:27:10 PM »
Thanks Jeff.  I haven't used the ThisDrawing.Application area much.  I need to explore that area.

T.W. - does it tell you where its found in code? (I haven't looked it up yet)  Looking in the developer guide is great only if it tells you where to find it in the IDE
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second

Matersammichman

  • Guest
Re: How do you delete a LayerState?
« Reply #18 on: September 12, 2006, 07:39:35 AM »
You guys have been such a great help to me, let me share this.
What I wanted to do was create a LayerState named "Temp" that I could save, and overwrite as needed. Here is the completed blurb of code in ADT2005)
Code: [Select]
Private Sub cmdTLS_Click()
On Error Resume Next
    Dim colLayers As AcadLayers
    Dim objDict As AcadDictionary
    Dim objLayerStates As AcadDictionary
    Dim objXrec As AcadXRecord
   
    Set colLayers = ThisDrawing.Layers
    If colLayers.HasExtensionDictionary Then
       Set objDict = colLayers.GetExtensionDictionary
       Set objLayerStates = objDict("Acad_LayerStates")
       objLayerStates("temp").Delete
   End If

'''
Dim oLSM As AcadLayerStateManager
    ' Access the LayerStateManager object
   
    Set oLSM = ThisDrawing.Application. _
       GetInterfaceObject("AutoCAD.AcadLayerStateManager.16")

    ' Associate the current drawing database with LayerStateManager
    oLSM.SetDatabase ThisDrawing.Database
oLSM.Save "Temp", acLsOn + acLsFrozen + acLsLocked

Me.hide
End Sub
« Last Edit: September 12, 2006, 09:44:03 AM by CmdrDuh »