private void CollectMassInfo(SourceType sourceType) { try { FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <Element> elements = collector.OfCategory(BuiltInCategory.OST_Mass).OfClass(typeof(DirectShape)).ToElements().ToList(); if (elements.Count > 0) { string hostCategory = ""; string hostUniqueId = ""; XYZ hostCentroid = null; double massHeight = 0; foreach (Element element in elements) { if (MassDataStorageUtil.GetLinkedHostInfo(element, out hostCategory, out hostUniqueId, out hostCentroid, out massHeight)) { if (hostCategory == sourceType.ToString()) { MassProperties mp = new MassProperties(element); mp.SetHostInfo(hostUniqueId, sourceType, hostCentroid, massHeight); massList.Add(mp); } } } } } catch (Exception ex) { MessageBox.Show("Failed to collect masses information.\n" + ex.Message, "Collect Mass Information", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static bool CreateAreaSolid(Document doc, AreaProperties ap, out MassProperties createdMass) { bool created = false; createdMass = null; try { string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); if (null != ap.Linked3dMass) { //delete existing mass first MassProperties existingMass = ap.Linked3dMass; doc.Delete(new ElementId(existingMass.MassId)); } IList <GeometryObject> areaGeometries = new List <GeometryObject>(); if (ap.AreaProfile.Count > 0) { XYZ extrusionDir = new XYZ(0, 0, 1); Solid areaSolid = GeometryCreationUtilities.CreateExtrusionGeometry(ap.AreaProfile, extrusionDir, ap.UserHeight); if (null != areaSolid) { areaGeometries.Add(areaSolid); } } #if RELEASE2015 || RELEASE2016 DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory), appGuid, ap.AreaId.ToString()); #else DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory)); createdShape.ApplicationId = appGuid; createdShape.ApplicationDataId = ap.AreaId.ToString(); #endif #if RELEASE2016 DirectShapeOptions options = createdShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.Referenceable; createdShape.SetOptions(options); #endif createdShape.SetShape(areaGeometries); createdShape.SetName(ap.AreaName); Element massElement = doc.GetElement(createdShape.Id); if (null != massElement) { createdMass = new MassProperties(massElement); createdMass.SetHostInfo(ap.AreaUniqueId, SourceType.Areas, ap.AreaCenterPoint, ap.UserHeight); bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Areas.ToString(), ap.AreaUniqueId, ap.AreaCenterPoint, ap.UserHeight); created = true; } } catch (Exception ex) { MessageBox.Show("Failed to create area solid.\n" + ex.Message, "Create Area Solid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(created); }
public static bool CreateFloorFace(Document doc, FloorProperties fp, out MassProperties createdMass) { bool created = false; createdMass = null; try { string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); if (null != fp.Linked2dMass) { //delete existing mass first MassProperties existingMass = fp.Linked2dMass; doc.Delete(new ElementId(existingMass.MassId)); } IList <GeometryObject> floorGeometries = GetGeometryObjectsFromFace(fp.TopFace); #if RELEASE2015 || RELEASE2016 DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory), appGuid, fp.FloorId.ToString()); #else DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory)); createdShape.ApplicationId = appGuid; createdShape.ApplicationDataId = fp.FloorId.ToString(); #endif #if RELEASE2016 DirectShapeOptions options = createdShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.Referenceable; createdShape.SetOptions(options); #endif createdShape.SetShape(floorGeometries); createdShape.SetName(fp.FloorName); Element massElement = doc.GetElement(createdShape.Id); if (null != massElement) { createdMass = new MassProperties(massElement); createdMass.MassElementType = MassType.MASS2D; createdMass.SetHostInfo(fp.FloorUniqueId, SourceType.Floors, fp.FloorSolidCentroid, 0); bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Floors.ToString(), fp.FloorUniqueId, fp.FloorSolidCentroid, 0); created = true; } } catch (Exception ex) { MessageBox.Show("Failed to create room solid.\n" + ex.Message, "Create Room Solid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(created); }
public static bool CreateRoomFace(Document doc, RoomProperties rp, out MassProperties createdMass) { bool created = false; createdMass = null; try { string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); if (null != rp.Linked2dMass) { //delete existing mass first MassProperties existingMass = rp.Linked2dMass; doc.Delete(new ElementId(existingMass.MassId)); } if (null != rp.BottomFace) { IList <GeometryObject> roomGeometries = GetGeometryObjectsFromFace(rp.BottomFace); #if RELEASE2015 || RELEASE2016 DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory), appGuid, rp.RoomId.ToString()); #else DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory)); createdShape.ApplicationId = appGuid; createdShape.ApplicationDataId = rp.RoomId.ToString(); #endif createdShape.SetShape(roomGeometries); createdShape.SetName(rp.RoomName); Element massElement = doc.GetElement(createdShape.Id); if (null != massElement) { createdMass = new MassProperties(massElement); createdMass.MassElementType = MassType.MASS2D; createdMass.SetHostInfo(rp.RoomUniqueId, SourceType.Rooms, rp.RoomSolidCentroid, 0); bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Rooms.ToString(), rp.RoomUniqueId, rp.RoomSolidCentroid, 0); created = true; } } } catch (Exception ex) { MessageBox.Show("Failed to create room face.\n" + ex.Message, "Create Room Face", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(created); }