.NET

.NET

Reply
Active Contributor
44 Posts
0 Kudos
Registered: ‎04-12-2005
Post 1 of 4

Name of Block from DBObject - Can anyone help

123 Views, 3 Replies
05-24-2005 01:31 PM
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
*Frank Oquendo
Post 2 of 4

Re: Name of Block from DBObject - Can anyone help

05-24-2005 02:25 PM in reply to: Chris Ludtke
In COM, you'd cast to an AcadBlockReference and query the Name property.
Look for something similar in the managed libraries.
Contributor
17 Posts
0 Kudos
Registered: ‎05-24-2005
Post 3 of 4

Re: Name of Block from DBObject - Can anyone help

05-24-2005 02:53 PM in reply to: Chris Ludtke
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
*Chris Ludtke
Post 4 of 4

Re: Name of Block from DBObject - Can anyone help

05-27-2005 07:17 AM in reply to: Chris Ludtke
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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post