Browse Source

mxg:修改Other数据格式,添加JoinObject类型的导出

mengxiangge 5 years ago
parent
commit
92f0e14241

+ 0 - 4
Executer/DataExport/JBIM/Component/Equipment.cs

@@ -23,9 +23,5 @@ namespace JBIM.Component
             
         }
 
-        /// <summary>
-        /// 族名称
-        /// </summary>
-        public string FamilyName { get; set; }
     }
 }

+ 22 - 0
Executer/DataExport/JBIM/Component/Other.cs

@@ -0,0 +1,22 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:其它
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:25:47
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JBIM.Common;
+using JBIM.Definition;
+
+namespace JBIM.Component
+{
+    [TypeDefiniton(TypeDefinition.Other)]
+    public class Other : VisibleComponentObject
+    {
+    }
+}

+ 9 - 0
Executer/DataExport/JBIM/Component/VisibleComponentObject.cs

@@ -32,5 +32,14 @@ namespace JBIM.Component
         /// 轮廓信息
         /// </summary>
         public List<Polygon> OutLine { get; private set; }
+
+        /// <summary>
+        /// 族名称
+        /// </summary>
+        public string FamilyName { get; set; }
+        /// <summary>
+        /// 族类型
+        /// </summary>
+        public string FamilySymbol { get; set; }
     }
 }

+ 10 - 1
Executer/DataExport/JBIM/Definition/GeometryLocation.cs

@@ -5,6 +5,7 @@
  * 版本号:v1.0
  *  -------------------------------------------------------------------------*/
 
+using System;
 using System.Collections.Generic;
 
 namespace JBIM.Definition
@@ -31,8 +32,16 @@ namespace JBIM.Definition
 
         public static GeometryLocation CreatePointLocation(XYZ xyz)
         {
+            if (xyz == null) return null;
             var result = new GeometryLocation(LocationType.Point);
-            result.Points.Add(xyz);
+            try
+            {
+                result.Points.Add(xyz);
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+            }
             return result;
         }
 

+ 1 - 0
Executer/DataExport/JBIM/JBIM.csproj

@@ -69,6 +69,7 @@
     <Compile Include="Component\Level.cs" />
     <Compile Include="Component\MepSystem.cs" />
     <Compile Include="Component\MepSystemType.cs" />
+    <Compile Include="Component\Other.cs" />
     <Compile Include="Component\OtherJoinObject.cs" />
     <Compile Include="Component\Parameter.cs" />
     <Compile Include="Component\ParameterDefinition.cs" />

+ 10 - 3
Executer/DataExport/RevitExport/Export/ExportInstance.cs

@@ -37,9 +37,16 @@ namespace RevitExport.Export
 
                 if (IsCancel)
                     return false;
-                ElementWrapper revitElementWrapper = ExportElements[i];
-                ParseElement?.Invoke(this, new ExportArgs(revitElementWrapper));
-                ProcessChanged?.Invoke(i + 1);
+                try
+                {
+                    ElementWrapper revitElementWrapper = ExportElements[i];
+                    ParseElement?.Invoke(this, new ExportArgs(revitElementWrapper));
+                    ProcessChanged?.Invoke(i + 1);
+                }
+                catch (Exception e)
+                {
+                    Console.WriteLine(e);
+                }
             }
             return true;
         }

+ 2 - 1
Executer/DataExport/RevitToJBim/Common/Converter.cs

@@ -41,6 +41,7 @@ namespace RevitToJBim.Common
         /// <returns></returns>
         public static XYZ ConvertToXYZ(Autodesk.Revit.DB.XYZ xyz,bool ignoreZ=false)
         {
+            if (xyz == null) return null;
             var result = new XYZ()
             {
                 X = FtToUse(xyz.X),
@@ -70,7 +71,7 @@ namespace RevitToJBim.Common
         /// <returns></returns>
         public static List<XYZ> ConvertToXYZs(List<Autodesk.Revit.DB.XYZ> xyzs, bool ignoreZ=false)
         {
-            return xyzs.Select(xyz=>ConvertToXYZ(xyz, ignoreZ)).ToList();
+            return xyzs.Select(xyz=>ConvertToXYZ(xyz, ignoreZ)).Where(t=>t!=null).ToList();
         }
        
     }

+ 2 - 2
Executer/DataExport/RevitToJBim/Common/ElementWrapperFactory.cs

@@ -91,13 +91,13 @@ namespace RevitToJBim.Common
                 var connectors = familyInstance.GetAllConnectors();
                 if (connectors.Any(c => c.Domain == Domain.DomainHvac || c.Domain == Domain.DomainPiping))
                 {
-                    useFamilyType = FamilyType.Other;
+                    useFamilyType = FamilyType.JoinObject;
                 }
             }
 
             if (useFamilyType == FamilyType.Undefine)
             {
-                return null;
+                useFamilyType = FamilyType.Other;
             }
 
             ElementWrapper wrapper = new ElementWrapper(familyInstance);

