Let's start with this:
{code}
If Not IsNothing(tst.Value) Then
myObjIDs = New DatabaseServices.ObjectIdCollection(tst.Value.GetObjectIds)
{code}
No need to create an ObjectIdCollection because you can iterate over the
array of ObjectIds returned by GetObjectIds():
Here is a complete example:
{code}
// Translated by Reflector (http://www.redgate.net/reflector) (untested)
Public Class EntityHelper
' Takes an Entity and returns the name of the layout it is on, or
' an empty string if the entity is not in a layout block:
Public Shared Function GetLayoutName(ByVal entity As Entity) As String
Dim blockId As ObjectId = entity.BlockId
Dim btr As BlockTableRecord =
TryCast(blockId.GetObject(OpenMode.ForRead),BlockTableRecord)
If Not btr.LayoutId.IsNull Then
Dim layout As Layout =
TryCast(btr.LayoutId.GetObject(OpenMode.ForRead),Layout)
If (Not layout Is Nothing) Then
Return layout.LayoutName
End If
End If
Return String.Empty
End Function
' Usage example: Displays the name of the layout
' of each entity in a selection set:
Public Shared Sub Example()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim pso As New PromptSelectionOptions
Dim psr As PromptSelectionResult = doc.Editor.GetSelection
If (psr.Status = PromptStatus.OK) Then
Using tr As Transaction = doc.TransactionManager.StartTransaction
Dim i As Integer = 0
Dim id As ObjectId
For Each id In psr.Value.GetObjectIds
Dim entity As Entity =
TryCast(id.GetObject(OpenMode.ForRead),Entity)
Dim layoutName As String = EntityHelper.GetLayoutName(entity)
doc.Editor.WriteMessage(vbNewLine & "Item {0} Layout = {1}",
i, layoutName )
i += 1
Next
tr.Commit
End Using
End If
End Sub
End Class
{code}
In the code that follows that you are assuming that all objects in the
selection set are block references. Are they? If they're not you will get
an error when assigning the result of GetObject() to the BlockReference
variable.
In any case, you shouldn't be casting to a BlockReference to start with,
because the BlockId property you need to use to find the layout is a
property of Entity, so any entity will have it.
{code}
/// Translated from C# by Reflector
Public Class EntityHelper
' Methods
Public Shared Sub Example()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument
Dim pso As New PromptSelectionOptions
Dim psr As PromptSelectionResult = doc.Editor.GetSelection
If (psr.Status = PromptStatus.OK) Then
Using tr As Transaction = doc.TransactionManager.StartTransaction
Dim i As Integer = 0
Dim id As ObjectId
For Each id In psr.Value.GetObjectIds
Dim entity As Entity =
TryCast(id.GetObject(OpenMode.ForRead),Entity)
Dim layoutName As String = EntityHelper.GetLayoutName(entity)
doc.Editor.WriteMessage("Item {0} Layout = {1}", New Object()
{ i, layoutName })
i += 1
Next
tr.Commit
End Using
End If
End Sub
Public Shared Function GetLayoutName(ByVal entity As Entity) As String
Dim blockId As ObjectId = entity.BlockId
Dim btr As BlockTableRecord =
TryCast(entity.BlockId.GetObject(OpenMode.ForRead),BlockTableRecord)
If Not btr.LayoutId.IsNull Then
Dim layout As Layout =
TryCast(btr.LayoutId.GetObject(OpenMode.ForRead),Layout)
Return layout.LayoutName
End If
Return String.Empty
End Function
End Class
{code}
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6289993@discussion.autodesk.com...
Re post without formating (hopes this works)
{code}
Dim tst As EditorInput.PromptSelectionResult
tst = DwgSheetSelection("*")
Dim myDWG As ApplicationServices.Document
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myObjIDs As DatabaseServices.ObjectIdCollection
Dim myObjID As DatabaseServices.ObjectId
Dim myBlkRef As DatabaseServices.BlockReference
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction
If Not IsNothing(tst.Value) Then
myObjIDs = New DatabaseServices.ObjectIdCollection(tst.Value.GetObjectIds)
For Each myObjID In myObjIDs
myBlkRef = myObjID.GetObject(DatabaseServices.OpenMode.ForRead, False)
Dim myBTR As DatabaseServices.BlockTableRecord
myBTR =
myBlkRef.BlockTableRecord.GetObject(DatabaseServices.OpenMode.ForRead)
'Error next line
Dim l As Layout =
myBTR.LayoutId.GetObject(DatabaseServices.OpenMode.ForRead)
Next
End If
myTrans.Dispose()
myTransMan.Dispose()
{/code}