ObjectId OpenAs

ObjectId OpenAs

David_Prontnicki
Collaborator Collaborator
340 Views
2 Replies
Message 1 of 3

ObjectId OpenAs

David_Prontnicki
Collaborator
Collaborator

I have an older method I wrote and it is still working in other programs written prior. But when creating a new one, I can not use the same method anymore as it tells me "OpenAs is not a member of ObjectId". Has this changed or am I missing something?

 

    Public Sub BurstAllBlocks()

        Dim curDb As Database = Active.Database

        Try

            Using tr As Transaction = curDb.TransactionManager.StartTransaction()

                Dim layoutDbDictionary As DBDictionary = tr.GetObject(curDb.LayoutDictionaryId, OpenMode.ForRead)

                For Each layoutDbDictionaryEntry As DBDictionaryEntry In layoutDbDictionary

                    Dim layout As Layout = CType(layoutDbDictionaryEntry.Value.GetObject(OpenMode.ForRead), Layout)
                    Dim blkTblRec As BlockTableRecord = tr.GetObject(layout.BlockTableRecordId, OpenMode.ForWrite)

                    Dim rxClass = RXObject.GetClass(GetType(BlockReference))
                    Dim blocks = blkTblRec.Cast(Of ObjectId).Where(Function(ent) ent.ObjectClass.IsDerivedFrom(rxClass)) _
                        .Select(Function(ent) ent.OpenAs(Of BlockReference)(tr, OpenMode.ForRead))

                    For Each block As BlockReference In blocks

                        BurstBlocks(tr, block, blkTblRec)

                    Next

                Next

                tr.Commit()

            End Using

        Catch ex As Exception

            MessageServices.DisplayError("Error Bursting Blocks!", "Click OK to skip this section and continue.", ex)

        End Try

    End Sub
0 Likes
Accepted solutions (1)
341 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant

Hi,

 

As far as I know the ObjectId type never had such OpenAs method (see ObjectId methods).

This is certainly an extension method which was part of your "other programs written prior".



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 3

David_Prontnicki
Collaborator
Collaborator
Accepted solution

@_gile 

I forgot about an extension I was using to make that happen. If anyone else is interested here it is: 

Imports System.Runtime.CompilerServices
Imports Autodesk.AutoCAD.DatabaseServices

Module DBObjectExtensions
    <Extension()>
    Public Function OpenAs(Of T As DBObject)(ByVal objectId As ObjectId, tr As Transaction, openMode As OpenMode)

        Return DirectCast(tr.GetObject(objectId, openMode), T)

    End Function

End Module

 

0 Likes