Open-Document for AutoCAD drawings fails in PowerShell IDEs

Issue

When calling Open-Document with -Application 'DWG TrueView' in VsCode or another PowerShell IDE it fails with the following errors.

ERROR powerJobs.Application.TrueView.Application - DWG TrueView: Failed to initialize application!
System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
   at NativeMethods.SetupHostApplication()
   at powerJobs.Application.TrueView.Application.Start()
ERROR powerJobs.Cmdlets.CmdLets.CadCmdletBase - OpenDocumentContext failed with exception: Unable to load DLL 'DwgLibrary.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
System.DllNotFoundException: Unable to load DLL 'DwgLibrary.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at powerJobs.Application.TrueView.UnsafeNativeMethods.☺(String ☻, Int32 ♥, Int32& ♦)
   at ♣.♣.☺(String ☻, Int32 ♥, Int32& ♦)
   at powerJobs.Application.TrueView.Document..ctor(IApplication application, OpenDocumentSettings openSettings)
   at powerJobs.Application.TrueView.Application.OpenDocument_Internal(OpenDocumentSettings openSettings)
   at powerJobs.Common.Applications.ApplicationBase.Open(OpenDocumentSettings openSettings)
   at powerJobs.Cmdlets.CmdLets.OpenDocumentContext.Execute()

Cause

This is currently under investigation

Solution

To get around this you can manually load the missing acdbmgd.dll and add the Dwg TrueView directory to the windows path variable. Depending on your versions you'll have to update the paths

For TrueView 2024

[System.Reflection.Assembly]::LoadFrom('C:\Program Files\Autodesk\AutoCAD 2024\acdbmgd.dll')
$env:Path += ';C:\Program Files\Autodesk\DWG TrueView 2024 - English'