Skip to content

Commit

Permalink
Merge master branch into 'origin/powerGate_rework'
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRossmeisl committed Dec 9, 2022
2 parents 6492c3e + 0880531 commit 4a12ef9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 154 deletions.
49 changes: 30 additions & 19 deletions Files/powerEvents/Events/ErpService.Lifecycle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ function Test-ErpItemAndBOMForVaultFileOrVaultItem {
#Attention!!! When changing inside this function please check if you have to change somthing in "Check-Boms" function, beacause the functions are similare
Log -Begin
$number = GetEntityNumber -Entity $Entity
if(-not $number) {
if (-not $number) {
Add-VaultRestriction -EntityName $number -Message "There is no erp material linked to this entity!"
}

$erpMaterial = Get-ERPObject -EntitySet "Materials" -Keys @{ Number = $number }
if ($? -eq $false) {
return
}
}

if (-not $erpMaterial) {
Add-VaultRestriction -EntityName $number -Message "An item with the number '$($number)' does not exist in the ERP system."
Add-VaultRestriction -EntityName $number -Message "An item with the number '$($number)' does not exist in the ERP system."
return
}
}
if ($Entity._Extension -eq "ipt") {
return
}
Expand All @@ -44,15 +44,15 @@ function Test-ErpItemAndBOMForVaultFileOrVaultItem {
#>

$erpBomHeader = Get-ERPObject -EntitySet "BomHeaders" -Keys @{Number = $number } -Expand "BomRows"
if ($? -eq $false) {
return
}
if ($? -eq $false) {
return
}

if (-not $erpBomHeader) {
Log -Message "Bomheader doesn't exist yet and is new!"
Log -Message "Bomheader doesn't exist yet and is new!"
Add-VaultRestriction -EntityName $number -Message "Open the BOM Window, because the ERP BOM is different then in Vault: BOM does not exist in ERP!"
return
}
}

Log -Message "Bom head exists! Check if rows need to be added/updated"
$vaultBomRows = GetVaultBomRows -Entity $Entity
Expand Down Expand Up @@ -117,33 +117,44 @@ function RestrictItemRelease($items) {
Log -End
}

function StartSynchronizeJob($file) {
# since Synchronize Properties gets triggered already by powerEvents, disable it in the Vault configuration!
Write-Host "Adding job 'Synchronize Properties' for file '$($file._Name)' to queue."
Add-VaultJob -Name "autodesk.vault.syncproperties" -Parameters @{
"FileVersionIds" = $file.Id;
"QueueCreateDwfJobOnCompletion" = $true
} -Description "Synchronize properties of file: '$($file._Name)'"
}

