Have anyone here tried doing automation using Navisworks API in Powershell? I have managed to successfully read Navisworks files, append, save and going through all the elements to check its parameters but even then, i have a vague idea how to properly access the .NET Methods and properties. Sometimes i can’t access the methods. Now what i am trying to achieve is automate a clash test using Powershell. Below code is what i have so far.
$NavisworksAPI_API = "C:Program FilesAutodeskNavisworks Manage 2021Autodesk.Navisworks.Api.dll"
$NavisworksAPI_DC = "C:Program FilesAutodeskNavisworks Manage 2021Autodesk.Navisworks.Controls.dll"
$NavisworksAPI_AUTO = "C:Program FilesAutodeskNavisworks Manage 2021Autodesk.Navisworks.Automation.dll"
#Initialize Navisworks API
function Initialize-NavisworksApi {
Add-Type -Path $NavisworksAPI_API
Add-Type -Path $NavisworksAPI_DC
Add-Type -Path $NavisworksAPI_AUTO
[Autodesk.Navisworks.Api.Controls.ApplicationControl]::Initialize()
}
#Clash Test function
function Navis-ClashTest
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[String]$Path
)
try{
$napiDC = [Autodesk.Navisworks.Api.Controls.DocumentControl]::new()
WriteConsole -Value ("Opening file {0}" -f (Split-Path $Path -Leaf)) -Timestamp
$open = $napiDC.Document.TryOpenFile($Path)
If(!($open)){
Throw "Error opening file: {0}" -f (Split-Path $Path -Leaf)
}
$DCClash = [Autodesk.Navisworks.Api.Clash]::ClashTest()
$napiDC.Document.Clear()
$napiDC.Dispose()
}
catch{
$ex = $_.Exception.Message
WriteConsole -Value $ex -Timestamp
}
}
I cannot seem to access the methods. In the docs it mentions this namespace Autodesk.Navisworks.Api.Class
but i have added Autodesk.Navisworks.Api.dll in one of my function. One of the methods is “ClashTest”.
I tried to access that one with this code $DCClash = [Autodesk.Navisworks.Api.Clash]::ClashTest()
. It has error “Unable to find type Autodesk.Navisworks.Api.Clash
This one also gives me error: $DCClash = [Autodesk.Navisworks.Api]::Clash.ClashTest()
The Navisworks doc is so confusing. Some part like reading a file is straightforward but not with the clash data. How do I access the .NET methods in Powershell?
Tal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.