Beispiel #1
0
        public bool Export(AssetSet appearanceAssetSet, View3D view, ExportSetting setting, out Exception ex)
        {
            ex = new Exception();

            try
            {
                ConvertEntity converter = new ConvertEntity();
                converter.ExportSetting = setting;
                if (setting.SystemSetting.IsExportRebar)
                {
                    converter.Rebars = Tools.GetRebaresInDocument(view.Document);
                }
                else
                {
                    ElementColorOverride colorOverride = new ElementColorOverride();
                    if (!setting.SystemSetting.IsOriginMaterial && !view.Document.IsFamilyDocument)
                    {
                        colorOverride.ArrangeElemlentColor(view.Document, view);
                    }

                    RevitEnvironmentSetting envSetting = new RevitEnvironmentSetting(view.Document);
                    if (setting.SystemSetting.IsModifyUnit)
                    {
                        envSetting.ReadOriginUnitsAndSetNew();
                    }

                    ModelExportContext context = new ModelExportContext(view.Document);
                    context.ExportSetting = setting;
                    context.BuiltInMaterialLibraryAsset = appearanceAssetSet;
                    context.IsPackageEntityToBlock      = true;
                    context.ExtraMaterial            = colorOverride.GetMaterials();
                    context.ExtraElementColorSetting = colorOverride.GetElementColorSetting();
                    context.IsOptimisePipeEntity     = true;
                    CustomExporter exporter = new CustomExporter(view.Document, context);

                    //exporter.IncludeFaces = false;

                    exporter.ShouldStopOnError = false;
                    exporter.Export(view);

                    if (setting.SystemSetting.IsModifyUnit)
                    {
                        envSetting.RecoverOriginUnits();
                    }

                    converter.Materials  = context.Materials;
                    converter.ModelBlock = context.ModelSpaceBlock;
                    converter.DictBlocks = context.DictBlocks;
                    converter.Levels     = Tools.GetLevelsFromDocument(view.Document);
                    if (setting.SystemSetting.IsExportGrid)
                    {
                        converter.Grids = Tools.GetGridFromDocument(view.Document);
                    }
                }

                converter.WndParent = new WindowHandle(Process.GetCurrentProcess().MainWindowHandle);
                converter.BeginConvert();
            }
            catch (Exception e)
            {
                ex = e;
                return(false);
            }

            return(true);
        }
        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);
        }