Register-VaultEvent -EventName UpdateFileStates_Post -Action 'AddPdfJob'
function AddPdfJob($files, $successful) {
Log -Begin
if (-not $successful) { return }
$releasedFiles = @($files | Where-Object { $_._Extension -in $supportedPdfExtensions -and $_._ReleasedRevision -eq $true })
Write-Host "Found '$($releasedFiles.Count)' files which are valid to add a PDF job for!"
foreach ($file in $releasedFiles) {
# since Synchronize Properties gets triggered already by powerEvents, disable it in the Vault configuration!
Write-Host "Adding job 'Synchronize Properties' for file '$($file._Name)' to queue."
Add-VaultJob -Name "autodesk.vault.syncproperties" -Parameters @{
"FileVersionIds"=$file.Id;
"QueueCreateDwfJobOnCompletion"=$true} -Description "Synchronize properties of file: '$($file._Name)'"
foreach ($file in $releasedFiles) {
StartSynchronizeJob($file)
$jobType = "ErpService.Create.PDF"
Write-Host "Adding job '$jobType' for file '$($file._Name)' to queue."
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE" } -Description "Create PDF for file '$($file._Name)' and upload to ERP system" -Priority 110
}
Log -End
}

Register-VaultEvent -EventName UpdateItemStates_Post -Action 'AddItemPdfJob'
function AddItemPdfJob($items) {
Log -Begin
$releasedItems = @($items | Where-Object { $_._ReleasedRevision -eq $true})
$releasedItems = @($items | Where-Object { $_._ReleasedRevision -eq $true })
foreach ($item in $releasedItems) {
$jobType = "Erp.Service.CreatePDFFromItem"
Write-Host "Adding job '$jobType' for item '$($item._Name)' to queue."
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $item.Id; "EntityClassId" = "ITEM" } -Description "Create PDF for item '$($item._Name)' and upload to ERP system" -Priority 101
$attachedDrawings = Get-VaultItemAssociations -Number $item._Number
Write-Host "Found '$($attachedDrawings.Count)' files which are valid to add a PDF job for!"
foreach ($file in $attachedDrawings) {
StartSynchronizeJob($file)
$jobType = "ErpService.Create.PDF"
Write-Host "Adding job '$jobType' for file '$($file._Name)' to queue."
Add-VaultJob -Name $jobType -Parameters @{ "EntityId" = $file.Id; "EntityClassId" = "FILE"; "ItemNumber" = $item._Number } -Description "Create PDF for file '$($file._Name)' and upload to ERP system" -Priority 110
}
Log -End
}
Log -End
}
25 changes: 12 additions & 13 deletions Files/powerGate/Modules/MaterialFunctions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ function Update-VaultFileWithErrorHandling {
function Update-VaultItemWithErrorHandling {
param (
$Number,
$erpMaterial,
[Hashtable]$Properties
)
$fehler = $false
$updateditem = Update-VaultItem -Number $Number -Properties $Properties
$updateditem = Update-VaultItem -Number $Number -Description $erpMaterial.Description -NewNumber $erpMaterial.Number -Properties $Properties
foreach($prop in $Properties.GetEnumerator()){
if($updateditem.($prop.Key) -ne ($prop.Value)){
$fehler = $true
Expand All @@ -98,23 +99,21 @@ function SetEntityProperties($erpMaterial, $vaultEntity) {
#TODO: Update Entity UDPs with values from ERP
if ($vaultEntity._EntityTypeID -eq "ITEM") {
try {
Update-VaultItemWithErrorHandling -Number $vaultEntity._Number -Properties @{
#the item description cannot be updated, since "Description (Item,CO)" is a system property!
"_Description(Item,CO)" = $erpMaterial.Description
"_Number" = $erpMaterial.Number
}
}catch {
Update-VaultItemWithErrorHandling -Number $vaultEntity._Number
}
catch {
ShowMessageBox -Message $_.Exception.Message -Title "powerGate ERP - Link ERP Item" -Button "OK" -Icon "Error"
}
}
elseif ($vaultEntity._EntityTypeID -eq "FILE") {
try {
Update-VaultFileWithErrorHandling -File $vaultEntity._FullPath -Properties @{
"_PartNumber" = $erpMaterial.Number
"_Description" = $erpMaterial.Description
try {
Update-VaultFileWithErrorHandling -File $vaultEntity._FullPath -Properties @{
"_PartNumber" = $erpMaterial.Number
"_Description" = $erpMaterial.Description
}
}
} catch {
ShowMessageBox -Message $_.Exception.Message -Title "powerGate ERP - Link ERP Item" -Button "OK" -Icon "Error"
catch {
ShowMessageBox -Message $_.Exception.Message -Title "powerGate ERP - Link ERP Item" -Button "OK" -Icon "Error"
}
}
}
Expand Down
105 changes: 0 additions & 105 deletions Files/powerJobs/Jobs/Erp.Service.CreatePDFFromItem.ps1

This file was deleted.

29 changes: 12 additions & 17 deletions Files/powerJobs/Jobs/ErpService.Create.PDF.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ $openReleasedDrawingsFast = $true
$vaultToPgsMapping = @{ 'Vault' = $vaultConnection.Server; 'TestVault' = 'localhost'}
#endregion

$localPDFfileLocation = "$workingDirectory\$($file._Name).pdf"
$vaultPDFfileLocation = $file._EntityPath + "/" + (Split-Path -Leaf $localPDFfileLocation)

$logPath = Join-Path $env:LOCALAPPDATA "coolOrange\Projects\ErpService.Create.Pdf-Job.log"
Set-LogFilePath -Path $logPath

Expand All @@ -45,15 +42,16 @@ if(-not $connected) {
}

$ipjVaultPath = $vault.DocumentService.GetInventorProjectFileLocation()
$localWorkspaceFolder = ($vaultConnection.WorkingFoldersManager.GetWorkingFolder("$/")).FullPath
$localIpjFile = (Save-VaultFile -File $ipjVaultPath -DownloadDirectory $localWorkspaceFolder)[0]
$workingDirectory = ($vaultConnection.WorkingFoldersManager.GetWorkingFolder("$/")).FullPath
$localIpjFile = (Save-VaultFile -File $ipjVaultPath -DownloadDirectory $workingDirectory)[0]

$fastOpen = $openReleasedDrawingsFast -and $file._ReleasedRevision
$downloadedFiles = Save-VaultFile -File $file._FullPath -ExcludeChildren:$fastOpen -ExcludeLibraryContents:$fastOpen
$file = $downloadedFiles | select -First 1
# InventorServer does not support all target & source formats, you can find all supportet formats here:
# https://doc.coolorange.com/projects/powerjobsprocessor/en/stable/jobprocessor/file_conversion/?highlight=InventorServer#supported-format-conversions"
$openResult = Open-Document -LocalFile $file.LocalPath -Options @{ "Project" = $localIpjFile.LocalPath; FastOpen = $fastOpen } -Application InventorServer
$openResult = Open-Document -LocalFile $file.LocalPath -Options @{ "Project" = $localIpjFile.LocalPath; FastOpen = $fastOpen } #-Application InventorServer

$localPDFfileLocation = "$workingDirectory\$($file._Name).pdf"
$vaultPDFfileLocation = $file._EntityPath + "/" + (Split-Path -Leaf $localPDFfileLocation)

if ($openResult) {
if ($openResult.Application.Name -like 'Inventor*') {
Expand All @@ -66,25 +64,22 @@ if ($openResult) {
if ($exportResult) {
$PDFfile = Add-VaultFile -From $localPDFfileLocation -To $vaultPDFfileLocation -FileClassification DesignVisualization -Hidden $hidePDF
$file = Update-VaultFile -File $file._FullPath -AddAttachments @($PDFfile._FullPath)

if ($Job.ItemNumber) {
# Make sure you have permissions to modify released items before you use this Job for items with lifecycle change
Update-VaultItem -Number $Job.ItemNumber -AddAttachments @($PDFfile._FullPath)
}

Log -Message "Uploading PDF file $($PDFfile._Name) to ERP system..."
$d = New-ERPObject -EntityType "Document"
$d.FileName = $PDFfile._Name
$d.Number = $file._PartNumber
$d.Description = $file._Description
$d.Description = $file._Description
$uploadPDFToErpResult = Add-ERPMedia -EntitySet "Documents" -Properties $d -ContentType "application/pdf" -File $localPDFfileLocation
}
$closeResult = Close-Document
}

Get-ChildItem -LiteralPath $workingDirectory -Recurse -File -ErrorAction SilentlyContinue `
| Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $workingDirectory -Recurse -Force -ErrorAction SilentlyContinue

Get-ChildItem -LiteralPath $localWorkspaceFolder -Recurse -File `
| Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $localWorkspaceFolder -Recurse -Force -ErrorAction SilentlyContinue

if (-not $openResult) {
throw("Failed to open document $($file.LocalPath)! Reason: $($openResult.Error.Message)")
}
Expand Down
4 changes: 4 additions & 0 deletions wiki/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<img src="https://user-images.githubusercontent.com/36075173/47220092-12a0cb80-d3b1-11e8-85e2-0f2b17470517.png" align="middle" />
</p>


## [Download newest Release](https://github.com/coolOrangeProjects/{REPO_NAME}/releases)


# Legal + Github Manual

- [Github Quickstart Guide.pdf](https://github.com/coolOrangeLabs/powerGateTemplate/files/5964515/Github.Quickstart.Guide.pdf)
Expand Down

0 comments on commit 4a12ef9

Please sign in to comment.