change layer

Discussion in 'AutoCAD' started by thenrich, May 13, 2004.

  1. thenrich

    thenrich Guest

    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.
     
    thenrich, May 13, 2004
    #1
  2. thenrich

    Ed Jobe Guest

    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 Jobe, May 13, 2004
    #2
  3. thenrich

    thenrich Guest

    thx - I'll give'er a try
     
    thenrich, May 13, 2004
    #3
  4. thenrich

    thenrich Guest

    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
     
    thenrich, May 13, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.