.NET
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
*Alan
How to obtain the name of a block
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
74 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.MdiActiveDocumen t.Editor
AcApp.Application.DocumentManager.MdiActiveDocumen
Dim db As Database =
HostApplicationServices.WorkingDatabase
HostApplicationServices.WorkingDatabase
Dim trans As Transaction =
db.TransactionManager.StartTransaction()
db.TransactionManager.StartTransaction()
Try
Dim bt As BlockTable
= CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead),
BlockTable)
= CType(trans.GetObject(db.BlockTableId, OpenMode.ForRead),
BlockTable)
Dim btr As
BlockTableRecord = CType(trans.GetObject(bt(btr.ModelSpace), OpenMode.ForRead),
BlockTableRecord)
BlockTableRecord = CType(trans.GetObject(bt(btr.ModelSpace), OpenMode.ForRead),
BlockTableRecord)
Dim id As
ObjectId
ObjectId
For Each id In
btr
btr
Dim ent As Entity = CType(trans.GetObject(id, OpenMode.ForRead, False),
Entity)
If
TypeOf ent Is BlockReference Then
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
Re: How to obtain the name of a block
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.BlockTableRec ord,OpenMode.ForRead);
CommandLinePrompts.Message("\nGot a block named " +
blkDef.Name);
}
}
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.BlockTableRec
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">
"Alan" <sscvs@bluewin.ch>
wrote in message
href="news:4897475@discussion.autodesk.com">news:4897475@discussion.autodesk.com...
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
Re: How to obtain the name of a block
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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.MdiActiveDocumen
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
color=#0000ff>Sub
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
"Alan" <sscvs@bluewin.ch> a
écrit dans le message de
href="news:4897475@discussion.autodesk.com">news:4897475@discussion.autodesk.com...
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
