Browse Source

mxg:BIMLocation取设备中心点,自动放置时平移设备将中心点移到指定点

mengxiangge 6 years ago
parent
commit
c57911559c

+ 12 - 10
MBI/SAGA.MBI/Extend/ElementExtend.cs

@@ -109,16 +109,18 @@ namespace SAGA.MBI.Tools
         /// <returns></returns>
         public static XYZ GetLocationPointMBIXYZ(this Element element)
         {
-            //定位点不可靠,未来可能会更改为Box的中心点
-            XYZ bimXyz = element.GetLocationPoint();
-            if (element is FamilyInstance fi)
-            {
-                var family = fi.GetFamily();
-                if (family.IsInPlace)
-                {
-                    bimXyz = fi.GetBoxCenter();
-                }
-            }
+            ////定位点不可靠,未来可能会更改为Box的中心点
+            //XYZ bimXyz = element.GetLocationPoint();
+            //if (element is FamilyInstance fi)
+            //{
+            //    var family = fi.GetFamily();
+            //    if (family.IsInPlace)
+            //    {
+            //        bimXyz = fi.GetBoxCenter();
+            //    }
+            //}
+            //定位点改为Box中心点 
+            XYZ bimXyz = element.GetBoxCenter();
 
             return bimXyz;
         }

+ 14 - 4
MBI/SAGA.MBI/RevitReference/RVTNoModeDutyOperate.cs

@@ -50,20 +50,30 @@ namespace SAGA.MBI.RevitReference
                             if (fs == null)
                             {
                                 MessageShowBase.Infomation($"没有找到编码{mode.MEquipBase.EquipClassCode}类型的族,请手动载入后再操作。");
-                                return Result.Cancelled; }
+                                return Result.Cancelled;
+                            }
                             if (IsBasePointFamily(fs))
                             {
                                 //使用BIMLocation中的坐标,mm转为英寸
                                 XYZ xyz = mode.MEquipBase.Location.ToXyz();
-                                xyz = xyz==null ? XYZ.Zero : xyz.ConvertToApi();
+                                xyz = xyz == null ? XYZ.Zero : xyz.ConvertToApi();
                                 var level = GetCurFloorLevel(doc);
                                 //传标高,z值设置为零
-                                xyz=xyz.NewZ(0);
+                                xyz = xyz.NewZ(0);
                                 fi = doc.Create.NewFamilyInstance(xyz, fs, level, StructuralType.NonStructural);
-                                mode.MEquipBase.SaveDutyBIMRelation(doc.PathName.GetFileName(),fi.Id.ToString());
+                                //假如定位点和中心点不一致,平移设备,将设备中心点移到定位点上
+                                XYZ centerXyz = fi.GetLocationPointMBIXYZ().NewZ(0);
+                                if (!centerXyz.IsEqual2(xyz))
+                                {
+                                    XYZ vector = xyz - centerXyz;
+                                    doc.MoveElement(fi.Id, vector);
+                                }
+
                                 trans.Commit();
                                 if (fi != null)
                                 {
+                                    //本地数据库保存岗位和BimId的关系
+                                    mode.MEquipBase.SaveDutyBIMRelation(doc.PathName.GetFileName(), fi.Id.ToString());
                                     mode.BimId = fi.Id.ToString();
                                     afterAction?.Invoke(fi);
                                 }