AutoCAD Electrical Forum
Welcome to Autodesk’s AutoCAD Electrical Forums. Share your knowledge, ask questions, and explore popular AutoCAD Electrical topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with layers and blocks

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
305 Views, 12 Replies

Problem with layers and blocks

I have the following situation:

Let’s say somebody had a block drawn under a certain layer and then they deleted the block. When I get that drawing from them and I try to delete the layer under which that block was created, I can’t do it because there is an object attached to it, even though the object does not appear in the drawing anymore.

What I am trying to find out is if there is a way to see/sort blocks (used or not used) that contain a certain layer.

I don't want to purge all the unused blocks and then delete the layer, I want just to delete/edit the block that contains that particular layer that I want to get rid of.

Thank you all in advance. This is my first post and I hope I get some feedback. 🙂
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

First purge your drawing of all unused blocks.

If you still cannot purge the layer then it must still be being used somewhere. From the layers drop-down, switch off all layers except this one. Zoom extents. Can you see anything?

John
Message 3 of 13
Anonymous
in reply to: Anonymous

John,

Thank you for the reply.

Unfortunately, that does not solve my problem, because as I said in my initial post, I don't want to delete the unused blocks (as some of them are going to be needed at a later time and I don't know which ones).

What I know for sure is that I don't need the block that contains the layer I want to delete, but I can't find which one it is.

Thanks again and I hope you know the answer under these conditions.
Message 4 of 13
Anonymous
in reply to: Anonymous

I don't think there is an easy way to do this. I would insert all blocks next to each other. Then explode them all. Then quickselect all object in the layer you want to delete. then you can see what blocks use this layer.
Another option is to write an custom lisp for this but that would also take a lot of time and I don't know how to examine block definitions in lisp.

Sven Kloeck
Electrical Network Design
Message 5 of 13
Anonymous
in reply to: Anonymous

You might try using the Block Editor tool to accomplish moving the geometry to a layer you wish to keep, then purge the layers you wish to delete.
A second option would be to insert the block that you want to keep into a blank new drawing...change the layers, purge the old, then go back to the old drawing and purge the block, then reinsert your new block with the corrected layers.
As someone else has alluded to...it's not going to be a simple fix for what you sound like you want to accomplish.

Hope that gives you options...
Jim
Message 6 of 13
rhesusminus
in reply to: Anonymous

Hi.

Type VBAIDE on the commandprompt in AutoCAD and press enter. DoubleClick "ThisDrawing" and copy/paste this code into that window:

-----------------------------------------
Sub ListLayersUsedInBlocks()

Dim blkBlock As AcadBlock
Dim entAcad As AcadEntity
Dim colLayers As Collection
Dim intCounter As Integer
Dim blnLayerExistsInCollection As Boolean


For Each blkBlock In ThisDrawing.Blocks
Set colLayers = New Collection
ThisDrawing.Utility.Prompt "Blockname: " & blkBlock.Name & vbCrLf
For Each entAcad In blkBlock
blnLayerExistsInCollection = False
For intCounter = 1 To colLayers.Count
If colLayers.Item(intCounter) = entAcad.Layer Then
blnLayerExistsInCollection = True
Exit For
End If
Next
If Not blnLayerExistsInCollection Then
colLayers.Add entAcad.Layer
End If
Next
ThisDrawing.Utility.Prompt "Entities on layer: "
For intCounter = 1 To colLayers.Count
ThisDrawing.Utility.Prompt colLayers.Item(intCounter) & IIf(intCounter <> colLayers.Count, " & ", vbCrLf)
Next
ThisDrawing.Utility.Prompt vbCrLf
Set colLayers = Nothing
Next

End Sub
-------------------------------------------

Go back to AutoCAD and type VBARUN on the commandline, and press enter. Then press the Run button.

When it's done, you can open AutoCADs text window (F2) and see what blocks exists, and what layers they have entities in.

Hope this answers your question.


Trond Hasse Lie

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 7 of 13
Anonymous
in reply to: Anonymous

Hey Trond Hasse Lie,

When i'm correct this VBA will only show the block layer, not the entities inside the block. They also can be on a different layer.

Peter
Message 8 of 13
rhesusminus
in reply to: Anonymous

Well Peter..

