.NET

Reply
*Alan
Message 1 of 3 (102 Views)

How to obtain the name of a block

102 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
*Jon Prisbe
Message 2 of 3 (102 Views)

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
*Alan
Message 3 of 3 (102 Views)

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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.