How to obtain the name of a block

How to obtain the name of a block

Anonymous
Not applicable
561 Views
2 Replies
Message 1 of 3

How to obtain the name of a block

Anonymous
Not applicable

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
0 Likes
562 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable


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
0 Likes
Message 3 of 3

Anonymous
Not applicable


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
0 Likes