Browse Source

mxg:添加批量更新阿里云端底图的功能

mengxiangge 5 years ago
parent
commit
783b97bf4a

+ 12 - 0
MBI/Menu/MBITool.xml

@@ -222,6 +222,18 @@
       <MenuTab>MBITool_W</MenuTab>
       <Modules>MBITool</Modules>
     </Button>
+    <Button ButtonStyles="Stacked">
+      <ButtonName>SAGA.MBI.UpdateBaseMapCommand</ButtonName>
+      <ButtonText>批量导出底图</ButtonText>
+      <ImageName>1、打开楼层模型</ImageName>
+      <DllName>..\OutputDll\SAGA.MBI.exe</DllName>
+      <ClassName>SAGA.MBI.UpdateBaseMapCommand</ClassName>
+      <ToolTip>导出底图数据到选定文件夹</ToolTip>
+      <LongDescription>导出底图数据到选定文件夹</LongDescription>
+      <ToolTipImage></ToolTipImage>
+      <MenuTab>MBITool_W</MenuTab>
+      <Modules>MBITool</Modules>
+    </Button>
   </Panel>
  <Panel PanelName="功能扩展" GroupFlag="True" GroupImage="" RevitVer="R14,R15,R16,R17"  ButtonStyles="Large">   
     <Button ButtonStyles="Large">

+ 1 - 1
MBI/SAGA.MBI/Extend/DocExtend.cs

@@ -97,7 +97,7 @@ namespace SAGA.MBI.Tools
             }
             else
             {
-                result= doc.Close();
+                result= doc.Close(false);
             }
             return result;
         }

+ 25 - 0
MBI/SAGA.MBI/Interaction/MBIModelInfoUpload.cs

@@ -75,6 +75,31 @@ namespace SAGA.MBI.Interaction
             return flag;
         }
         /// <summary>
+        /// 获取压缩后的文件内容
+        /// </summary>
+        /// <returns></returns>
+        public static byte[] GetCompressedExportInfo(string sagaName)
+        {
+            bool flag = false;
+            var db = MbiElementManager.MBIDb;
+            string jsonStr = string.Empty;
+            if (db != null)
+            {
+                jsonStr = db.ToJsonString(sagaName);
+            }
+            //测试使用
+            //File.WriteAllText(@"c:\" + key, jsonStr);
+            byte[] result = null;
+            if (!string.IsNullOrEmpty(jsonStr))
+            {
+                var newBytes = Encoding.UTF8.GetBytes(jsonStr);
+                var gzipBytes = CompressUtil.GZipCompress(newBytes);
+                result = gzipBytes;
+            }
+
+            return result;
+        }
+        /// <summary>
         /// 批量获取导出信息
         /// </summary>
         /// <param name="contexts"></param>

+ 8 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -357,6 +357,10 @@
     <Compile Include="Test\CopyParameterValue.cs" />
     <Compile Include="Test\CopyWallLocalName.cs" />
     <Compile Include="Test\RenameSystemName.cs" />
+    <Compile Include="Test\ReuploadBaseMap.cs" />
+    <Compile Include="Test\WinSelectFileFloder.xaml.cs">
+      <DependentUpon>WinSelectFileFloder.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Test\WinRenameConfig.xaml.cs">
       <DependentUpon>WinRenameConfig.xaml</DependentUpon>
     </Compile>
@@ -792,6 +796,10 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Test\WinSelectFileFloder.xaml">
+      <Generator>MSBuild:Compile</Generator>
+      <SubType>Designer</SubType>
+    </Page>
     <Page Include="Test\WinRenameConfig.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>

+ 121 - 0
MBI/SAGA.MBI/Test/ReuploadBaseMap.cs

