Skip to content

Commit

Permalink
added support for NWD templates
Browse files Browse the repository at this point in the history
  • Loading branch information
koechlm committed Nov 19, 2024
1 parent ee95d8b commit 93e97de
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
73 changes: 63 additions & 10 deletions Autodesk.VLTINVSRV.ExportSampleJob/JobExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,10 +767,10 @@ private void mCreateExport(IJobProcessorServices context, IJob job)
if ((item == "NWD" || item == "NWD+DWF") && mNavisworksAutomation != null)
{
//delete existing export files; note the resulting file name is e.g. "Assembly.iam.nwd
string mNWDName = mDocPath + ".nwd";
if (System.IO.File.Exists(mNWDName))
string mNwdName = mDocPath + ".nwd";
if (System.IO.File.Exists(mNwdName))
{
System.IO.FileInfo fileInfo = new FileInfo(mNWDName);
System.IO.FileInfo fileInfo = new FileInfo(mNwdName);
fileInfo.IsReadOnly = false;
fileInfo.Delete();
}
Expand All @@ -792,11 +792,36 @@ private void mCreateExport(IJobProcessorServices context, IJob job)
{
//disable navisworks progress bar whilst we do this procedure
//Navisworks.DisableProgress();
//open the file with navisworks; opening other file formats creates a new navisworks file appending the import file
mNavisworksAutomation.OpenFile(mDocPath);

// check if a NWD template is enabled.
if (string.IsNullOrEmpty(mSettings.NwdTemplate))
{
//open the file with navisworks; opening other file formats creates a new navisworks file appending the import file
mNavisworksAutomation.OpenFile(mDocPath);
}
else
{
// download the template file
ACW.File mNwdTemplateFile = mWsMgr.DocumentService.FindLatestFilesByPaths(new string[] { mSettings.NwdTemplate }).FirstOrDefault();
if (mNwdTemplateFile != null)
{
string mNwdTemplate = mDownloadFile(connection, mNwdTemplateFile);

//open the template file with Navisworks
mNavisworksAutomation.OpenFile(mNwdTemplate);

//append the source file to the template file
mNavisworksAutomation.AppendFile(mDocPath);
}
else
{
throw new Exception("Job stopped execution as the file " + settings.NwdTemplate + " was not found in the vault.");
}

}

//save the new navisworks
mNavisworksAutomation.SaveFile(mNWDName);
mNavisworksAutomation.SaveFile(mNwdName);

//export DWF
if (item == "NWD+DWF")
Expand All @@ -806,17 +831,17 @@ private void mCreateExport(IJobProcessorServices context, IJob job)
//Navisworks.EnableProgress();

//collect all export files for later upload
System.IO.FileInfo mExportFileInfo = new System.IO.FileInfo(mNWDName);
System.IO.FileInfo mExportFileInfo = new System.IO.FileInfo(mNwdName);
if (mExportFileInfo.Exists)
{
mUploadFiles.Add(mNWDName);
mUploadFiles.Add(mNwdName);
mTrace.WriteLine("Navisworks created file: " + mUploadFiles.LastOrDefault());
mTrace.IndentLevel -= 1;
}
else
{
mResetIpj(mSaveProject);
throw new Exception("Validating the export file " + mNWDName + " before upload failed.");
throw new Exception("Validating the export file " + mNwdName + " before upload failed.");
}
if (item == "NWD+DWF")
{
Expand Down Expand Up @@ -1104,7 +1129,7 @@ private void mCreateExport(IJobProcessorServices context, IJob job)
mExplUtil.UpdateFileProperties(mExpFile, mPropDictonary);
mExpFile = (mWsMgr.DocumentService.GetLatestFileByMasterId(mExpFile.MasterId));
}
}
}

catch (Exception ex)
{
Expand Down Expand Up @@ -1229,6 +1254,34 @@ private void mSldworksDispose()
}
}

private string mDownloadFile(Connection connection, ACW.File mFile)
{
//download the source file iteration, enforcing overwrite if local files exist
VDF.Vault.Settings.AcquireFilesSettings mDownloadSettings = new VDF.Vault.Settings.AcquireFilesSettings(connection);
VDF.Vault.Currency.Entities.FileIteration mFileIteration = new VDF.Vault.Currency.Entities.FileIteration(connection, mFile);
mDownloadSettings.AddFileToAcquire(mFileIteration, VDF.Vault.Settings.AcquireFilesSettings.AcquisitionOption.Download);
mDownloadSettings.OrganizeFilesRelativeToCommonVaultRoot = true;
mDownloadSettings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeChildren = true;
mDownloadSettings.OptionsRelationshipGathering.FileRelationshipSettings.RecurseChildren = true;
mDownloadSettings.OptionsRelationshipGathering.FileRelationshipSettings.IncludeLibraryContents = true;
mDownloadSettings.OptionsRelationshipGathering.FileRelationshipSettings.ReleaseBiased = true;
VDF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions mResOpt = new VDF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions();
mResOpt.OverwriteOption = VDF.Vault.Settings.AcquireFilesSettings.AcquireFileResolutionOptions.OverwriteOptions.ForceOverwriteAll;
mResOpt.SyncWithRemoteSiteSetting = VDF.Vault.Settings.AcquireFilesSettings.SyncWithRemoteSite.Always;

//execute download
VDF.Vault.Results.AcquireFilesResults mDownLoadResult = connection.FileManager.AcquireFiles(mDownloadSettings);
//pickup result details
VDF.Vault.Results.FileAcquisitionResult fileAcquisitionResult = mDownLoadResult.FileResults.Where(n => n.File.EntityName == mFileIteration.EntityName).FirstOrDefault();

if (fileAcquisitionResult == null)
{
throw new Exception("Job stopped execution as the file " + mFile.Name + " did not download.");
}
string mDocPath = fileAcquisitionResult.LocalPath.FullPath;
return mDocPath;
}

#endregion Job Execution
}
}
3 changes: 3 additions & 0 deletions Autodesk.VLTINVSRV.ExportSampleJob/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class Settings
[XmlElement("ImgFileType")]
public string ImgFileType;

[XmlElement("NwdTemplate")]
public string NwdTemplate;

private Settings()
{

Expand Down
5 changes: 5 additions & 0 deletions Autodesk.VLTINVSRV.ExportSampleJob/Settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<!-- Multiple Outputs per jobs are supported, list all required formats comma separated, e.g., STP, JT, SMDXF -->
<!-- To Export Sheet Metal Flatpattern SMDXF - NOTE: distinct category for sheet metal part required, if job handles parts and SM-parts-->
<ExportFormats>NWD+DWF,SLDDRW.PDF</ExportFormats>

<!-- NWD Template Options: store a Vault path of a NWD file as template, e.g. $/Templates/Navisworks/Standard-Vertical-Z.nwd-->
<!-- Note - Using a template will add another reference to the resulting file.-->
<!-- Leave the template blank, if the Navisworks default template should be consumed.-->
<NwdTemplate>$\Templates\Navisworks\Standard-Vertical-Z.nwd</NwdTemplate>

<!--Sheet Metal Category Name-->
<SmCatDispName>Sheet Metal Part</SmCatDispName>
Expand Down

0 comments on commit 93e97de

Please sign in to comment.