Author Topic: How do you delete a LayerState?  (Read 5806 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?

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

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: 5251
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!

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Jeff_M

  • King Gator
  • Posts: 4087
  • 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.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
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.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)