Take another look.
There are 2 "for each" loops there, the first goes through all blocks in the blocks collection, and the other goes through all entities in those blocks. It finds the layer name for each entity in this block, and puts the layername into a collection of layernames (if the layername isn't already there). When all the entities in the block has been "processed", all the unique layernames are sent to autocads text window. The layer collection is emptied, and the next block is processed...


THL

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 9 of 13
Anonymous
in reply to: Anonymous

Hi,

Yep, did take a second look and the result remains.
Only the layer on which the blocks are inserted is visible in the text window.
In the attached file you see the results of the VBA, also you see one of the used block properties showing the layer TAGS. This layer is not visible in the text window.

Peter
Message 10 of 13
rhesusminus
in reply to: Anonymous

Ok.

My code only went through the blocks collection, were the definitions of all blocks, inserted or not, resides in the dwg file. If you use the BATTMAN command in AutoCAD, youll see that the attributes in VT0011 actually is on layer 0. It seems like AutoCAD Electrical moves the attributereferences to the designated layers when the block is inserted into the drawing (hence the result you get when using EATTEDIT).

However.. I updated the code, to include the already inserted blockreferences also:

-----------------------------------------------------
Sub ListLayersUsedInBlocks()

Dim ssInsertedBlocks As AcadSelectionSet
Dim dxfCode(1) As Integer
Dim dxfData(1) As Variant
Dim blkBlock As AcadBlock
Dim blkRef As AcadBlockReference
Dim entAcad As AcadEntity
Dim colLayers As Collection
Dim intCounter As Integer
Dim blnLayerExistsInCollection As Boolean
Dim attAtts As Variant
Dim attAtt As AcadAttributeReference
Dim attCounter As Integer


For Each blkBlock In ThisDrawing.Blocks
Set colLayers = New Collection
ThisDrawing.Utility.Prompt vbCr & "Blockname: " & blkBlock.Name & vbCrLf
For Each entAcad In blkBlock
blnLayerExistsInCollection = False
For intCounter = 1 To colLayers.Count
If colLayers.Item(intCounter) = entAcad.Layer Then
blnLayerExistsInCollection = True
Exit For
End If
Next
If Not blnLayerExistsInCollection Then
colLayers.Add entAcad.Layer
End If
Next

ThisDrawing.Utility.Prompt vbCr & "Blockdefinition has entities on layer(s): "
For intCounter = 1 To colLayers.Count
ThisDrawing.Utility.Prompt colLayers.Item(intCounter) & IIf(intCounter colLayers.Count, " & ", vbCr)
Next
Set colLayers = Nothing

Set ssInsertedBlocks = ThisDrawing.SelectionSets.Add("InsertedBlocks")
dxfCode(0) = 0
dxfData(0) = "INSERT"
dxfCode(1) = 2
dxfData(1) = blkBlock.Name

ssInsertedBlocks.Select acSelectionSetAll, , , dxfCode, dxfData

Set colLayers = New Collection
For Each blkRef In ssInsertedBlocks
If blkRef.HasAttributes Then
attAtts = blkRef.GetAttributes
For attCounter = 0 To UBound(attAtts)
Set attAtt = attAtts(attCounter)
blnLayerExistsInCollection = False
For intCounter = 1 To colLayers.Count
If colLayers.Item(intCounter) = attAtt.Layer Then
blnLayerExistsInCollection = True
Exit For
End If
Next
If Not blnLayerExistsInCollection Then
colLayers.Add attAtt.Layer
End If
Set attAtt = Nothing
Next
End If
Next

ThisDrawing.Utility.Prompt vbCr & "Blockreferences (inserted blocks) has attriutes on layer(s): "
For intCounter = 1 To colLayers.Count
ThisDrawing.Utility.Prompt colLayers.Item(intCounter) & IIf(intCounter colLayers.Count, " & ", vbCrLf)
Next
ThisDrawing.Utility.Prompt vbCrLf & vbCrLf
Set colLayers = Nothing

ssInsertedBlocks.Delete
Set ssInsertedBlocks = Nothing
Next

End Sub
-----------------------------------------------------
You can also download the code on http://www.baremitt.com/ListLayersUsedInBlocks.dvb

Hope this is helpful.

THL

Trond Hasse Lie
AutoCAD Electrical and EPLAN expert
Ctrl Alt El
Please select "Accept Solution" if this post answers your question. 'Likes' won't hurt either. 😉
Message 11 of 13
Anonymous
in reply to: Anonymous

Thank you all for coming up with solutions to my problem and that you RhesusMinus for the code. I didn't try it yet, but I am sure it's going to work. 🙂
Message 12 of 13
Anonymous
in reply to: Anonymous

RhesusMinus, thank you once more for the codes you provided. The first one worked, but when I tried the second one I got this message: Syntax error.

When I looked at the code I noticed that the following was not a normal color, it was red:
ThisDrawing.Utility.Prompt colLayers.Item(intCounter) & IIf(intCounter colLayers.Count, " & ", vbCr)

Can you please take another look and tell me how the code should look like? This would be of tremendous help.
Message 13 of 13
Anonymous
in reply to: Anonymous

Never mind. I took a closer look at the first code that you submitted and I found the problem. There was no "<>" by intCounter and colLayers. It works now. Thanks again!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost