powershell get Content - Autodesk Navisworks

225 views Asked by At

HI im trying to get the content of an Autodesk Navisworks (NWD) file.

here is a simple version of what im trying todo -

$fileCont = Get-Content -Path $filePath
New-Item C:\Temp\tom2.nwd
Set-Content C:\Temp\tom2.nwd $fileCont

For this to prove that I can successfully collect the content of the navisworks file..

although this is a simple workflow and what i'm trying to achieve is greater thank this, if i can figure this bit out i know the rest..

here is the error when i try to open C:\Temp\tom2.nwd

Navisworks Error message when opening file

2

There are 2 answers

0
TD123123123 On BEST ANSWER

you're correct this method did work but was extremely slow and un usable, but i can now confirm that by following this post

i used the following method to collect and post the data in the file.

  write-host "Creting object in bucket.."

$B_Key = ''
write-host "Bucket Key ="$B_Key

write-host "File Content being uploaded to bucket object"

$currentDir = Get-Location
$sourceFile = [System.IO.Path]::Combine($currentDir, 'rac_basic_sample_project_pstest.rvt')
$fileName = [System.IO.Path]::GetFileName($SourceFile)
Set-ItemProperty -Path $sourceFile -Name IsReadOnly -Value $false

$Clen = Get-Item $sourceFile
$Clen = $Clen.Length
write-host $Clen

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
            $headers.Add("Authorization", "Bearer $token")
            $headers.Add("Content-Type", "application/octet-stream")
            $headers.Add("Content-Length", $CLen)

$CreateObj = 'https://developer.api.autodesk.com/oss/v2/buckets/'+$B_Key+'/objects/'+$fileName 
$CreateObjAPIresult = Invoke-RestMethod -Uri $CreateObj -Method Put   -Headers $headers -InFile $sourceFile

write-host "New Object Created in bucket"
0
mklement0 On

By default, both Get-Content and Set-Content operate only on text.

To handle raw byte data - which is needed to handled the content of a binary file format such as .nwd - you need to use:

  • in Windows PowerShell: -Encoding Byte
  • in PowerShell [Core] v6+: -AsByteStream

Note: If all bytes fit into memory at once, you can greatly speed up a Get-Content call by adding -Raw.