+ 1 - 0
Executer/DataExport/RevitToJBim/Common/FamilyType.cs

@@ -24,6 +24,7 @@ namespace RevitToJBim.Common
         Window,
         Door,
         Column,
+        JoinObject,
         Other,
 
     }

+ 17 - 9
Executer/DataExport/RevitToJBim/Common/RevitUtil.cs

@@ -58,15 +58,23 @@ namespace RevitToJBim.Common
         public static List<XYZ> GetBottomPolygon(FamilyInstance fi)
         {
             List<XYZ> path=new List<XYZ>();
-            var box = fi.get_BoundingBox(null);
-            if (box == null) return path;
-            var boxMin = box.Min;
-            var boxMax = box.Max;
-            path.Add(boxMin);
-            path.Add(boxMin.NewX(boxMax.X));
-            path.Add(boxMin.NewX(boxMax.X).NewY(boxMax.Y));
-            path.Add(boxMin.NewY(boxMax.Y));
-            path.Add(boxMin);
+            try
+            {
+                var box = fi.get_BoundingBox(null);
+                if (box == null) return path;
+                var boxMin = box.Min;
+                var boxMax = box.Max;
+                path.Add(boxMin);
+                path.Add(boxMin.NewX(boxMax.X));
+                path.Add(boxMin.NewX(boxMax.X).NewY(boxMax.Y));
+                path.Add(boxMin.NewY(boxMax.Y));
+                path.Add(boxMin);
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine(e);
+            }
+            
             return path;
         }
         /// <summary>

+ 1 - 1
Executer/DataExport/RevitToJBim/ComponentParse/ParseBase.cs

@@ -27,7 +27,7 @@ namespace RevitToJBim.ComponentParse
         /// <returns></returns>
         public virtual List<string> FastIndex()
         {
-            return null;//Guid.NewGuid().ToString("N");
+            return new List<string>();//Guid.NewGuid().ToString("N");
         }
         public abstract bool Match(ElementWrapper wrapper);
         public virtual List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)

+ 5 - 1
Executer/DataExport/RevitToJBim/ComponentParse/ParseColumn.cs

@@ -17,6 +17,7 @@ using SAGA.RevitUtils.Extends;
 using SAGA.RevitUtils.Extends.Graphic;
 using System.Linq;
 using JBIM.Definition;
