/// <summary> /// 模板生成 /// </summary> /// <param name="doc"></param> /// <param name="face"></param> /// <param name="drt"></param> /// <param name="HostELemID"></param> /// <returns></returns> public static ElementId SurfaceLayerGernerate(Document doc, Face face, DirectShapeType drt, ElementId HostELemID) { DirectShape dsElem = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_Parts), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); XYZ faceNormal = face.ComputeNormal(new UV(0, 0)); if (face is CylindricalFace) { return(null); //如果是圆柱面则排除 } IList <CurveLoop> faceLoopList = face.GetEdgesAsCurveLoops(); Solid sd = GeometryCreationUtilities.CreateExtrusionGeometry(faceLoopList, faceNormal, 5 / 304.8); //模板尺寸判断,矩形标尺寸,非矩形不标 string tpSize = null; double last = sd.Volume; //catch { SWF.MessageBox.Show(HostELemID.IntegerValue + ""); } //对于生成的solid进行预处理 sd = SolidHandle(doc, HostELemID, sd); double now = sd.Volume; if (now == 0) { return(null); } if (last == now) { if (faceLoopList.Count == 1) { List <Curve> curveList = faceLoopList[0].ToList(); tpSize = bc.RectTangleSize(curveList); } else { tpSize = "非矩形板"; } } else { tpSize = "非矩形板"; } dsElem.SetShape(new List <GeometryObject>() { sd }); dsElem.SetTypeId(drt.Id); dsElem.LookupParameter("HostElemID").Set(HostELemID.IntegerValue); dsElem.LookupParameter("模板面积").Set(sd.Volume / (5 / 304.8)); Parameter dsParamter = dsElem.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS); try { if (faceNormal.IsAlmostEqualTo(-XYZ.BasisZ)) { if (doc.GetElement(HostELemID) is Floor) { dsParamter.Set("楼板底模板"); } else if (doc.GetElement(HostELemID).Category.Id == new ElementId(BuiltInCategory.OST_StructuralFraming)) { dsParamter.Set("梁底模板"); } else if (doc.GetElement(HostELemID) is Wall) { dsParamter.Set("墙洞顶模板"); } else if (doc.GetElement(HostELemID) is Stairs) { dsParamter.Set("平台底模板"); } } else if (faceNormal.IsAlmostEqualTo(XYZ.BasisZ)) { //墙 if (doc.GetElement(HostELemID) is Wall) { dsParamter.Set("墙洞底模板"); } } else { if (doc.GetElement(HostELemID) is Floor) { dsParamter.Set("楼板侧模板"); } else if (doc.GetElement(HostELemID).Category.Id == new ElementId(BuiltInCategory.OST_StructuralFraming)) { dsParamter.Set("梁侧模板"); } else if (doc.GetElement(HostELemID).Category.Id == new ElementId(BuiltInCategory.OST_StructuralColumns)) { dsParamter.Set("柱侧模板"); } else if (doc.GetElement(HostELemID) is Wall) { dsParamter.Set("墙侧模板"); } else if (doc.GetElement(HostELemID) is Stairs) { dsParamter.Set("楼梯侧模板"); } else if (doc.GetElement(HostELemID).Category.Id == new ElementId(BuiltInCategory.OST_StructuralFoundation)) { dsParamter.Set("基础侧模板"); } } } catch (Exception e) { SWF.MessageBox.Show(e.ToString()); } dsElem.LookupParameter("模板尺寸").Set(tpSize); dsElem.LookupParameter("X").Set(faceNormal.X); dsElem.LookupParameter("Y").Set(faceNormal.Y); dsElem.LookupParameter("Z").Set(faceNormal.Z); doc.ActiveView.PartsVisibility = PartsVisibility.ShowPartsOnly; return(dsElem.Id); }