示例#1
0
        public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            var           ap    = commandData.Application.Application;

            UIDocument uidoc = uiapp.ActiveUIDocument;

            if (uidoc == null)
            {
                MessageBox.Show("当前没有打开的Revit文档!");
                return(Result.Cancelled);
            }

            Document doc = uidoc.Document;

            if (uidoc.ActiveView as View3D == null)
            {
                MessageBox.Show("请在3D视图下使用此命令!");
                return(Result.Cancelled);
            }

            string filePath = Path.GetDirectoryName(doc.PathName);
            string fileName = Path.GetFileNameWithoutExtension(doc.PathName);

            FormSettings dlg = new FormSettings();

            dlg.ExportSetting.SystemSetting.ExportFilePath = filePath + "\\" + fileName + dlg.ExportSetting.SystemSetting.GetFileExtension();
            DialogResult dr = dlg.ShowDialog(new WindowHandle(Process.GetCurrentProcess().MainWindowHandle));

            if (dr != DialogResult.OK)
            {
                return(Result.Cancelled);
            }

            Exception ex;
            var       assertSet = uiapp.Application.get_Assets(AssetType.Appearance);

            if (Export(assertSet, uidoc.ActiveView as View3D, dlg.ExportSetting, out ex))
            {
                TaskDialog.Show("导出", "导出完成!");
                return(Result.Succeeded);
            }
            else
            {
                TaskDialog.Show("导出", "导出失败!");
                messages = ex.Message;
                return(Result.Failed);
            }
        }
        public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;

            if (uidoc == null)
            {
                MessageBox.Show("当前没有打开的Revit文档!");
                return(Result.Cancelled);
            }

            Document doc = uidoc.Document;

            if (!(uidoc.ActiveView is View3D))
            {
                MessageBox.Show("请在3D视图下使用此命令!");
                return(Result.Cancelled);
            }

            //var dicProfileData = GetProfileDictFromDocument(doc);

            Process process = Process.GetCurrentProcess();
            IntPtr  h       = process.MainWindowHandle;

            string filePath = System.IO.Path.GetDirectoryName(doc.PathName);
            string fileName = System.IO.Path.GetFileNameWithoutExtension(doc.PathName);

            FormSettings dlg = new FormSettings();

            dlg.ExportSetting.SystemSetting.ExportFilePath = filePath + "\\" + fileName + ".vdcl";
            DialogResult dr = dlg.ShowDialog(new WindowHandle(h));

            if (dr != DialogResult.OK)
            {
                return(Result.Cancelled);
            }

            ElementColorOverride colorOverride = new ElementColorOverride();

            if (!dlg.ExportSetting.SystemSetting.IsOriginMaterial)
            {
                colorOverride.ArrangeElemlentColor(doc, uidoc.ActiveView as View3D);
            }

            RevitEnvironmentSetting setting = new RevitEnvironmentSetting(doc);

            if (dlg.ExportSetting.SystemSetting.IsModifyUnit)
            {
                setting.ReadOriginUnitsAndSetNew();
            }

            ModelExportContext context = new ModelExportContext(doc);

            context.IsPackageEntityToBlock   = true;
            context.IsExportProperty         = dlg.ExportSetting.SystemSetting.IsExportProperty;
            context.ExtraMaterial            = colorOverride.GetMaterials();
            context.ExtraElementColorSetting = colorOverride.GetElementColorSetting();
            CustomExporter exporter = new CustomExporter(doc, context);

            exporter.IncludeFaces      = false;
            exporter.ShouldStopOnError = false;
            exporter.Export(doc.ActiveView as View3D);

            if (dlg.ExportSetting.SystemSetting.IsModifyUnit)
            {
                setting.RecoverOriginUnits();
            }

            ConvertEntity converter = new ConvertEntity();

            converter.OptimizeTriangle = dlg.ExportSetting.SystemSetting.IsOptimizeCylinderFace;
            converter.ExportSetting    = dlg.ExportSetting;
            converter.Materials        = context.Materials;
            converter.ModelBlock       = context.ModelSpaceBlock;
            converter.WndParent        = new WindowHandle(h);
            if (dlg.ExportSetting.SystemSetting.IsExportGrid)
            {
                converter.Grids = GetGridFromDocument(doc);
            }
            //converter.FamilySketchDictionary = dicProfileData;
            converter.InstanceLocationCurveDictionary = context.InstanceLocation;
            converter.BeginConvert(dlg.ExportSetting.SystemSetting.ExportFilePath);

            return(Result.Succeeded);
        }