管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-03-16 7e6bc3b86674ec026b3c5c3f25574116a3ecaa28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using ExportMap.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
 
namespace ExportMap.cs
{
    /// <summary>
    /// 模型转换工具
    /// </summary>
    public class ConvertUtils
    {
        /// <summary>
        /// 工作配置
        /// </summary>
        public static string JobConfig = "{{ \"format\": \"3dtiles\", \"mode\": 0, \"outputPath\": \"{0}\", \"outputOptions\": null, \"levelOfDetail\": -1, \"levelOfDetailText\": \"Auto\", \"georeferenced\": null }}";
 
        /// <summary>
        /// Roamer.exe
        /// </summary>
        public static string RoamerExe = "\"C:\\Program Files\\Autodesk\\Navisworks Manage 2020\\Roamer.exe\"";
 
        /// <summary>
        /// 模型转换
        /// </summary>
        public static int Convert(List<int> ids)
        {
            int count = 0;
            string uploadFolder = Tool.GetSetting("uploadFolder");
            string tilesFolder = Path.Combine(Tool.GetSetting("lfData"), "3d\\3dtiles");
 
            List<SysMeta> list = XYZUtils.selectMetas(ids, "and type in ('ifc', 'fbx', 'rvt')");
            if (null == list || list.Count == 0) return 0;
 
            foreach (SysMeta meta in list)
            {
                string modelFile = Path.Combine(uploadFolder, meta.path);
                if (!File.Exists(modelFile)) continue;
 
                string configFile = Path.Combine(Tool.TempDir, ExportUtil.DateStr + ".json");
                string outPath = Path.Combine(tilesFolder, meta.type, meta.id.ToString());
                string jsonFile = Path.Combine(outPath, "tileset.json");
 
                if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
                if (File.Exists(jsonFile)) File.Delete(jsonFile);
 
                WriteText(configFile, string.Format(JobConfig, outPath.Replace("\\", "\\\\")));
                ExecNavisworks(modelFile, configFile);
 
                File.Delete(configFile);
                count += File.Exists(jsonFile) ? 1 : 0;
            }
 
            return count;
        }
 
        /// <summary>
        /// 运行Navisworks
        /// </summary>
        public static void ExecNavisworks(string modelFile, string configFile)
        {
            Process p = null;
            try
            {
                string args = string.Format("-licensing AdLM -OpenFile \"{0}\" -ExecuteAddInPlugin \"EngineBatch_Sample.SmartEarth\" \"{1}\" -NoGui -Exit", modelFile, configFile); // -log D:\\xyz\\auto\\log.txt
                LogOut.Info("Args:" + args);
 
                // 启动进程
                p = Process.Start(RoamerExe, args);
 
                // 让组件等候相关的进程进入闲置状态
                p.WaitForInputIdle();
 
                // 让组件无限期地等待关联进程退出
                p.WaitForExit();
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.StackTrace);
            }
            finally
            {
                if (p != null)
                {
                    p.Close();
                    p.Dispose();
                    p = null;
                }
            }
        }
 
        /// <summary>
        /// 写文本文件
        /// </summary>
        private static void WriteText(string file, string str)
        {
            File.WriteAllText(file, str);
            LogOut.Info("JobConfig:" + str);
        }
    }
}