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

GetObjectId returns '(0)', generating eNullObjectID error

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
Stormraven
992 Views, 2 Replies

GetObjectId returns '(0)', generating eNullObjectID error

I'm having trouble with this code in AutoCAD 2015:

 

        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Try ' Reference the Layout Manager Dim acLayoutMgr As LayoutManager = LayoutManager.Current ' Get the current layout Dim acLayoutID As DatabaseServices.ObjectId = acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout) Dim acLayout As Layout = acTrans.GetObject(acLayoutID, OpenMode.ForRead) ...

 

This is a functionally the same as the AutoCAD 2015 Help article "Plot from Model Space (.NET)."  The article combines my last two steps, but I defined acLayoutID as an intermediate step to try to debug.  The final line, "Dim acLayout ...," consistently throws an error, eNullObjectID.

 

The problem appears to be that although acLayoutMgr.CurrentLayout returns "Model," the function acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout) returns an ObjectId that converts to string "(0)", which I presume to be a Null object.

 

I should point out that the code worked in AutoCAD 2012.  I'm trying to manage an upgrade to 2015.

 

Thanks in advance for any help.

2 REPLIES 2
Message 2 of 3
Stormraven
in reply to: Stormraven

A former coworker has found a solution to the problem.  The following code works where the officially documented help file code fails:

 

        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
            Try
                ' Get the current layout
                Dim acLayout As Layout = Nothing

                Dim myDictionary As DBDictionary = TryCast(acCurDb.LayoutDictionaryId.GetObject(OpenMode.ForRead), DBDictionary)
                Dim CurrentLayoutName As String = TryCast(LayoutManager.Current.CurrentLayout, String)

                If myDictionary.Contains(CurrentLayoutName) Then
                    Dim myLayoutID As ObjectId = myDictionary(CurrentLayoutName)

                    acLayout = TryCast(myLayoutID.GetObject(OpenMode.ForRead), Layout)
                Else
                    Return Nothing
                End If

                If acLayout Is Nothing Then
                    Return Nothing
                End If

 

Message 3 of 3

This worked for me too. I was porting an existing app used in 2014 (VS 2010/FW4.0) for use in 2016 (VS 2012 FW4.5) and got the same eNullObjectId error with essentially identical code.

 

When I get time, I am going to run this by ADN to see why this has changed. Thanks for the help!

 

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