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

How to get the blockname?

4 REPLIES 4
Reply
Message 1 of 5
simonkx
323 Views, 4 Replies

How to get the blockname?

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

Thank you very much!
Message 4 of 5
simonkx
in reply to: simonkx

but now, I have another problem:
how to regenerate the drawing with C#, or which method can do this?
thanks
Message 5 of 5
Anonymous
in reply to: simonkx

http://discussion.autodesk.com/thread.jspa?messageID=5102182&tstart=0#5102182

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