@@ -0,0 +1,121 @@
+/* ==============================================================================
+ * 功能描述:ReuploadBaseMap  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/9 20:19:06
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using SAGA.DotNetUtils.Extend;
+using SAGA.MBI.Calc;
+using SAGA.MBI.Interaction;
+using SAGA.MBI.RevitExport;
+using SAGA.MBI.Tools;
+using SAGA.MBI.WinView.Upload;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.MBI.Test
+{
+    /// <summary>
+    /// ReuploadBaseMap
+    /// </summary>
+    class ReuploadBaseMap
+    {
+        public static void Execute()
+        {
+            WinSelectFileFloder win = new WinSelectFileFloder();
+            if (win.ShowDialog() == true)
+            {
+                Operate(win.RevitDirs);
+            }
+        }
+        private static void Operate(string revitDir)
+        {
+            var list = GetRevitFiles(revitDir);
+            if (!list.Any()) return;
+            foreach (string fullPath in list)
+            {
+                OperateFloor(fullPath);
+            }
+        }
+
+        private static void OperateFloor(string fullPath)
+        {
+            Document doc = null;
+            try
+            {
+                var uiApp = ExternalDataWrapper.Current.UiApp;
+                ModelPath mpath=new FilePath(fullPath);
+                OpenOptions options=new OpenOptions();
+                options.AllowOpeningLocalByWrongUser = true;
+                doc = uiApp.Application.OpenDocumentFile(mpath,options);
+                MbiElementManager.ExecuteExport(doc);
+                
+                var floorId = GetFloorId(fullPath);
+
+                string sagaName = doc.GetUseView()?.Name;
+                var result=MBIModelInfoUpload.GetCompressedExportInfo(sagaName);
+
+                string key = $"{floorId}" + DateTime.Now.ToString("yyyyMMddHHmmss") + "bim.jsonz";//楼层对应信息文件key值
+                File.WriteAllBytes(Path.Combine(GetDirectory(fullPath),key),result);
+            }
+            catch (Exception e)
+            {
+                var dir = GetDirectory(fullPath);
+                string errorPath = Path.Combine(dir, "ErrorFiles");
+                if (!Directory.Exists(errorPath))
+                    Directory.CreateDirectory(errorPath);
+                File.Copy(fullPath,errorPath);
+                string errorLog = Path.Combine(errorPath, "errorLog.txt");
+                File.AppendAllText(errorLog,$"{DateTime.Now.TimeOfDay} | {fullPath} | {e.Message} | {e.StackTrace}");
+            }
+            finally
+            {
+                doc?.CloseDocSimple();
+            }
+        }
+
+        private static string GetFloorId(string fullPath)
+        {
+            var fileName = fullPath.GetFileName();
+            var strs = fileName.Split('_');
+            string floorId = fileName;
+            if (strs.Length == 3)
+                floorId = strs[2];
+            return floorId;
+        }
+
+        private static string GetDirectory(string fullPath)
+        {
+            FileInfo fileInfo = new FileInfo(fullPath);
+            var dir = fileInfo.DirectoryName;
+            return dir;
+        }
+        /// <summary>
+        /// 获取需要修改的Revit文件
+        /// </summary>
+        /// <param name="revitDir"></param>
+        /// <returns></returns>
+        private static List<string> GetRevitFiles(string revitDir)
+        {
+            DirectoryInfo directory = new DirectoryInfo(revitDir);
+            List<string> list = new List<string>();
+            try
+            {
+                list = directory.GetFiles("*.rvt").Where(t => !t.FullName.Is000File()).Select(t => t.FullName).ToList();
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+
+            }
+
+            return list;
+        }
+    }
+}

+ 4 - 10
MBI/SAGA.MBI/Test/WinRenameConfig.xaml

@@ -1,4 +1,4 @@
-<windows:WinBase x:Class="SAGA.MBI.Test.WinRenameConfig"
+<windows:WinBase x:Class="SAGA.MBI.Test.WinSelectFileFloder"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
@@ -6,7 +6,7 @@
              xmlns:local="clr-namespace:SAGA.MBI.Test"
         xmlns:wpf="clr-namespace:SAGA.DotNetUtils.WPF.UserControl;assembly=SAGA.DotNetUtils"
         xmlns:windows="clr-namespace:SAGA.RevitUtils.Windows;assembly=SAGA.RevitUtils"
-        mc:Ignorable="d" Title="系统重命名参数设置" WindowStartupLocation="CenterScreen"
+        mc:Ignorable="d" Title="选择文件夹" WindowStartupLocation="CenterScreen"
                   Height="200" Width="400">
     <Window.Resources>
         <Style  TargetType="TextBox">
@@ -30,19 +30,13 @@
     </Window.Resources>
     <Grid Margin="5">
         <Grid.RowDefinitions>
-            <RowDefinition Height="50"></RowDefinition>
+            <RowDefinition Height="20"></RowDefinition>
             <RowDefinition></RowDefinition>
             <RowDefinition Height="50"></RowDefinition>
         </Grid.RowDefinitions>
-        <Grid Grid.Row="0">
-            <StackPanel>
-                <Label Content="请选择重命名系统的参考表:"></Label>
-                <wpf:SelectFile_Hyperlink Height="25" Text="{Binding Path=ReferenceFilePath,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" IsDisplayFullPath="True"></wpf:SelectFile_Hyperlink>
-            </StackPanel>
-        </Grid>
         <Grid Grid.Row="1">
             <StackPanel>
-                <Label Content="请选择需要修改的Revit文件夹:"></Label>
+                <Label Content="请选择需要操作的文件夹:"></Label>
                 <wpf:SelectPath Height="25" Text="{Binding Path=RevitDirs,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" ButtonPosition="End"></wpf:SelectPath>
             </StackPanel>
         </Grid>

+ 2 - 27
MBI/SAGA.MBI/Test/WinRenameConfig.xaml.cs

@@ -1,19 +1,6 @@
 using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
 using System.ComponentModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 using Exception = System.Exception;
 
 namespace SAGA.MBI.Test
@@ -21,9 +8,9 @@ namespace SAGA.MBI.Test
     /// <summary>
     /// WinParameterDic.xaml 的交互逻辑
     /// </summary>
-    public partial class WinRenameConfig : INotifyPropertyChanged
+    public partial class WinSelectFileFloder : INotifyPropertyChanged
     {
-        public WinRenameConfig()
+        public WinSelectFileFloder()
         {
             InitializeComponent();
             this.DataContext = this;
@@ -32,18 +19,6 @@ namespace SAGA.MBI.Test
         #region Binding
         
 
-        private string m_ReferenceFilePath;
-
-        public string ReferenceFilePath
-        {
-            get { return m_ReferenceFilePath; }
-            set
-            {
-                m_ReferenceFilePath = value;
-                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ReferenceFilePath)));
-            }
-        }
-
         private string m_RevitDirs;
 
         public string RevitDirs

+ 56 - 0
MBI/SAGA.MBI/Test/WinSelectFileFloder.xaml

@@ -0,0 +1,56 @@
+<windows:WinBase x:Class="SAGA.MBI.Test.WinRenameConfig"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:SAGA.MBI.Test"
+        xmlns:wpf="clr-namespace:SAGA.DotNetUtils.WPF.UserControl;assembly=SAGA.DotNetUtils"
+        xmlns:windows="clr-namespace:SAGA.RevitUtils.Windows;assembly=SAGA.RevitUtils"
+        mc:Ignorable="d" Title="系统重命名参数设置" WindowStartupLocation="CenterScreen"
+                  Height="200" Width="400">
+    <Window.Resources>
+        <Style  TargetType="TextBox">
+            <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
+            <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
+            <Setter Property="Height" Value="24"></Setter>
+        </Style>
+        <Style TargetType="DataGridColumnHeader">
+            <Setter Property="Height" Value="25"></Setter>
+            <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
+            <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
+        </Style>
+        <Style x:Key="dgtextblock">
+            <Setter Property="TextBlock.Height" Value="25"></Setter>
+            <Setter Property="TextBlock.HorizontalAlignment" Value="Center"></Setter>
+        </Style>
+        <Style x:Key="dgtextbox">
+            <Setter Property="TextBox.Height" Value="25"></Setter>
+            <Setter Property="TextBox.HorizontalContentAlignment" Value="Center"></Setter>
+        </Style>
+    </Window.Resources>
+    <Grid Margin="5">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="50"></RowDefinition>
+            <RowDefinition></RowDefinition>
+            <RowDefinition Height="50"></RowDefinition>
+        </Grid.RowDefinitions>
+        <Grid Grid.Row="0">
+            <StackPanel>
+                <Label Content="请选择重命名系统的参考表:"></Label>
+                <wpf:SelectFile_Hyperlink Height="25" Text="{Binding Path=ReferenceFilePath,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" IsDisplayFullPath="True"></wpf:SelectFile_Hyperlink>
+            </StackPanel>
+        </Grid>
+        <Grid Grid.Row="1">
+            <StackPanel>
+                <Label Content="请选择需要修改的Revit文件夹:"></Label>
+                <wpf:SelectPath Height="25" Text="{Binding Path=RevitDirs,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" ButtonPosition="End"></wpf:SelectPath>
+            </StackPanel>
+        </Grid>
+
+        <WrapPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <Button Height="24" Width="100" Content="执行" Margin="10,0" IsDefault="True" Click="ButtonBase_OnClick"></Button>
+            <Button Height="24" Width="100" Content="取消" Margin="10,0" IsCancel="True"></Button>
+        </WrapPanel>
+    </Grid>
+</windows:WinBase>
+

+ 82 - 0
MBI/SAGA.MBI/Test/WinSelectFileFloder.xaml.cs

@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+using Exception = System.Exception;
+
+namespace SAGA.MBI.Test
+{
+    /// <summary>
+    /// WinParameterDic.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinRenameConfig : INotifyPropertyChanged
+    {
+        public WinRenameConfig()
+        {
+            InitializeComponent();
+            this.DataContext = this;
+        }
+
+        #region Binding
+        
+
+        private string m_ReferenceFilePath;
+
+        public string ReferenceFilePath
+        {
+            get { return m_ReferenceFilePath; }
+            set
+            {
+                m_ReferenceFilePath = value;
+                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ReferenceFilePath)));
+            }
+        }
+
+        private string m_RevitDirs;
+
+        public string RevitDirs
+        {
+            get { return m_RevitDirs; }
+            set
+            {
+                m_RevitDirs = value;
+                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(RevitDirs)));
+            }
+        }
+
+
+        #endregion
+
+
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
+        {
+            try
+            {
+
+            }
+            catch (Exception exception)
+            {
+                Console.WriteLine(exception);
+
+            }
+
+            this.DialogResult = true;
+        }
+
+        
+    }
+}

+ 25 - 5
MBI/SAGA.MBI/TestCommand.cs

@@ -143,7 +143,27 @@ namespace SAGA.MBI
         }
     }
     #endregion
-
+    /// <summary>
+    /// 批量导出底图
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class UpdateBaseMapCommand : ExternalCommand, IExternalCommandAvailability
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                ReuploadBaseMap.Execute();
+            }
+            catch (Exception e)
+            {
+                MessageShow.Show(e);
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+    }
     /// <summary>
     /// 上传当前楼层数据
     /// </summary>
@@ -170,11 +190,11 @@ namespace SAGA.MBI
                             break;
                         }
                     case System.Windows.Forms.DialogResult.No:
-                    {
-                        var doc = ExternalDataWrapper.Current.Doc;
+                        {
+                            var doc = ExternalDataWrapper.Current.Doc;
                             MbiElementManager.ExecuteExport(doc);
                             var floorId = ExternalDataWrapper.Current.Doc.PathName.GetFileName();
-                        string sagaName = doc.GetUseView()?.Name;
+                            string sagaName = doc.GetUseView()?.Name;
                             MBIModelInfoUpload.UploadMbiInfo(floorId, sagaName);
                             break;
                         }
@@ -532,7 +552,7 @@ namespace SAGA.MBI
                 }
             }
 
-           
+
             return Result.Succeeded;
             var result = System.Windows.Forms.DialogResult.No;//MessageShow.Question2("是修改整个项目(【是】整个项目;【否】当前打开模型)");
             switch (result)