xulisong 5 سال پیش
والد
کامیت
afcff99459

+ 3 - 2
JBIM/RevitExport/Parse/ParseInstance.cs

@@ -50,8 +50,8 @@ namespace RevitExport
             {
                 return parser;
             }
-            var currentParse = Parsers.FirstOrDefault(p => p.Match(wrapper));
-            return currentParse;
+            var currentParser = Parsers.FirstOrDefault(p => p.Match(wrapper));
+            return currentParser;
         }
 
         public virtual List<Result> ParseElement(ElementWrapper elementWrapper)
@@ -69,6 +69,7 @@ namespace RevitExport
             if (!Parsers.Any())
                 return;
             ElementWrapper element = e.ElementWrapper;
+
             ParseElement(element);      
         }
 

BIN
JBIM/RevitExport/bin/Debug/RevitExport.dll


BIN
JBIM/RevitExport/bin/Debug/RevitExport.pdb


+ 1 - 1
JBIM/RevitToJBim/ComponentParse/ParseBase.cs

@@ -34,7 +34,7 @@ namespace RevitToJBim.ComponentParse
         }
         public virtual List<BimId> Parse(ElementWrapper wrapper, JBimParseContext context)
         {
-            BimId result = context.GetBimId(wrapper.RefElement.Id.ToString());
+            BimId result = context.GetBimId(wrapper.SourceId);
             if (result != null)
             {
                 return new List<BimId>() { result };

+ 13 - 12
JBIM/RevitToJBim/ComponentParse/ParseCore.cs

@@ -28,10 +28,8 @@ namespace RevitToJBim.ComponentParse
     /// </summary>
     public class ParseCore
     {
-        public class ParseElementManager
-        {
-            //获取可用的解析类
-            public static List<ParseBase> GetUseParses()
+       //获取可用的解析类
+       public static List<ParseBase> GetUseParsers()
             {
                 List<ParseBase> result = new List<ParseBase>();
                 Assembly assembly = Assembly.GetCallingAssembly();
@@ -57,17 +55,12 @@ namespace RevitToJBim.ComponentParse
                 return result;
 
             }
-        }
+     
         public static void AttachObject(ComponentObject bimObj, ElementWrapper wrapper)
         {
             bimObj.SourceId = wrapper.SourceId;
             bimObj.Name = wrapper.RefElement?.Name;
         }
-        public static BimObject GetObject(object obj)
-        {
-            return null;
-        }
-
         public static Connector CreateConnector(Autodesk.Revit.DB.Connector connector)
         {
             var result= new Connector();
@@ -90,7 +83,15 @@ namespace RevitToJBim.ComponentParse
             result.Origin = BimConvert.ConvertToXYZ(connector.Origin);
             return result;
         }
-
-       
+        /// <summary>
+        /// 获取Connector包装类
+        /// </summary>
+        /// <param name="connector"></param>
+        /// <returns></returns>
+        public static ElementWrapper GetConnectorWrapper(Autodesk.Revit.DB.Connector connector)
+        {
+            ElementWrapper wrapper = new ElementWrapper(connector, RevitIdGenerator.GetConnectorId(connector));
+            return wrapper;
+        }
     }
 }

+ 7 - 2
JBIM/RevitToJBim/ComponentParse/ParsePipe.cs

@@ -12,7 +12,6 @@ using System.Text;
 using System.Threading.Tasks;
 using Autodesk.Revit.DB.Plumbing;
 using JBIM;
-using JBIM.Relationship;
 using RevitExport;
 using RevitToJBim.Common;
 using SAGA.RevitUtils.Extends;
@@ -86,7 +85,13 @@ namespace RevitToJBim.ComponentParse
             }
             //创建MepSystem
             var mepSystemElementWrapper = new ElementWrapper(pipe.MEPSystem);
-            return new List<ElementWrapper>() {mepSystemElementWrapper};
+            var wrappers=new List<ElementWrapper>() { mepSystemElementWrapper};
+            var connectors = pipe.GetConnectors();
+            foreach (var connector in connectors)
+            {
+                wrappers.Add(ParseCore.GetConnectorWrapper(connector));
+            }            
+            return wrappers;
         }
     }
 }

+ 2 - 1
JBIM/RevitToJBim/JBimParseContext.cs

@@ -12,6 +12,7 @@ using JBIM.Common;
 using JBIM.Component;
 using JBIM.Relationship;
 using RevitExport;
