/// <summary> /// Implement the member of IExternalCommand Execute. /// </summary> /// <param name="commandData"> /// The application object for the active instance of Autodesk Revit. /// </param> /// <param name="message"> /// A message that can be set by the external command and displayed in case of error. /// </param> /// <param name="elements"> /// A set of elements that can be displayed if an error occurs. /// </param> /// <returns> /// A value that signifies if yout command was successful, failed or the user wishes to cancel. /// </returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //for repeating click-events m_Revit = commandData.Application; BIM.OpenFOAMExport.Exporter.Instance.settings.setDocument(m_Revit); string fileName = "wallSTL.stl"; // save Revit document's triangular data in a temporary file, generate openFOAM-casefolder and start simulation Directory.CreateDirectory(BIM.OpenFOAMExport.Exporter.Instance.settings.localCaseFolder); Directory.CreateDirectory(BIM.OpenFOAMExport.Exporter.Instance.settings.localCaseFolder + "\\constant"); Directory.CreateDirectory(BIM.OpenFOAMExport.Exporter.Instance.settings.localCaseFolder + "\\constant\\triSurface"); DataGenerator Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document); DataGenerator.GeneratorStatus succeed = Generator.SaveSTLFile(fileName); if (succeed == DataGenerator.GeneratorStatus.SUCCESS) { BIM.OpenFOAMExport.Exporter.Instance.settings.initConfigs(); succeed = Generator.CreateOpenFOAMCase(BIM.OpenFOAMExport.Exporter.Instance.settings.localCaseFolder); } return(Result.Succeeded); }
public void fuckFace(Autodesk.Revit.UI.UIApplication revit) { m_Revit = revit; // Create data generator m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView); FolderBrowserDialog folderDialog = new FolderBrowserDialog(); // Set file name of exported stl string fileName; if (folderDialog.ShowDialog() == DialogResult.OK) { fileName = folderDialog.SelectedPath + "\\buildingPrint.stl"; } else { return; } // Set binary save format SaveFormat saveFormat = SaveFormat.Binary; // Set export range ElementsExportRange exportRange = ElementsExportRange.OnlyVisibleOnes; // Include linked cbIncludeLinked = true; // Export in color cbExportColor = false; // Export in shared coordinates cbExportSharedCoordinates = false; // Set dup to 2 for millimeters dup = DisplayUnitType.DUT_MILLIMETERS; // scan for categories and add each of them to selectedCategories m_CategoryList = m_Generator.ScanCategories(true); List <Category> selectedCategories = m_CategoryList.Values.ToList(); // create settings object to save setting information BIM.STLExport.Settings aSetting = new BIM.STLExport.Settings(saveFormat, exportRange, cbIncludeLinked, cbExportColor, cbExportSharedCoordinates, selectedCategories, dup); // save Revit document's triangular data in a temporary file m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView); // Save STL file DataGenerator.GeneratorStatus succeed = m_Generator.SaveSTLFile(fileName, aSetting); }
/// <summary> /// Save button click event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event args.</param> private void btnSave_Click(object sender, EventArgs e) { string fileName = STLDialogManager.SaveDialog(); if (!string.IsNullOrEmpty(fileName)) { SaveFormat saveFormat; if (rbBinary.Checked) { saveFormat = SaveFormat.Binary; } else { saveFormat = SaveFormat.ASCII; } ElementsExportRange exportRange; exportRange = ElementsExportRange.OnlyVisibleOnes; // get selected categories from the category list List <Category> selectedCategories = new List <Category>(); // only for projects if (m_Revit.ActiveUIDocument.Document.IsFamilyDocument == false) { foreach (TreeNode treeNode in tvCategories.Nodes) { AddSelectedTreeNode(treeNode, selectedCategories); } } DisplayUnitType dup = m_DisplayUnits[comboBox_DUT.Text]; m_SelectedDUT = dup; // create settings object to save setting information Settings aSetting = new Settings(saveFormat, exportRange, cbIncludeLinked.Checked, cbExportColor.Checked, cbExportSharedCoordinates.Checked, selectedCategories, dup); // save Revit document's triangular data in a temporary file m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView); DataGenerator.GeneratorStatus succeed = m_Generator.SaveSTLFile(fileName, aSetting); if (succeed == DataGenerator.GeneratorStatus.FAILURE) { this.DialogResult = DialogResult.Cancel; MessageBox.Show(STLExportResource.ERR_SAVE_FILE_FAILED, STLExportResource.MESSAGE_BOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (succeed == DataGenerator.GeneratorStatus.CANCEL) { this.DialogResult = DialogResult.Cancel; MessageBox.Show(STLExportResource.CANCEL_FILE_NOT_SAVED, STLExportResource.MESSAGE_BOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } this.DialogResult = DialogResult.OK; this.Close(); } else { MessageBox.Show(STLExportResource.CANCEL_FILE_NOT_SAVED, STLExportResource.MESSAGE_BOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }