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

Name of Block from DBObject - Can anyone help

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
425 Views, 3 Replies

Name of Block from DBObject - Can anyone help

I am trying to obtain the name of a block from a Block Reference object

Private Function ReturnBlockName(ByVal oDBObject As DBObject) as string
If TypeOf oDBObject Is BlockReference Then

End If
End Function
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

In COM, you'd cast to an AcadBlockReference and query the Name property.
Look for something similar in the managed libraries.
Message 3 of 4
KrishnaK
in reply to: Anonymous

Chris,

You should open the blockReference's blockTableRecord to get its name.

For example:

_
Public Sub AsdkTest()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim Ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
Dim trans As Transaction = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction
Try
Dim Opts As New PromptSelectionOptions()

'Build a filter list so that only block references are selected
Dim filList() As TypedValue = {New TypedValue(DxfCode.Start, "INSERT")}

Dim filter As SelectionFilter = New SelectionFilter(filList)
Dim res As PromptSelectionResult = Ed.GetSelection(Opts, filter)

'Do nothing if selection is unsuccessful
If Not res.Status = PromptStatus.OK Then Return
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idArray As ObjectId() = SS.GetObjectIds()

Dim blockRefId As ObjectId
For Each blockRefId In idArray
Dim blRef As BlockReference
blRef = trans.GetObject(blockRefId, OpenMode.ForRead)
Dim btr As BlockTableRecord
btr = trans.GetObject(blRef.BlockTableRecord(), OpenMode.ForRead)
Ed.WriteMessage(vbCrLf + btr.Name + vbCrLf)
Next

Finally
trans.Dispose()
End Try

End Sub

Krishna Kalvai
DevTech
Autodesk Message was edited by: KrishnaK
Message 4 of 4
Anonymous
in reply to: Anonymous

Thanks

wrote in message news:4855315@discussion.autodesk.com...
Chris,

You should open the blockReference's blockTableRecord to get its name.

For example:

_
Public Sub AsdkTest()
Dim db As Database = HostApplicationServices.WorkingDatabase
Dim Ed As Editor =
Application.DocumentManager.MdiActiveDocument.Editor
Dim trans As Transaction =
Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction
Try
Dim Opts As New PromptSelectionOptions()

'Build a filter list so that only block references are selected
Dim filList() As TypedValue = {New TypedValue(DxfCode.Start,
"INSERT")}

Dim filter As SelectionFilter = New SelectionFilter(filList)
Dim res As PromptSelectionResult = Ed.GetSelection(Opts, filter)

'Do nothing if selection is unsuccessful
If Not res.Status = PromptStatus.OK Then Return
Dim SS As Autodesk.AutoCAD.EditorInput.SelectionSet = res.Value
Dim idArray As ObjectId() = SS.GetObjectIds()

Dim blockRefId As ObjectId
For Each blockRefId In idArray
Dim blRef As BlockReference
blRef = trans.GetObject(blockRefId, OpenMode.ForRead)
Dim btr As BlockTableRecord
btr = trans.GetObject(blRef.BlockTableRecord(),
OpenMode.ForRead)
Ed.WriteMessage(vbCrLf + btr.Name + vbCrLf)
Next

Finally
trans.Dispose()
End Try

End Sub

Krishna Kalvai
DevTech
Autodesk

Message was edited by: KrishnaK

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