コード例 #1
0
        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);
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        /// <summary>
        /// Save active Revit document as STL file according to customer's settings.
        /// </summary>
        /// <param name="fileName">The name of the STL file to be saved.</param>
        /// <param name="settings">Settings for save operation.</param>
        /// <returns>Successful or failed.</returns>      
        public GeneratorStatus SaveSTLFile(string fileName, Settings settings)
        {
            m_Settings = settings;

            try
            {

                m_StlExportCancel.Show();

                // save data in certain STL file
                if (SaveFormat.Binary == settings.SaveFormat)
                {
                    m_Writer = new SaveDataAsBinary(fileName, settings.SaveFormat);
                }
                else
                {
                    m_Writer = new SaveDataAsAscII(fileName, settings.SaveFormat);
                }

                m_Writer.CreateFile();
                ScanElement(settings.ExportRange);

                System.Windows.Forms.Application.DoEvents();

                if (m_StlExportCancel.CancelProcess == true)
                {
                    m_StlExportCancel.Close();
                    return GeneratorStatus.CANCEL;
                }

                if (0 == m_TriangularNumber)
                {
                    MessageBox.Show(STLExportResource.ERR_NOSOLID, STLExportResource.MESSAGE_BOX_TITLE,
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                    m_StlExportCancel.Close();
                    return GeneratorStatus.FAILURE;
                }

                if (SaveFormat.Binary == settings.SaveFormat)
                {
                    // add triangular number to STL file
                    m_Writer.TriangularNumber = m_TriangularNumber;
                    m_Writer.AddTriangularNumberSection();
                }
                m_Writer.CloseFile();
            }
            catch (SecurityException)
            {
                MessageBox.Show(STLExportResource.ERR_SECURITY_EXCEPTION, STLExportResource.MESSAGE_BOX_TITLE,
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                m_StlExportCancel.Close();
                return GeneratorStatus.FAILURE;
            }
            catch (Exception)
            {
                MessageBox.Show(STLExportResource.ERR_EXCEPTION, STLExportResource.MESSAGE_BOX_TITLE,
                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                m_StlExportCancel.Close();
                return GeneratorStatus.FAILURE;
            }

            m_StlExportCancel.Close();
            return GeneratorStatus.SUCCESS;
        }