+using RevitToJBim.ComponentParse;
 using RevitToJBim.JsonConverter;
 
 namespace RevitToJBim
@@ -21,7 +22,7 @@ namespace RevitToJBim
     /// </summary>
     public class JBimParseContext: ParseContext
     {
-        public JBimParseContext(List<IParseElement<JBimParseContext, BimId>> parsers)
+        public JBimParseContext(List<ParseBase> parsers)
         {
             Parser = new RevitToJBimParser(this, parsers);
             Document = new BimDocument();

+ 1 - 0
JBIM/RevitToJBim/RevitToJBim.csproj

@@ -74,6 +74,7 @@
     <Compile Include="RevitToJBimParser.cs" />
     <Compile Include="JBimParseContext.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="TestExport.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\JBIM\JBIM.csproj">

+ 6 - 5
JBIM/RevitToJBim/RevitToJBimParser.cs

@@ -12,18 +12,19 @@ using System.Text;
 using System.Threading.Tasks;
 using JBIM;
 using RevitExport;
+using RevitToJBim.ComponentParse;
 
 namespace RevitToJBim
 {
     public class RevitToJBimParser: ParseInstance<JBimParseContext, BimId>
     {
-        public RevitToJBimParser(JBimParseContext context, List<IParseElement<JBimParseContext, BimId>> parsers):base(context,parsers)
+        public RevitToJBimParser(JBimParseContext context, List<ParseBase> parsers):base(context,parsers.OfType<IParseElement<JBimParseContext, BimId>>().ToList())
         {
            
         }
-        public override List<BimId> ParseElement(ElementWrapper elementWrapper)
-        {
-            return ParseElement(elementWrapper);
-        }
+        //public override List<BimId> ParseElement(ElementWrapper elementWrapper)
+        //{
+        //    return base.ParseElement(elementWrapper);
+        //}
     }
 }

+ 80 - 0
JBIM/RevitToJBim/TestExport.cs

@@ -0,0 +1,80 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:TestExport
+ * 作者:xulisong
+ * 创建时间: 2019/6/18 15:43:54
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Autodesk.Revit.Attributes;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.DB.Plumbing;
+using Autodesk.Revit.UI;
+using RevitExport;
+using RevitToJBim.ComponentParse;
+using SAGA.RevitUtils;
+using SAGA.RevitUtils.Extends;
+
+namespace RevitToJBim
+{
+    public class TestExport
+    {
+        public static Document Document { get; set; }
+        public static void Export()
+        {
+            var elements = Document.GetElements(typeof(Pipe));
+            var wrappers = elements.Select(e => new ElementWrapper(e)).ToList();
+            ExportInstance report = new ExportInstance(wrappers);
+            JBimParseContext context = new JBimParseContext(ParseCore.GetUseParsers());
+            var dd = false;
+            context.Parser.Parse(report);
+            var result = context.Serialize();
+            string fileName = DateTime.Now.ToString("yyyyMMddhhmmss");
+            string path = Path.Combine("C", $"{fileName}.json");
+            File.WriteAllText(path, result);
+        }
+    }
+    /// <summary>
+    /// 增加缺失元空间
+    /// </summary>
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    public class AddSiSpaceCommand : IExternalCommand, IExternalCommandAvailability
+    {
+
+        public  Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            try
+            {
+                TestExport.Document = commandData.Application.ActiveUIDocument.Document;
+                TestExport.Export();
+                TaskDialog dialog = new TaskDialog("导出");
+                dialog.MainInstruction ="导出成功";
+                dialog.Show();
+            }
+            catch (Exception e)
+            {
+                TaskDialog dialog = new TaskDialog("导出");
+                dialog.MainInstruction =e.Message+"\n\t"+ e.StackTrace.ToString();
+                dialog.Show();
+                return Result.Cancelled;
+            }
+            return Result.Succeeded;
+        }
+
+
+        /// <summary>
+        /// Onlys show the dialog when a document is open, as Dockable dialogs are only available
+        /// when a document is open.
+        /// </summary>
+        public  bool IsCommandAvailable(UIApplication applicationData, CategorySet selectedCategories)
+        {
+            return false;
+        }
+    }
+}

BIN
JBIM/RevitToJBim/bin/Debug/RevitExport.dll


BIN
JBIM/RevitToJBim/bin/Debug/RevitExport.pdb


BIN
JBIM/RevitToJBim/bin/Debug/RevitToJBim.dll


BIN
JBIM/RevitToJBim/bin/Debug/RevitToJBim.pdb