Author Topic: Deleting a Layer  (Read 3654 times)

0 Members and 1 Guest are viewing this topic.

Arizona

  • Guest
Deleting a Layer
« on: June 07, 2006, 01:10:40 PM »
I have some drawings that have both the old layering scheme and the new layering scheme contained within them. I am able to iterate through the lists of old name and move all the entities to the new layer. The problem I encountered is that even though the layer is now empty it will not delete using VBA. What am I missing? Any ideas?

P.S. This is version 2000i, so no layer translator.

Bob Wahr

  • Guest
Re: Deleting a Layer
« Reply #1 on: June 07, 2006, 01:18:18 PM »
How are you trying to delete them?

Arizona

  • Guest
Re: Deleting a Layer
« Reply #2 on: June 07, 2006, 01:31:27 PM »
   Layer defined as acadlayer

 If Layer.Name = UCase(oldLayers(intNum)) Then
      intCnt = intNum
         strName1 = oldLayers(intCnt)
         strNewName = newLayers(intCnt)
         CreateNewLayer(strNewName)  'create new layer
         
             'selection set stuff (I deleted this just for simplification)and change
     
         For Each entObj In objSelSet
            entObj.Layer = strNewName
            entObj.Linetype = "BYLAYER"
            intEntity = intEntity + 1
         Next entObj
         intCnt = intCnt + 1  'increments thru old layer names

         Layer.Delete (strName1)     '***This is the staement that is failing.
   
      End If

The error message I'm getting is "Wrong number of arguments or invalid property assignment"
If I comment out the layer delete line the code runs through doing everything that I need it to do except purge the layer.

Bob Wahr

  • Guest
Re: Deleting a Layer
« Reply #3 on: June 07, 2006, 01:42:51 PM »
Does it work if you change the line to

Layer.Delete

Bryco

  • Water Moccasin
  • Posts: 1882
Re: Deleting a Layer
« Reply #4 on: June 07, 2006, 02:29:33 PM »
You probably need to check each ent in each block as well.
But I have found layers are resistant to deletion after wblocking and cant find out why. I delete that RAK crap, but there may be a timing issue with that.

Arizona

  • Guest
Re: Deleting a Layer
« Reply #5 on: June 07, 2006, 02:31:49 PM »
No, it didn't work that way either. But I just figured it out. I think I must have had a brain fart...
I wasn't cycling through the entities within the blocks...dumb, dumb, dumb!
I knew I should have gone home before I wore out my brain.

Thanks Bryco, you were right on!

Jeff_M

  • King Gator
  • Posts: 4087
  • C3D user & customizer
Re: Deleting a Layer
« Reply #6 on: June 07, 2006, 02:48:17 PM »
Also, if the layer is set to frozen in a PS viewport, that will keep it from being deleted.

MikeJarosz

  • Guest
Re: Deleting a Layer
« Reply #7 on: June 07, 2006, 03:02:51 PM »
If you have blocks that have entities inside that are on a layer you want to purge, there is an alternative way of cleaning it out. It's a favorite trick of mine I dig up every time nothing else works.

A dxf file is a text file, and a text search and replace will work. Say you have a layer "A-Glass-Wall". You can search for "A-Glass-Wall" and replace with 0.

A dxf file for a good sized .dwg will have several million lines, so you can't use an in-memory editor like notepad. I have Unix utilities, so I use SED. But, if you don't have a streaming editor, you can write a small program to open the dxf file and loop through it  replacing as you go.

If you are a real dxf expert, there are other editing tricks -- like replacing z coordinates with 0. As always, be careful. A global search and replace could create a monster that crashes when you try to load it. Make sure you save everything before you start.

Dnereb

  • Guest
Re: Deleting a Layer
« Reply #8 on: June 07, 2006, 03:57:30 PM »
Basic principle Creating and deletein a layer

Code: [Select]
Sub Test()

Dim Ac As AcadLayer

ThisDrawing.Layers.Add "TEST"

Set Ac = ThisDrawing.Layers("Test")
Ac.Delete

End Sub

If you can't wo0rk it out from here ask for details....good luck

Bob Wahr

  • Guest
Re: Deleting a Layer
« Reply #9 on: June 07, 2006, 04:05:59 PM »
Berend,

I think Anozira got it worked out.

Dnereb

  • Guest
Re: Deleting a Layer
« Reply #10 on: June 07, 2006, 04:55:17 PM »
Mmmmh overlooked the post.......sorry.

Anozira??? funny.


Arizona

  • Guest
Re: Deleting a Layer
« Reply #11 on: June 08, 2006, 06:15:07 AM »
Jeff, You brought up a good point in that I wasn't checking the state of any of the layers.

Mike, What an interesting concept. At this point for me, it will be easier to iterate through the entities that make up each block.

Berend, Thanks anyway. Sometimes it's the simplest/most obvious things that catch me up. I usually have to go have a cup of coffee and then it hits me what I overlooked.

Bob, Was that one cup of coffee too many? Or are you still typing at the speed of sound?