diff --git a/Source/Revit.IFC.Export/Exporter/Exporter.cs b/Source/Revit.IFC.Export/Exporter/Exporter.cs index 770eee29..1d399b97 100644 --- a/Source/Revit.IFC.Export/Exporter/Exporter.cs +++ b/Source/Revit.IFC.Export/Exporter/Exporter.cs @@ -37,6 +37,9 @@ using Autodesk.Revit.DB.ExternalService; using Revit.IFC.Export.Properties; using System.Reflection; +using System.Runtime.InteropServices; +using System.Text; + using Autodesk.Revit.DB.Steel; namespace Revit.IFC.Export.Exporter @@ -96,6 +99,14 @@ private void OnApplicationInitialized(object sender, EventArgs eventArgs) /// public class Exporter : IExporterIFC { + [DllImport("kernel32.dll", CharSet = CharSet.Auto)] + private static extern int GetShortPathName( + [MarshalAs(UnmanagedType.LPTStr)] + string path, + [MarshalAs(UnmanagedType.LPTStr)] + StringBuilder shortPath, + int shortPathLength); + RevitStatusBar statusBar = null; // Used for debugging tool "WriteIFCExportedElements" @@ -983,6 +994,9 @@ private string LocateSchemaFile(string schemaFileName) #if IFC_OPENSOURCE // Find the alternate schema file from the open source install folder filePath = Path.Combine(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), schemaFileName); + // If the path contains accented characters, the schema loading will fail, so let's + // try to get the short path form of the specified path. + filePath = TryGetShortPathName(filePath); if (!File.Exists(filePath)) #endif { @@ -991,6 +1005,28 @@ private string LocateSchemaFile(string schemaFileName) return filePath; } + private static string TryGetShortPathName(string filePath) + { + try + { + var shortPathBuilder = new StringBuilder(255); + if (GetShortPathName(filePath, shortPathBuilder, shortPathBuilder.Capacity) != 0) + { + var shortPath = shortPathBuilder.ToString(); + if (!string.IsNullOrWhiteSpace(shortPath)) + { + return shortPath; + } + } + + return filePath; + } + catch (Exception) + { + return filePath; + } + } + /// /// Sets the lists of property sets to be exported. This can be overriden. ///