VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

change layer

3 REPLIES 3
Reply
Message 1 of 4
thenrich
150 Views, 3 Replies

change layer

How can I change the layer of a block that was created on a differant layar? What I had is a block that was created on a layer called 'trimtags'. This block got inserted into many drawings. I've since updated the block so it is on layer 0 so by default it comes in on the current layer. But all the drawings with the old block still have the original block definition so when I insert the new block it comes in the old way and the user is still unable to change to the correct layer.
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: thenrich

Here's my sub to convert block ents to ByLayer. Public Sub BlockEntsByLayer() Dim oBlk As AcadBlock Dim oBlk1 As AcadBlock Dim oBlkRef As AcadBlockReference Dim oBlkRef1 As AcadBlockReference Dim oEnt As AcadEntity Dim oEnt1 As AcadEntity Dim ss As AcadSelectionSet Set ss = toolbox.ejSelectionSets.GetSS_BlockFilter For Each oBlkRef In ss Set oBlk = ThisDrawing.Blocks(oBlkRef.Name) If Not oBlk.IsXRef Then For Each oEnt In oBlk If TypeOf oEnt Is AcadBlockReference Then Set oBlkRef1 = oEnt Set oBlk1 = ThisDrawing.Blocks(oBlkRef1.Name) For Each oEnt1 In oBlk1 With oEnt1 If Not ThisDrawing.Layers(.Layer).Lock Then .Layer = "0" .Color = acByLayer End If End With Next oEnt1 Else With oEnt If Not ThisDrawing.Layers(.Layer).Lock Then .Layer = "0" .Color = acByLayer End If End With End If Next oEnt End If Next oBlkRef ThisDrawing.Regen acAllViewports End Sub -- ---- Ed ---- "thenrich" wrote in message news:8724639.1084465618832.JavaMail.jive@jiveforum1... How can I change the layer of a block that was created on a differant layar? What I had is a block that was created on a layer called 'trimtags'. This block got inserted into many drawings. I've since updated the block so it is on layer 0 so by default it comes in on the current layer. But all the drawings with the old block still have the original block definition so when I insert the new block it comes in the old way and the user is still unable to change to the correct layer.
Message 3 of 4
thenrich
in reply to: thenrich

thx - I'll give'er a try
Message 4 of 4
thenrich
in reply to: thenrich

turned out to be almost exactly what I'ze looking for - thx again: heres my .NET-ified version...

Dim AcadssetObj As AcadSelectionSet
Dim acadent, ent As AcadEntity
Dim blkRef As AcadBlockReference
Dim att As AcadAttributeReference
Dim blk As AcadBlock
Dim atts As Object

Try

''' Deleting old Selection set if it exists
For Each AcadssetObj In AcadDoc.SelectionSets
If AcadssetObj.Name = "TempSet" Then
AcadssetObj.Delete()
Exit For
End If
Next

AcadssetObj = AcadDoc.SelectionSets.Add("TempSet")
AppActivate("autocad")
AcadssetObj.SelectOnScreen()
AcadDoc.ActiveLayer = AcadDoc.Layers.Item("trimtags")
For Each acadent In AcadssetObj
If TypeOf acadent Is AcadBlockReference Then
blkRef = acadent
blk = AcadDoc.Blocks.Item(blkRef.Name)
For Each ent In blk
With ent
If Not AcadDoc.Layers.Item(.Layer).Lock Then
.Layer = "0"
.Color = ACAD_COLOR.acByLayer
End If
End With
Next ent
If blkRef.HasAttributes Then
atts = blkRef.GetAttributes
For Each att In atts
att.Layer = Me.lstLayers.SelectedItem
att.Update()
Next
End If
End If
acadent.Layer = Me.lstLayers.SelectedItem
AcadApp.Update()
Next

''' Deleting old Selection set if it exists
For Each AcadssetObj In AcadDoc.SelectionSets
If AcadssetObj.Name = "TempSet" Then
AcadssetObj.Delete()
Exit For
End If
Next
Catch ex As Exception
MsgBox(ex.Message & Chr(13) & ex.StackTrace)
End Try

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

Post to forums  

Autodesk Design & Make Report

”Boost