PowerShell 4.0
It works fine:
$cad = [Autodesk.AutoCAD.ApplicationServices.Application]
function Get-DocumentManager { $cad::DocumentManager }
function Get-CurrentDocument { $cad::DocumentManager.MdiActiveDocument }
function Get-CurrentEditor { (Get-CurrentDocument).Editor }
function Get-CurrentDatabase { (Get-CurrentDocument).Database }
All these functions return the necessary objects. But if I rewrite the body of Get-CurrentDocument
function then I get the problem:
$cad = [Autodesk.AutoCAD.ApplicationServices.Application]
function Get-DocumentManager { $cad::DocumentManager }
function Get-CurrentDocument { (Get-DocumentManager).MdiActiveDocument }
function Get-CurrentEditor { (Get-CurrentDocument).Editor }
function Get-CurrentDatabase { (Get-CurrentDocument).Database }
I get the error message when I launch the Get-CurrentDocument
function:
Object reference not set to an instance of an object.
Why does it happen? This way works fine for my Get-CurrentEditor
and Get-CurrentDatabase
functions.