.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to obtain the name of a block

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
262 Views, 2 Replies

How to obtain the name of a block


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
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous



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
Message 3 of 3
Anonymous
in reply to: Anonymous



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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost