Пример #1
0
        private ExportUnit GetExportUnit()
        {
            ExportUnit exportUnit = ExportUnit.Default;

            try
            {
                Units           units         = m_doc.GetUnits();
                FormatOptions   formatOptions = units.GetFormatOptions(UnitType.UT_Length);
                DisplayUnitType dut           = formatOptions.DisplayUnits;

                switch (dut)
                {
                case DisplayUnitType.DUT_METERS:
                    exportUnit = ExportUnit.Meter;
                    break;

                case DisplayUnitType.DUT_CENTIMETERS:
                    exportUnit = ExportUnit.Centimeter;
                    break;

                case DisplayUnitType.DUT_DECIMAL_FEET:
                    exportUnit = ExportUnit.Foot;
                    break;

                case DisplayUnitType.DUT_DECIMAL_INCHES:
                    exportUnit = ExportUnit.Inch;
                    break;

                case DisplayUnitType.DUT_FEET_FRACTIONAL_INCHES:
                    exportUnit = ExportUnit.Foot;
                    break;

                case DisplayUnitType.DUT_FRACTIONAL_INCHES:
                    exportUnit = ExportUnit.Inch;
                    break;

                case DisplayUnitType.DUT_METERS_CENTIMETERS:
                    exportUnit = ExportUnit.Meter;
                    break;

                case DisplayUnitType.DUT_MILLIMETERS:
                    exportUnit = ExportUnit.Millimeter;
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get export units.\n" + ex.Message, "Get Export Unit", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(exportUnit);
        }
Пример #2
0
        public bool ExportToDWG()
        {
            bool result = false;

            try
            {
                string inputFolder = GetInputDirectory();
                string fileName    = Path.GetFileNameWithoutExtension(filePath);
                bool   exported    = false;

                if (Directory.Exists(inputFolder))
                {
                    DWGExportOptions options = new DWGExportOptions();
                    options.ExportOfSolids = SolidGeometry.ACIS;
                    exportUnit             = GetExportUnit();
                    options.TargetUnit     = exportUnit;

                    ICollection <ElementId> views = new List <ElementId>();
                    views.Add(selectedView);

                    Guid transId = new Guid();
                    using (Transaction trans = new Transaction(m_doc))
                    {
                        try
                        {
                            transId = Guid.NewGuid();
                            trans.Start(transId.ToString());
                            exported = m_doc.Export(inputFolder, fileName, views, options);
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            trans.RollBack();
                            MessageBox.Show("DWG Export was failed.\n" + ex.Message, "DWG Export", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }

                string dwgFileName = Path.Combine(inputFolder, fileName + ".dwg");
                if (exported && File.Exists(dwgFileName))
                {
                    string unitString = "F";
                    switch (exportUnit)
                    {
                    case ExportUnit.Default:
                        unitString = "F";
                        break;

                    case ExportUnit.Inch:
                        unitString = "I";
                        break;

                    case ExportUnit.Foot:
                        unitString = "F";
                        break;

                    case ExportUnit.Millimeter:
                        unitString = "M";
                        break;

                    case ExportUnit.Centimeter:
                        unitString = "C";
                        break;

                    case ExportUnit.Meter:
                        unitString = "e";
                        break;
                    }

                    if (InitializeRhino())
                    {
                        string script = string.Format("-DivaDocumentUnits {0} {1}", unitString, unitString); //document units to foot
                        rhino.RunScript(script, false);

                        script = string.Format("-Import \"{0}\" Enter", dwgFileName); //model and layout unit to foot
                        rhino.RunScript(script, false);

                        rhinoFileName = dwgFileName.Replace(".dwg", ".3dm");
                        if (File.Exists(rhinoFileName))
                        {
                            File.Delete(rhinoFileName);
                        }

                        script = string.Format("-SaveAs \"{0}\" Enter", rhinoFileName);
                        rhino.RunScript(script, false);

                        if (File.Exists(rhinoFileName))
                        {
                            result = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to export to dwg.\n" + ex.Message, "Export to DWG", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(result);
        }