+using RevitToJBim.Extension;
 
 namespace RevitToJBim.ComponentParse
 {
@@ -29,7 +30,7 @@ namespace RevitToJBim.ComponentParse
         }
         public override bool Match(ElementWrapper wrapper)
         {
-            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Other);
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Column);
         }
         protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
         {
@@ -40,6 +41,9 @@ namespace RevitToJBim.ComponentParse
             JColumn jObject = new JColumn();
             ParseCore.AttachObject(jObject, wrapper);
             jObject.Location = ParseCore.GetLocation(familyInstance.Location);
+            //FamilyName
+            jObject.FamilyName = familyInstance.GetFamilyName();
+            jObject.FamilySymbol = familyInstance.GetFamilySymbolName();
             var polygonPath = RevitUtil.GetTopPolygon(familyInstance);
             if (polygonPath != null && polygonPath.Any())
             {

+ 3 - 3
Executer/DataExport/RevitToJBim/ComponentParse/ParseCore.cs

@@ -135,11 +135,11 @@ namespace RevitToJBim.ComponentParse
             }
             else if (location is LocationCurve curve)
             {
-                var useCurve = curve.Curve.GetPoints();
+                var points = curve.Curve.GetPoints();
                 if (curve.Curve is Line)
-                    return GeometryLocation.CreateLineLocation(useCurve.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList());
+                    return GeometryLocation.CreateLineLocation(BimConvert.ConvertToXYZs(points));
                 else if (curve.Curve is Arc)
-                    return GeometryLocation.CreateArcLocation(useCurve.Select(xyz => BimConvert.ConvertToXYZ(xyz)).ToList());
+                    return GeometryLocation.CreateArcLocation(BimConvert.ConvertToXYZs(points));
             }
 
             return null;

+ 4 - 0
Executer/DataExport/RevitToJBim/ComponentParse/ParseDoor.cs

@@ -17,6 +17,7 @@ using JBIM;
 using Autodesk.Revit.DB;
 using JBIM.Component;
 using JBIM.Definition;
+using RevitToJBim.Extension;
 
 namespace RevitToJBim.ComponentParse
 {
@@ -42,6 +43,9 @@ namespace RevitToJBim.ComponentParse
             ParseCore.AttachObject(jObject, wrapper);
             context.AddBimObject(jObject);
             jObject.Location = ParseCore.GetLocation(fi.Location);
+            //FamilyName
+            jObject.FamilyName = fi.GetFamilyName();
+            jObject.FamilySymbol = fi.GetFamilySymbolName();
             if (fi.Host != null)
             {
                 jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();

+ 2 - 0
Executer/DataExport/RevitToJBim/ComponentParse/ParseFacility.cs

@@ -62,6 +62,8 @@ namespace RevitToJBim.ComponentParse
             }
             //FamilyName
             jObject.FamilyName = familyInstance.GetFamilyName();
+            jObject.FamilySymbol = familyInstance.GetFamilySymbolName();
+
             //Tag
             jObject.Tag = "";
             //Parameters

+ 6 - 2
Executer/DataExport/RevitToJBim/ComponentParse/ParseFamilyJoinObject.cs

@@ -16,6 +16,7 @@ using JBIM.Component;
 using JBIM.Definition;
 using RevitExport.Export;
 using RevitToJBim.Common;
+using RevitToJBim.Extension;
 using JFamilyType=RevitToJBim.Common.FamilyType;
 using RevitToJBim.ParseData;
 using SAGA.RevitUtils.Extends;
@@ -28,11 +29,11 @@ namespace RevitToJBim.ComponentParse
     {
         public override List<string> FastIndex()
         {
-            return new List<string>() { CategoryGenerator .BuildingCategory(JFamilyType.Other)};
+            return new List<string>() { CategoryGenerator .BuildingCategory(JFamilyType.JoinObject)};
         }
         public override bool Match(ElementWrapper wrapper)
         {
-            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Other);
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.JoinObject);
         }
 
         protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
@@ -45,6 +46,9 @@ namespace RevitToJBim.ComponentParse
             OtherJoinObject jObject = new OtherJoinObject();
             //Name,SourceId
             ParseCore.AttachObject(jObject, wrapper);
+            //FamilyName
+            jObject.FamilyName = familyInstance.GetFamilyName();
+            jObject.FamilySymbol = familyInstance.GetFamilySymbolName();
             //Location
             jObject.Location = GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(familyInstance.GetLocationPoint()));
             //OutLine

+ 82 - 0
Executer/DataExport/RevitToJBim/ComponentParse/ParseOther.cs

