管道基础大数据平台系统开发-【CS】-ExportMap
1
13693261870
2023-03-14 4e2e497696cc0e7866bab056cd056d509b7d6c6c
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
using ExportMap.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
 
namespace ExportMap.cs
{
    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, "type in ('ifc', 'fbx', 'rvt')");
            foreach (SysMeta meta in list)
            {
                try
                {
                    string modelFile = Path.Combine(uploadFolder, meta.path);
                    if (!File.Exists(modelFile))
                    {
                        continue;
                    }
 
                    string configFile = Path.Combine(Tool.BaseDir, ExportUtil.DateStr + ".json");
                    string outPath = Path.Combine(tilesFolder, meta.type, meta.id.ToString());
 
                    if (!Directory.Exists(outPath)) Directory.CreateDirectory(outPath);
                    WriteText(configFile, string.Format(JobConfig, outPath));
 
                    ExecNavisworks(modelFile, configFile);
 
                    count++;
                }
                catch (Exception ex)
                {
                    LogOut.Error(ex.StackTrace);
                }
            }
 
            return count;
        }
 
        /// <summary>
        /// 运行Navisworks
        /// </summary>
        public static string ExecNavisworks(string modelFile, string outPath)
        {
            string args = string.Format("-licensing AdLM -OpenFile \"{0}\" -ExecuteAddInPlugin SmartEarth \"{1}\" -NoGui -NoCache -Exit", modelFile, outPath);
 
            Process p = new Process();
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.ErrorDialog = true;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.StartInfo.RedirectStandardError = false;
            p.StartInfo.FileName = RoamerExe;
            p.StartInfo.Arguments = args;
            p.StartInfo.CreateNoWindow = true;
            p.Start();
 
            return string.Empty;
        }
 
        /// <summary>
        /// 写文本文件
        /// </summary>
        private static void WriteText(string file, string str)
        {
            File.WriteAllText(file, str);
        }
    }
}