• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    *Alan

    How to obtain the name of a block

    74 Views, 2 Replies
    07-10-2005 10:56 PM

    Hi

     

    How to obtain the name of a block ?


    <CommandMethod("LISTBLOCK")> _


    Public Sub ListBlock()

        Dim ed As Editor =
    AcApp.Application.DocumentManager.MdiActiveDocument.Editor

        Dim db As Database =
    HostApplicationServices.WorkingDatabase

        Dim trans As Transaction =
    db.TransactionManager.StartTransaction()

     

    Try

        Dim bt As BlockTable
    = CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead),
    BlockTable)

        Dim btr As
    BlockTableRecord = CType(trans.GetObject(bt(btr.ModelSpace), OpenMode.ForRead),
    BlockTableRecord)

        Dim id As
    ObjectId

        For Each id In
    btr

           
    Dim ent As Entity = CType(trans.GetObject(id, OpenMode.ForRead, False),
    Entity)

            If
    TypeOf ent Is BlockReference Then

           
        '?????

           
    End If

        Next

    Catch ex As Exception

       
    ed.WriteMessage("Error ListBlock")

    Finally

       
    trans.Dispose()

        End Try

    End Sub
    Please use plain text.
    *Jon Prisbe

    Re: How to obtain the name of a block

    07-14-2005 06:52 AM in reply to: *Alan


    Here's how I do it in C#,

    foreach(ObjectId objId in
    btr)
    {
        DBObject dbObj =
    t.GetObject(objId,OpenMode.ForRead);
        BlockReference blkRef
    = dbObj as BlockReference;
        if
    (blkRef!=null)
       
    {
            BlockTableRecord blkDef =
    (BlockTableRecord)t.GetObject(blkRef.BlockTableRecord,OpenMode.ForRead);
           
    CommandLinePrompts.Message("\nGot a block named " +
    blkDef.Name);
        }
    }


    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


    Hi

     

    How to obtain the name of a block ?


    <CommandMethod("LISTBLOCK")>
    _


    Public Sub ListBlock()

        Dim ed As Editor =
    AcApp.Application.DocumentManager.MdiActiveDocument.Editor

        Dim db As Database =
    HostApplicationServices.WorkingDatabase

        Dim trans As Transaction =
    db.TransactionManager.StartTransaction()

     

    Try

        Dim bt As
    BlockTable = CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead),
    BlockTable)

        Dim btr As
    BlockTableRecord = CType(trans.GetObject(bt(btr.ModelSpace),
    OpenMode.ForRead), BlockTableRecord)

        Dim id As
    ObjectId

        For Each id In
    btr

           
    Dim ent As Entity = CType(trans.GetObject(id, OpenMode.ForRead, False),
    Entity)

           
    If TypeOf ent Is BlockReference Then

           
        '?????

           
    End If

        Next

    Catch ex As Exception

       
    ed.WriteMessage("Error ListBlock")

    Finally

       
    trans.Dispose()

        End
    Try

    End
    Sub
    Please use plain text.
    *Alan

    Re: How to obtain the name of a block

    07-14-2005 11:12 PM in reply to: *Alan


    This Code is ok !.


    Danks M. Jon Prisbe !... Alan


    <CommandMethod("LISTBLOCK")> _


    Public Sub ListBlock()

       
    Dim
    ed As Editor =
    AcApp.Application.DocumentManager.MdiActiveDocument.Editor

       
    Dim
    db As Database =
    HostApplicationServices.WorkingDatabase

       
    Dim
    trans As Transaction =
    db.TransactionManager.StartTransaction()

     

       
    Try

       
        Dim
    bt As BlockTable =
    CType(trans.GetObject(db.BlockTableId,
    OpenMode.ForRead), BlockTable)

       
        Dim
    btr As BlockTableRecord
    = CType(trans.GetObject(bt(btr.ModelSpace),
    OpenMode.ForRead), BlockTableRecord)

       
        Dim
    id As
    ObjectId

       
        For
    Each id
    color=#0000ff>In
    btr

       
            Dim
    ent
    color=#0000ff>As
    Entity =
    color=#0000ff>CType
    (trans.GetObject(id, OpenMode.ForRead,
    color=#0000ff>False
    ), Entity)

       
            If

    color=#0000ff>TypeOf
    ent Is BlockReference

    size=2>Then

       
                Dim
    Blk
    color=#0000ff>As
    BlockReference = CType(ent,
    BlockReference)

       
                Dim
    br
    color=#0000ff>As
    BlockTableRecord =
    color=#0000ff>CType
    (trans.GetObject(Blk.BlockTableRecord,
    OpenMode.ForRead, False),
    BlockTableRecord)

           
            ed.WriteMessage("Block name = " + br.Name
    + ControlChars.Lf)

       
            End

    color=#0000ff>If

       
        Next

       
    Catch
    ex As Exception

           
    ed.WriteMessage("Error ListBlock")

       
    Finally

        trans.Dispose()

       
    End

    size=2>Try

     

    End
    color=#0000ff>Sub


    style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">


    Hi

     

    How to obtain the name of a block ?


    <CommandMethod("LISTBLOCK")>
    _


    Public Sub ListBlock()

        Dim ed As Editor =
    AcApp.Application.DocumentManager.MdiActiveDocument.Editor

        Dim db As Database =
    HostApplicationServices.WorkingDatabase

        Dim trans As Transaction =
    db.TransactionManager.StartTransaction()

     

    Try

        Dim bt As
    BlockTable = CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead),
    BlockTable)

        Dim btr As
    BlockTableRecord = CType(trans.GetObject(bt(btr.ModelSpace),
    OpenMode.ForRead), BlockTableRecord)

        Dim id As
    ObjectId

        For Each id In
    btr

           
    Dim ent As Entity = CType(trans.GetObject(id, OpenMode.ForRead, False),
    Entity)

           
    If TypeOf ent Is BlockReference Then

           
        '?????

           
    End If

        Next

    Catch ex As Exception

       
    ed.WriteMessage("Error ListBlock")

    Finally

       
    trans.Dispose()

        End
    Try

    End
    Sub
    Please use plain text.