powerJobs cmdlets fail with 0x80004005 when using InventorServer
Description
When using InventorServer, Open-Document, Export-Document, Close-Document fails with
"Unspecified error (Exception from HRESULT: 080004005 (E_FAIL))
Cause
In some situations InventorServer will run into this error when the active project file points to design data folder that doesn't exist or doesn't contain any design data
Solution
Download the project file from Vault and ensure that DesignData and Styles are available where the project file is looking for them.
As those rarely change it is sufficient to manually download them where they are expected by the Inventor project. For most people those files are stored in Vault and can simply be downloaded with "Get.."
When changes are made to those files, they should be updated on the job machine
Inventor styles are not confirmed to cause issues and are just loaded for ensurance
This workaround assumes Vault runs with one project file that is enforced
- Create C:\ProgramData\coolOrange\powerJobs\Modules\SaveVaultFileWithProject.psm1 with
function SaveVaultFileWithProject {
param (
$VaultFilePath,
$WorkspaceDirectoryName = "Designs",
[bool]$FastOpen = $false
)
Write-Host ">> $($MyInvocation.MyCommand) >>"
Write-Host "VaultFilePath: $VaultFilePath"
Write-Host "WorkspaceDirectoryName: $WorkspaceDirectoryName"
Write-Host "FastOpen: $FastOpen"
$result = @{
Result = $true
Files = @()
ProjectFile = $null
}
$localWorkspaceDirectoryPath = Join-Path -Path ($vaultConnection.WorkingFoldersManager.GetWorkingFolder('$')).FullPath -ChildPath $WorkspaceDirectoryName
Write-Host "Deleting local workspace directory: $localWorkspaceDirectoryPath"
Remove-Item -LiteralPath $localWorkspaceDirectoryPath -Recurse -Force -ErrorAction SilentlyContinue
$ipjVaultPath = $vault.DocumentService.GetInventorProjectFileLocation()
$result.ProjectFile = (Save-VaultFile -File $ipjVaultPath) | Select-Object -First 1
$result.Files = Save-VaultFile -File $VaultFilePath -ExcludeChildren:$FastOpen -ExcludeLibraryContents:$FastOpen
if (-not $result.ProjectFile -or $result.Files.Count -lt 1) {
$result.Result = $false
$result.Files.Clear()
$result.ProjectFile = $null
}
# The working directory needs to be created manually as this would usually be done by Save-VaultFile.
$null = New-Item -Path $workingDirectory -ItemType Directory -Force
return $result
}
-
In your jobs and modules, instead of Save-VaultFile, use SaveVaultFileWithProject and use the Project option in Open-Document
$downloadResult = SaveVaultFileWithProject -VaultFilePath $file._FullPath -WorkspaceDirectoryName 'Designs' -FastOpen $false
$localFile = $downloadResult.Files[0]
$openResult = Open-Document -LocalFile $localFile.LocalPath -Application 'InventorServer' -Options @{
Project = $downloadResult.ProjectFile.LocalPath
FastOpen = $fastOpen
}
Adaption for multiple Vaults
In case you have multiple Vaults with different workspace folders the function could be extended with a switch statement
function SaveVaultFileWithProject {
param (
$VaultFilePath,
[bool]$FastOpen = $false
)
Write-Host ">> $($MyInvocation.MyCommand) >>"
Write-Host "VaultFilePath: $VaultFilePath"
Write-Host "FastOpen: $FastOpen"
$result = @{
Result = $true
Files = @()
ProjectFile = $null
}
switch ($vaultConnection.Vault) {
'Vault' { $workspaceDirectoryName = 'Designs'; break }
'Vault1' { $workspaceDirectoryName = 'Projects'; break }
default { $workspaceDirectoryName = 'Designs' }
}
$localWorkspaceDirectoryPath = Join-Path -Path ($vaultConnection.WorkingFoldersManager.GetWorkingFolder('$')).FullPath -ChildPath $workspaceDirectoryName
Write-Host "Deleting local workspace directory: $localWorkspaceDirectoryPath"
Remove-Item -LiteralPath $localWorkspaceDirectoryPath -Recurse -Force -ErrorAction SilentlyContinue
$ipjVaultPath = $vault.DocumentService.GetInventorProjectFileLocation()
$result.ProjectFile = (Save-VaultFile -File $ipjVaultPath) | Select-Object -First 1
$result.Files = Save-VaultFile -File $VaultFilePath -ExcludeChildren:$FastOpen -ExcludeLibraryContents:$FastOpen
if (-not $result.ProjectFile -or $result.Files.Count -lt 1) {
$result.Result = $false
$result.Files.Clear()
$result.ProjectFile = $null
}
# The working directory needs to be created manually as this would usually be done by Save-VaultFile.
$null = New-Item -Path $workingDirectory -ItemType Directory -Force
return $result
}
$downloadResult = SaveVaultFileWithProject -VaultFilePath $file._FullPath -FastOpen $false
$localFile = $downloadResult.Files[0]
$openResult = Open-Document -LocalFile $localFile.LocalPath -Application 'InventorServer' -Options @{
Project = $downloadResult.ProjectFile.LocalPath
FastOpen = $fastOpen
}