public void BindUi(IXbimXplorerPluginMasterWindow mainWindow) { _xpWindow = mainWindow; SetBinding(SelectedItemProperty, new Binding("SelectedItem") { Source = mainWindow, Mode = BindingMode.TwoWay }); SetBinding(SelectionProperty, new Binding("Selection") { Source = mainWindow.DrawingControl, Mode = BindingMode.TwoWay }); SetBinding(ModelProperty, new Binding()); // whole datacontext binding, see http://stackoverflow.com/questions/8343928/how-can-i-create-a-binding-in-code-behind-that-doesnt-specify-a-path // versioning information // var assembly = Assembly.GetAssembly(typeof(Xbim.GLTF.Builder)); PluginVersion.Text = $"Assembly Version: {assembly.GetName().Version}"; if (_xpWindow == null) { return; } var location = _xpWindow.GetAssemblyLocation(assembly); var fvi = FileVersionInfo.GetVersionInfo(location); PluginVersion.Text += $"\r\nFile Version: {fvi.FileVersion}"; }
private void ConfigureFolder() { // defaults to current directory var dir = new DirectoryInfo("."); var openedModel = _parentWindow?.GetOpenedModelFileName(); // if we have a model then use its direcotry if (!string.IsNullOrEmpty(openedModel)) { var directoryName = new FileInfo(openedModel).DirectoryName; if (directoryName != null) { dir = new DirectoryInfo(directoryName); } } // main folder config TxtFolderName.Text = dir.FullName; // configure settings for exporter var ass = System.Reflection.Assembly.GetAssembly(GetType()); if (_parentWindow == null) { Log.Error("attempt to locate DiskLess assembly without a valid IXbimXplorerPluginMasterWindow."); return; } var assemblyFile = _parentWindow.GetAssemblyLocation(ass); var pluginDir = new FileInfo(assemblyFile).Directory; if (pluginDir == null) { Log.ErrorFormat("Failed to determine plugin folder under IXbimXplorerPluginMasterWindow."); return; } ConfigFile = new FileInfo(Path.Combine(pluginDir.FullName, "COBieAttributesCustom.config")); if (ConfigFile.Exists) { return; } AppendLog("Creating Config File"); CreateDefaultAppConfig(ConfigFile); ConfigFile.Refresh(); }
/// <summary> /// Performs the export /// </summary> /// <returns>True on success, false on error.</returns> private bool ExportCoBie() { if (!Directory.Exists(TxtFolderName.Text)) { try { Directory.CreateDirectory(TxtFolderName.Text); } catch (Exception) { MessageBox.Show("Error creating directory. Select a different location."); return(false); } } var fName = Model.FileName; if (string.IsNullOrEmpty(fName)) { fName = "Unnamed"; } var f = new FileInfo(Path.ChangeExtension(fName, ".xls")); var outputFile = Path.Combine(TxtFolderName.Text, f.Name); // configure settings for exporter var ass = System.Reflection.Assembly.GetAssembly(GetType()); if (_parentWindow == null) { Log.LogError("attempt to locate DiskLess assembly without a valid IXbimXplorerPluginMasterWindow."); return(false); } var assemblyFile = _parentWindow.GetAssemblyLocation(ass); var pluginDir = new FileInfo(assemblyFile).Directory; if (pluginDir == null) { Log.LogError("Failed to determine plugin folder under IXbimXplorerPluginMasterWindow."); return(false); } var templateFileName = Path.Combine( pluginDir.FullName, CoBieTemplate); var context = new COBieContext { TemplateFileName = templateFileName, Model = Model, Exclude = UserFilters }; // setting culture for thread; the current one will be restored later. CultureInfo exisitingCultureInfo = null; try { var ci = new CultureInfo("en-GB"); exisitingCultureInfo = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = ci; } catch (Exception ex) { Log.LogError(0, ex, "CurrentUICulture could not be set to en-GB."); } // actual export code var builder = new COBieBuilder(context); var serialiser = new COBieXLSSerialiser(outputFile, context.TemplateFileName) { Excludes = UserFilters }; builder.Export(serialiser); // restoring culture for thread; try { if (exisitingCultureInfo != null) { Thread.CurrentThread.CurrentUICulture = exisitingCultureInfo; } } catch (Exception ex) { Log.LogError(0, ex, "CurrentUICulture could not restored."); } if (ChkOpenExcel.IsChecked.HasValue && ChkOpenExcel.IsChecked.Value) { Process.Start(outputFile); } return(true); }