|
![]() |
Get file name to open to read contents of resolved reference. Same as ResolvedFileReference
if file is local. Null if not resolved or file is remote and has not been downloaded.
Namespace: Autodesk.Navisworks.Api
Assembly: Autodesk.Navisworks.Api (in Autodesk.Navisworks.Api.dll)
Syntax
Examples

using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows.Forms; using System.Text; using Autodesk.Navisworks.Api.Controls; public static void FileReferenceResolve() { try { //create a file resolver FileReferenceResolver resolve = new FileReferenceResolver(); //file resolution events Autodesk.Navisworks.Api.Application.FileResolving += Application_FileResolving; Autodesk.Navisworks.Api.Application.FileResolved += Application_FileResolved; Autodesk.Navisworks.Api.Application.FileInteractiveResolving += Application_FileInteractiveResolving; Autodesk.Navisworks.Api.Application.FileInteractiveResolved += Application_FileInteractiveResolved; //resolve a file reference, this will raise the //Application.FileResolving and Application.FileResolved events FileReferenceResolveResult result = resolve.Resolve(@"C:\helloworld"); //finally build the output StringBuilder output = new StringBuilder(); output.AppendLine("FileReferenceResolveResult:"); output.AppendLine("FileNameToOpen = " + result.FileNameToOpen); output.AppendLine("ResolvedFileReference = " + result.ResolvedFileReference); output.AppendLine("Response = " + result.Response); //show the result: MessageBox.Show(output.ToString()); } //catch (Exception e) { MessageBox.Show(e.Message + "\n" + e.ToString()); } finally { //no longer need events Autodesk.Navisworks.Api.Application.FileResolving -= Application_FileResolving; Autodesk.Navisworks.Api.Application.FileResolved -= Application_FileResolved; Autodesk.Navisworks.Api.Application.FileInteractiveResolving -= Application_FileInteractiveResolving; Autodesk.Navisworks.Api.Application.FileInteractiveResolved -= Application_FileInteractiveResolved; } } private static String GetEventArgInfo(FileResolutionEventArgs e) { StringBuilder output = new StringBuilder(); if (e != null) { //base class FileResolutionEventArgs output.AppendLine("FileResolutionEventArgs properties:"); output.AppendLine("e.FileReference = " + ((e.FileReference == null) ? "null" : e.FileReference.ToString())); output.AppendLine("e.FileReferenceType = " + e.FileReferenceType.ToString()); output.AppendLine("e.ReferringFileName = " + ((e.ReferringFileName == null) ? "null" : e.ReferringFileName.ToString())); output.AppendLine("e.ReferringFileNameAsSaved = " + ((e.ReferringFileNameAsSaved == null) ? "null" : e.ReferringFileNameAsSaved.ToString())); output.AppendLine("e.ResolveToOpen = " + e.ResolveToOpen.ToString()); if (e is FileResolvingEventArgs) { output.AppendLine(); output.AppendLine("FileResolvingEventArgs properties:"); output.AppendLine("e.FileNameToOpen = " + ((((FileResolvingEventArgs)e).FileNameToOpen == null) ? "null" : ((FileResolvingEventArgs)e).FileNameToOpen.ToString())); output.AppendLine("e.ResolvedFileReference = " + ((((FileResolvingEventArgs)e).ResolvedFileReference == null) ? "null" : ((FileResolvingEventArgs)e).ResolvedFileReference.ToString())); } else if (e is FileResolvedEventArgs) { output.AppendLine(); output.AppendLine("FileResolvedEventArgs properties:"); output.AppendLine("e.FileNameToOpen = " + ((((FileResolvedEventArgs)e).FileNameToOpen == null) ? "null" : ((FileResolvedEventArgs)e).FileNameToOpen.ToString())); output.AppendLine("e.ResolvedFileReference = " + ((((FileResolvedEventArgs)e).ResolvedFileReference == null) ? "null" : ((FileResolvedEventArgs)e).ResolvedFileReference.ToString())); output.AppendLine("e.ResolvedFileReferenceType = " + ((FileResolvedEventArgs)e).ResolvedFileReferenceType.ToString()); } else if (e is FileInteractiveResolvingEventArgs) { output.AppendLine(); output.AppendLine("FileInteractiveResolvingEventArgs properties:"); output.AppendLine("e.DisplayString = " + ((((FileInteractiveResolvingEventArgs)e).DisplayString == null) ? "null" : ((FileInteractiveResolvingEventArgs)e).DisplayString)); output.AppendLine("e.Handled = " + ((FileInteractiveResolvingEventArgs)e).Handled.ToString()); output.AppendLine("e.ResolvedFileReference = " + ((((FileInteractiveResolvingEventArgs)e).ResolvedFileReference == null) ? "null" : ((FileInteractiveResolvingEventArgs)e).ResolvedFileReference)); output.AppendLine("e.Response = " + ((FileInteractiveResolvingEventArgs)e).Response.ToString()); } else if (e is FileInteractiveResolvedEventArgs) { output.AppendLine(); output.AppendLine("FileInteractiveResolvedEventArgs properties:"); output.AppendLine("e.ResolvedFileReference = " + ((((FileInteractiveResolvedEventArgs)e).ResolvedFileReference == null) ? "null" : ((FileInteractiveResolvedEventArgs)e).ResolvedFileReference)); output.AppendLine("e.Response = " + ((FileInteractiveResolvedEventArgs)e).Response.ToString()); } } return output.ToString(); } static void Application_FileResolving(object sender, FileResolvingEventArgs e) { string output = GetEventArgInfo(e); //output to screen MessageBox.Show(output, "Application.FileResolving"); //Browse for file OpenFileDialog fileToResolveTo = new OpenFileDialog(); fileToResolveTo.Title = "Application.FileResolving - Browse For File"; //Ask user if resolve information is ok? if (fileToResolveTo.ShowDialog() == DialogResult.OK) { //set the required properties e.FileNameToOpen = fileToResolveTo.FileName; e.ResolvedFileReference = fileToResolveTo.FileName; //latest value for output output = "Are these values acceptable?\n\n" + GetEventArgInfo(e); if (MessageBox.Show(output, "Application.FileResolving", MessageBoxButtons.YesNo) == DialogResult.Yes) { //mark as handled, so that Application.FileInteractiveResolving and //Application_FileInteractiveResolved are not sent e.Handled = true; } } } static void Application_FileResolved(object sender, FileResolvedEventArgs e) { string output = GetEventArgInfo(e); MessageBox.Show(output.ToString(), "Application.FileResolved"); } static void Application_FileInteractiveResolving(object sender, FileInteractiveResolvingEventArgs e) { //mark as handled, so that Application.FileInteractiveResolving and //Application_FileInteractiveResolved are not handled in the default manner by the GUI. e.Handled = true; string output = GetEventArgInfo(e); //output to screen MessageBox.Show(output, "Application.FileResolving"); //Browse for file OpenFileDialog fileToResolveTo = new OpenFileDialog(); fileToResolveTo.Title = "Application.FileResolving - Browse For File - " + e.DisplayString.ToString(); //Ask user if resolve information is ok? if (fileToResolveTo.ShowDialog() == DialogResult.OK) { //set the required properties e.Response = FileResolutionResponse.OK; e.ResolvedFileReference = fileToResolveTo.FileName; //latest value for output output = "Are these values acceptable?\n\n" + GetEventArgInfo(e); MessageBox.Show(output, "Application.FileResolving"); } } static void Application_FileInteractiveResolved(object sender, FileInteractiveResolvedEventArgs e) { string output = GetEventArgInfo(e); MessageBox.Show(output.ToString(), "Application.FileInteractiveResolved"); }