@@ -0,0 +1,82 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ParseFamilyJoinObject
+ * 作者:xulisong
+ * 创建时间: 2019/6/24 9:29:00
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using JBIM;
+using JBIM.Component;
+using JBIM.Definition;
+using RevitExport.Export;
+using RevitToJBim.Common;
+using RevitToJBim.Extension;
+using JFamilyType=RevitToJBim.Common.FamilyType;
+using RevitToJBim.ParseData;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.MEP;
+
+namespace RevitToJBim.ComponentParse
+{
+    [UsableParse]
+    public class ParseOther : ParseBase
+    {
+        public override List<string> FastIndex()
+        {
+            return new List<string>() { CategoryGenerator .BuildingCategory(JFamilyType.Other)};
+        }
+        public override bool Match(ElementWrapper wrapper)
+        {
+            return wrapper.Category == CategoryGenerator.BuildingCategory(JFamilyType.Other);
+        }
+
+        protected override List<BimId> ParseInner(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance familyInstance))
+            {
+                return null;
+            }
+            //ElementType
+            Other jObject = new Other();
+            //Name,SourceId
+            ParseCore.AttachObject(jObject, wrapper);
+            //FamilyName
+            jObject.FamilyName = familyInstance.GetFamilyName();
+            jObject.FamilySymbol = familyInstance.GetFamilySymbolName();
+            //Location
+            jObject.Location = GeometryLocation.CreatePointLocation(BimConvert.ConvertToXYZ(familyInstance.GetLocationPoint()));
+            //OutLine
+            var polygonPath = RevitUtil.GetBottomPolygon(familyInstance);
+            if (polygonPath != null && polygonPath.Any())
+            {
+                Polygon outLine = new Polygon(BimConvert.ConvertToXYZs(polygonPath));
+                jObject.OutLine.Add(outLine);
+            }
+            //Id
+            context.AddBimObject(jObject);
+            return new List<BimId>() { jObject.Id };
+        }
+
+        public override List<ElementWrapper> ArrangeRefElements(ElementWrapper wrapper, JBimParseContext context)
+        {
+            if (!(wrapper.RefElement is FamilyInstance fi))
+            {
+                return null;
+            }
+
+            var wrappers = new List<ElementWrapper>() { };
+            var connectors = fi.GetAllConnectors();
+            foreach (var connector in connectors)
+            {
+                wrappers.Add(ParseCore.GetConnectorWrapper(connector));
+            }
+            return wrappers;
+        }
+    }
+}

+ 0 - 4
Executer/DataExport/RevitToJBim/ComponentParse/ParseUnit.cs

@@ -22,10 +22,6 @@ namespace RevitToJBim.ComponentParse
     [UsableParseAttribute]
     class ParseUnit : ParseBase
     {
-        public override List<string> FastIndex()
-        {
-            return new List<string>() { CategoryGenerator.BuildingCategory(Common.FamilyType.Other) };
-        }
         public override bool Match(ElementWrapper wrapper)
         {
             return wrapper.RefObject is FormatOptions;

+ 4 - 0
Executer/DataExport/RevitToJBim/ComponentParse/ParseWindow.cs

@@ -16,6 +16,7 @@ using JBIM.Component;
 using JBIM.Definition;
 using RevitExport.Export;
 using RevitToJBim.Common;
+using RevitToJBim.Extension;
 using JFamilyType = RevitToJBim.Common.FamilyType;
 namespace RevitToJBim.ComponentParse
 {
@@ -42,6 +43,9 @@ namespace RevitToJBim.ComponentParse
             ParseCore.AttachObject(jObject, wrapper);
             context.AddBimObject(jObject);
             jObject.Location = ParseCore.GetLocation(fi.Location);
+            //FamilyName
+            jObject.FamilyName = fi.GetFamilyName();
+            jObject.FamilySymbol = fi.GetFamilySymbolName();
             if (fi.Host != null)
             {
                 jObject.Owner = context.Parser.ParseElement(ElementWrapperFactory.CreateWrapper(fi.Host))?.FirstOrDefault();

+ 4 - 0
Executer/DataExport/RevitToJBim/Extension/ElementExtension.cs

@@ -26,6 +26,10 @@ namespace RevitToJBim.Extension
         {
             return element.GetFamily()?.Name;
         }
+        public static string GetFamilySymbolName(this Element element)
+        {
+            return element.GetFamilySymbol()?.Name;
+        }
         /// <summary>
         /// 获取设备的种族类型编码 ATFC
         /// 族名称的命名规则:ATFC-风机盘管

+ 1 - 1
Executer/DataExport/RevitToJBim/MbiExport.cs

@@ -48,7 +48,7 @@ namespace RevitToJBim
                 //保存到本地
                 string fileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                 string path = Path.Combine($"{document.PathName}_{fileName}.json");
-                //File.WriteAllText(path, json.ToString());
+                File.WriteAllText(path, json.ToString());
             }
             catch (Exception ex)
             {

+ 1 - 0
Executer/DataExport/RevitToJBim/RevitToJBim.csproj

@@ -60,6 +60,7 @@
     <Compile Include="Common\CategoryGenerator.cs" />
     <Compile Include="Common\Converter.cs" />
     <Compile Include="Common\StandardUtil.cs" />
+    <Compile Include="ComponentParse\ParseOther.cs" />
     <Compile Include="Extension\CurveExtension.cs" />
     <Compile Include="Common\ElementWrapperFactory.cs" />
     <Compile Include="Common\ExceptionUtil.cs" />