private static bool IsVolumeSatisfied(double volumn, SolidVolumnConstraint solidVolumnConstraint) { switch (solidVolumnConstraint) { case SolidVolumnConstraint.Any: return(true); case SolidVolumnConstraint.Positive: return(volumn > 0); case SolidVolumnConstraint.Negative: return(volumn <= 0); } return(false); }
/// <summary> /// 获取一个单元中的所有体积大于 0 的实体对象(坐标为相对于单元所在的模型空间) /// </summary> /// <param name="elem"></param> /// /// <returns>一个键值对字典,其中键表示element 中的实体对象,值指示此Solid是此 Element 所特有的(true), /// 还是对于此element 所属的族的Solid进行“索引+变换”后的结果(false)。 /// 换句话说,true表示此 Element 是被切割过的,false表示此 Element 是被未被切割过的。 /// 但是要注意,不论Solid所对应的值为true还是false,此solid的位置都是与项目中的element所在的位置相一致的。</returns> /// /// <remarks>但是要注意,不论Solid所对应的值为true还是false,此solid的位置都是与项目中的element所在的位置相一致的。</remarks> public static Dictionary <Solid, bool> GetSolidsInModel(Element elem, SolidVolumnConstraint solidVolumnConstraint) { // 提取单元的几何信息 Options opt = new Options { ComputeReferences = false, DetailLevel = ViewDetailLevel.Medium }; GeometryElement geoElem = elem.get_Geometry(opt); Dictionary <Solid, bool> solids = new Dictionary <Solid, bool>(); solids = GetSolidsInModel(geoElem.ToList(), solidVolumnConstraint); return(solids); }
/// <summary> /// 获取一个单元中的所有体积大于 0 的实体对象(坐标为相对于单元所在的模型空间) /// </summary> /// <param name="geoElem"></param> /// <param name="solidVolumnConstraint"></param> /// /// <returns>一个键值对字典,其中键表示element 中的实体对象,值指示此Solid是此 Element 所特有的(true), /// 还是对于此element 所属的族的Solid进行“索引+变换”后的结果(false)。 /// 换句话说,true表示此 Element 是被切割过的,false表示此 Element 是被未被切割过的。 /// 但是要注意,不论Solid所对应的值为true还是false,此solid的位置都是与项目中的element所在的位置相一致的。</returns> /// /// <remarks>但是要注意,不论Solid所对应的值为true还是false,此solid的位置都是与项目中的element所在的位置相一致的。</remarks> public static Dictionary <Solid, bool> GetSolidsInModel(IList <GeometryObject> geoElem, SolidVolumnConstraint solidVolumnConstraint) { Dictionary <Solid, bool> solids = new Dictionary <Solid, bool>(); // 柱子中的各种图形 foreach (GeometryObject obj in geoElem) // GeometryElement 集合中只有 Solid 或者 GeometryInstance 对象,而没有 Face 等对象。 { // 如果Element被切割了,那么此Element的几何信息与定义此Element的族的几何信息就不一样了,所以,被切割的Element的GeometryElement之中就直接包含有Solid if (obj is Solid && IsVolumeSatisfied(((Solid)obj).Volume, solidVolumnConstraint)) { // 此时的 Solid 是 Familyinstance 特有的 Solid,后期不需要进行变换 // 如果此 Element is FamilyInstance,则其 HasModifiedGeometry 方法会返回 true。 solids.Add((Solid)obj, true); } // 如果 Element 未被切割,则GeometryElement之中就包含的就是GeometryInstance else if (obj is GeometryInstance) { GeometryInstance geoInstance = obj as GeometryInstance; // 返回族实例的几何数据 GeometryElement geoElement = geoInstance.GetInstanceGeometry(); // foreach (GeometryObject obj2 in geoElement) { if (obj2 is Solid && IsVolumeSatisfied(((Solid)obj2).Volume, solidVolumnConstraint)) { // 此时的solid 是 Family中的solid 直接经过变换后得到的索引实体对象。Solid的坐标位置与其在项目中的位置重合,后期不需要进行变换。 // 如果此 Element is FamilyInstance,则其 HasModifiedGeometry 方法会返回 false。 solids.Add((Solid)obj2, false); } } } } return(solids); }