.NET

Reply
Contributor
simonkx
Posts: 20
Registered: ‎12-29-2005
Message 1 of 5 (82 Views)

How to get the blockname?

82 Views, 4 Replies
03-04-2006 10:05 PM
Hi,
I have created a file of .dwg with several blocks,select the blocks and obtain their ObjectIds,now how to get the blockname?
Anybody can help me? Or is there some examples?
thanks
*Alan
Message 2 of 5 (82 Views)

Re: How to get the blockname?

03-05-2006 12:27 AM in reply to: simonkx
Hi,

This code list block, list Attribute
See code --> br.Name for name of block

_

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

Dim EntitySet As DBObjectCollection

ent.Explode(EntitySet)

Dim Blk As BlockReference = CType(ent, BlockReference)

Dim br As BlockTableRecord = CType(trans.GetObject(Blk.BlockTableRecord,
OpenMode.ForRead, False), BlockTableRecord)

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

'Get the attribute references,if any

Dim atts As AttributeCollection

atts = Blk.AttributeCollection

If atts.Count > 0 Then

ed.WriteMessage(vbNewLine + "ObjectId : " + br.ObjectId.ToString)

Dim attId As ObjectId

For Each attId In atts

Dim att As AttributeReference

att = CType(trans.GetObject(attId, OpenMode.ForRead, False),
AttributeReference)

ed.WriteMessage(vbNewLine + att.Tag + " " + att.TextString)

Next

End If

End If

Next

Catch ex As Exception

ed.WriteMessage("Error ListBlock")

Finally

trans.Dispose()

End Try

End Sub
Contributor
simonkx
Posts: 20
Registered: ‎12-29-2005
Message 3 of 5 (82 Views)

Re: How to get the blockname?

03-05-2006 01:19 AM in reply to: simonkx
Thank you very much!
Contributor
simonkx
Posts: 20
Registered: ‎12-29-2005
Message 4 of 5 (82 Views)

Re: How to get the blockname?

03-05-2006 01:55 AM in reply to: simonkx
but now, I have another problem:
how to regenerate the drawing with C#, or which method can do this?
thanks
Distinguished Contributor
Alexander Rivilis
Posts: 303
Registered: ‎09-26-2004
Message 5 of 5 (82 Views)

Re: How to get the blockname?

03-05-2006 12:46 PM in reply to: simonkx
http://discussion.autodesk.com/thread.jspa?messageID=5102182&tstart=0#5102182

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community