| | |
| | | /// <summary> |
| | | /// 从json字符串中解析 |
| | | /// </summary> |
| | | public static HStation.Model.RevitModel FromJsonString(string revitJsonString, out string msg) |
| | | public static HStation.Model.RevitModel FromJsonString |
| | | ( |
| | | string revitJsonString, |
| | | string revitOthersJsonString, |
| | | out string msg |
| | | ) |
| | | { |
| | | msg = string.Empty; |
| | | if (string.IsNullOrEmpty(revitJsonString)) |
| | |
| | | { |
| | | var model = new Model.RevitModel(); |
| | | |
| | | //解析结构json |
| | | var jarray = JArray.Parse(revitJsonString); |
| | | for (int i = 0; i < jarray.Count; i++) |
| | | { |
| | |
| | | } |
| | | if (exchanger.Diameter < 0.1) |
| | | { |
| | | exchanger.Diameter = 0.1; |
| | | exchanger.Diameter = 500; |
| | | } |
| | | if (exchanger.Roughness < 0.1) |
| | | { |
| | | exchanger.Roughness = 0.1; |
| | | exchanger.Roughness = 110; |
| | | } |
| | | model.Exchangers.Add(exchanger); |
| | | } |
| | |
| | | { |
| | | pipe.Length = length; |
| | | } |
| | | |
| | | |
| | | #region 直径 |
| | | |
| | | if (jobject[RevitJsonProp.Diameter].MatchNumeric(out double diameter)) |
| | | { |
| | | pipe.Diameter = diameter; |
| | | } |
| | | else if (jobject[RevitJsonProp.InternalDiameter].MatchNumeric(out double internalDiameter)) |
| | | |
| | | if (pipe.Diameter < 1) |
| | | { |
| | | pipe.Diameter = internalDiameter; |
| | | if (jobject[RevitJsonProp.InternalDiameter].MatchNumeric(out double internalDiameter)) |
| | | { |
| | | pipe.Diameter = internalDiameter; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | if (jobject[RevitJsonProp.MinorLoss].MatchNumeric(out double minorLoss)) |
| | | { |
| | | pipe.MinorLoss = minorLoss; |
| | |
| | | } |
| | | if (pipe.Diameter < 0.1) |
| | | { |
| | | pipe.Diameter = 0.1; |
| | | pipe.Diameter = 500; |
| | | } |
| | | if (pipe.Roughness < 0.1) |
| | | { |
| | | pipe.Roughness = 0.1; |
| | | pipe.Roughness = 110; |
| | | } |
| | | model.Pipes.Add(pipe); |
| | | } |
| | |
| | | } |
| | | if (translation.Diameter < 0.1) |
| | | { |
| | | translation.Diameter = 0.1; |
| | | translation.Diameter = 500; |
| | | } |
| | | if (translation.Roughness < 0.1) |
| | | { |
| | | translation.Roughness = 0.1; |
| | | translation.Roughness = 110; |
| | | } |
| | | model.Translations.Add(translation); |
| | | } |
| | |
| | | valve.MinorLoss = minorLoss; |
| | | } |
| | | |
| | | if (valve.Diameter < 0.1) |
| | | { |
| | | valve.Diameter = 500; |
| | | } |
| | | |
| | | valve.ValveType = jobject[RevitJsonProp.ValveType].ToString(); |
| | | valve.ValveSetting = jobject[RevitJsonProp.ValveSetting].ToString(); |
| | | model.Valves.Add(valve); |
| | |
| | | { |
| | | var decorator = new Model.RevitDecorator(); |
| | | decorator.Id = jobject[RevitJsonProp.Id].ToString(); |
| | | decorator.Code = jobject[RevitJsonProp.Code].ToString(); |
| | | if (string.IsNullOrEmpty(decorator.Code)) |
| | | { |
| | | decorator.Code = decorator.Id; |
| | | } |
| | | decorator.Name = string.Empty; |
| | | decorator.Category = jobject[RevitJsonProp.ClanAndType][RevitJsonProp.ClanName].ToString(); |
| | | decorator.Decoration = string.Empty; |
| | | decorator.Decoration = string.Empty; |
| | | model.Decorators.Add(decorator); |
| | | } |
| | | break; |
| | | default: break; |
| | | } |
| | | } |
| | | |
| | | //解析其他json |
| | | var jothersArray = JArray.Parse(revitOthersJsonString); |
| | | if (jothersArray != null && jothersArray.Count > 0) |
| | | { |
| | | var allParterList = model.GetAllParters(); |
| | | for (int i = 0; i < jothersArray.Count; i++) |
| | | { |
| | | var jobject = jothersArray[i]; |
| | | var id = jobject[RevitOthersJsonProp.Id]?.ToString(); |
| | | if (string.IsNullOrEmpty(id)) |
| | | { |
| | | continue; |
| | | } |
| | | if (allParterList.Exists(x => x.Id == id)) |
| | | { |
| | | continue; |
| | | } |
| | | if (model.Decorators.Exists(x => x.Id == id)) |
| | | { |
| | | continue; |
| | | } |
| | | var decorator = new Model.RevitDecorator(); |
| | | decorator.Id = id; |
| | | decorator.Code = id; |
| | | decorator.Name = jobject[RevitOthersJsonProp.Name]?.ToString(); |
| | | decorator.Category = jobject[RevitOthersJsonProp.CategoryName]?.ToString(); |
| | | decorator.Decoration = jobject[RevitOthersJsonProp.CategoryID]?.ToString(); |
| | | model.Decorators.Add(decorator); |
| | | } |
| | | } |
| | | |
| | |
| | | /// <summary> |
| | | /// 从json文件中解析 |
| | | /// </summary> |
| | | public static Model.RevitModel FromJsonFile(string revitJsonFile, out string msg) |
| | | public static Model.RevitModel FromJsonFile(string revitJsonFile, string revitOthersJsonFile, out string msg) |
| | | { |
| | | if (!File.Exists(revitJsonFile)) |
| | | { |
| | |
| | | return default; |
| | | } |
| | | var revitJson = File.ReadAllText(revitJsonFile); |
| | | var revitModel = FromJsonString(revitJson, out msg); |
| | | var revitOthersJson = string.Empty; |
| | | if (File.Exists(revitOthersJsonFile)) |
| | | { |
| | | revitOthersJson = File.ReadAllText(revitOthersJsonFile); |
| | | } |
| | | var revitModel = FromJsonString(revitJson, revitOthersJson, out msg); |
| | | if (revitModel == null) |
| | | { |
| | | return default; |