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);
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
        private void button2DCreate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                List <FloorProperties> floorList = (List <FloorProperties>)dataGridFloor.ItemsSource;
                var selectedFloors = from floor in floorList where floor.IsSelected select floor;

                if (selectedFloors.Count() > 0)
                {
                    statusLable.Text       = "Creating 2D Masses ..";
                    progressBar.Visibility = System.Windows.Visibility.Visible;
                    progressBar.Value      = 0;
                    progressBar.Maximum    = selectedFloors.Count();

                    bool createdParamMaps = (massConfig.UpdateType != ParameterUpdateType.None && massConfig.MassParameters.Count > 0) ? true : false;

                    UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
                    using (TransactionGroup tg = new TransactionGroup(m_doc))
                    {
                        tg.Start("Create 2D Masses");
                        try
                        {
                            double count = 0;
                            foreach (FloorProperties fp in selectedFloors)
                            {
                                using (Transaction trans = new Transaction(m_doc))
                                {
                                    trans.Start("Create 2D Mass");
                                    var options = trans.GetFailureHandlingOptions();
                                    options.SetFailuresPreprocessor(new DuplicateWarningSwallower());
                                    trans.SetFailureHandlingOptions(options);

                                    try
                                    {
                                        MassProperties createdMass = null;
                                        if (MassCreator.CreateFloorFace(m_doc, fp, out createdMass))
                                        {
                                            if (floorDictionary.ContainsKey(fp.FloorUniqueId))
                                            {
                                                FloorProperties updatedFloor = new FloorProperties(fp);
                                                updatedFloor.IsSelected   = false;
                                                updatedFloor.Linked2d     = true;
                                                updatedFloor.Linked2dMass = createdMass;
                                                updatedFloor.ModifiedHost = false;
                                                if (updatedFloor.Linked3d && null != updatedFloor.Linked3dMass)
                                                {
                                                    updatedFloor.ToolTip  = "Mass 3D Id: " + updatedFloor.Linked3dMass.MassId;
                                                    updatedFloor.ToolTip += "\nMass 2D Id: " + updatedFloor.Linked2dMass.MassId;
                                                }
                                                else
                                                {
                                                    updatedFloor.ToolTip = "Mass 2D Id: " + updatedFloor.Linked2dMass.MassId;
                                                }

                                                if (createdParamMaps)
                                                {
                                                    bool parameterUpdated = UpdateParameter(fp.FloorElement, createdMass.MassElement);
                                                }
                                                floorDictionary.Remove(fp.FloorUniqueId);
                                                floorDictionary.Add(fp.FloorUniqueId, updatedFloor);
                                            }
                                        }
                                        trans.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        trans.RollBack();
                                        string message = ex.Message;
                                    }
                                }

                                count++;
                                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, count });
                            }

                            DisplayFloorInfo();
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            tg.RollBack();
                            MessageBox.Show("Failed to create masses from the selected floors\n" + ex.Message, "Create 3D Masses from Floors", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    progressBar.Visibility = System.Windows.Visibility.Hidden;
                    statusLable.Text       = "Ready";
                }
                else
                {
                    MessageBox.Show("Please select floors to update masses.", "Select Floors", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create masses from the selected floors.\n" + ex.Message, "Create 3D Masses from Floors", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void CollectFloorsInfo(List <Floor> floorList, Autodesk.Revit.DB.Transform floorTransform)
        {
            try
            {
                foreach (Floor floor in floorList)
                {
                    FloorProperties fp = new FloorProperties(floor);
                    fp.GetFloorGeometry(floorTransform);

                    StringBuilder strBuilder  = new StringBuilder();
                    var           mass3dFound = from mass in massList
                                                where mass.HostType == SourceType.Floors && mass.HostUniqueId == fp.FloorUniqueId && mass.MassElementType == MassType.MASS3D
                                                select mass;
                    if (mass3dFound.Count() > 0)
                    {
                        MassProperties mp = mass3dFound.First();
                        fp.Linked3dMass = mp;
                        fp.Linked3d     = true;
                        fp.UserHeight   = mp.MassHeight;
                        strBuilder.AppendLine("Mass 3D Id: " + mp.MassId);
                        if (null != mp.MassSolid)
                        {
                            if (!fp.FloorSolidCentroid.IsAlmostEqualTo(mp.HostSolidCentroid))
                            {
                                fp.ModifiedHost = true;
                                strBuilder.Append(" (the floor has been modified)");
                            }
                        }
                    }

                    var mass2dFound = from mass in massList
                                      where mass.HostType == SourceType.Floors && mass.HostUniqueId == fp.FloorUniqueId && mass.MassElementType == MassType.MASS2D
                                      select mass;
                    if (mass2dFound.Count() > 0)
                    {
                        MassProperties mp = mass2dFound.First();
                        fp.Linked2dMass = mp;
                        fp.Linked2d     = true;
                        strBuilder.AppendLine("Mass 2D Id: " + mp.MassId);
                        if (null != mp.MassSolid)
                        {
                            if (!fp.FloorSolidCentroid.IsAlmostEqualTo(mp.HostSolidCentroid))
                            {
                                fp.ModifiedHost = true;
                                strBuilder.Append(" (the floor has been modified)");
                            }
                        }
                    }

                    if (strBuilder.Length > 0)
                    {
                        fp.ToolTip = strBuilder.ToString();
                    }

                    if (!floorDictionary.ContainsKey(fp.FloorUniqueId))
                    {
                        floorDictionary.Add(fp.FloorUniqueId, fp);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect floors Information.\n" + ex.Message, "Collect Floors Information", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void CollectAreaInfo(List <Area> areaList)
        {
            try
            {
                foreach (Area area in areaList)
                {
                    if (area.Area == 0)
                    {
                        continue;
                    }

                    AreaProperties ap = new AreaProperties(area);
                    ap.GetAreaProfile();

                    StringBuilder strBuilder  = new StringBuilder();
                    var           mass3dFound = from mass in massList
                                                where mass.HostType == SourceType.Areas && mass.HostUniqueId == ap.AreaUniqueId && mass.MassElementType == MassType.MASS3D
                                                select mass;
                    if (mass3dFound.Count() > 0)
                    {
                        MassProperties mp = mass3dFound.First();
                        ap.Linked3dMass = mp;
                        ap.Linked3d     = true;
                        ap.UserHeight   = mp.MassHeight;
                        strBuilder.AppendLine("Mass 3D Id: " + mp.MassId);
                        if (null != mp.MassSolid)
                        {
                            if (!ap.AreaCenterPoint.IsAlmostEqualTo(mp.HostSolidCentroid))
                            {
                                ap.ModifiedHost = true;
                                strBuilder.Append(" (the area has been modified)");
                            }
                        }
                    }

                    var mass2dFound = from mass in massList
                                      where mass.HostType == SourceType.Areas && mass.HostUniqueId == ap.AreaUniqueId && mass.MassElementType == MassType.MASS2D
                                      select mass;
                    if (mass2dFound.Count() > 0)
                    {
                        MassProperties mp = mass2dFound.First();
                        ap.Linked2dMass = mp;
                        ap.Linked2d     = true;
                        strBuilder.AppendLine("Mass 2D Id: " + mp.MassId);
                        if (null != mp.MassSolid)
                        {
                            if (!ap.AreaCenterPoint.IsAlmostEqualTo(mp.HostSolidCentroid))
                            {
                                ap.ModifiedHost = true;
                                strBuilder.Append(" (the area has been modified)");
                            }
                        }
                    }

                    if (strBuilder.Length > 0)
                    {
                        ap.ToolTip = strBuilder.ToString();
                    }

                    if (!areaDictionary.ContainsKey(ap.AreaUniqueId))
                    {
                        areaDictionary.Add(ap.AreaUniqueId, ap);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect area Information.\n" + ex.Message, "Collect Areas Information", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        private void CollectRoomsInfo(List <Room> roomList, Autodesk.Revit.DB.Transform roomTransform)
        {
            try
            {
                foreach (Room room in roomList)
                {
                    if (room.Area == 0)
                    {
                        continue;
                    }

                    RoomProperties rp = new RoomProperties(room);
                    rp.GetRoomGeometry(roomTransform);

                    StringBuilder strBuilder  = new StringBuilder();
                    var           mass3dFound = from mass in massList
                                                where mass.HostType == SourceType.Rooms && mass.HostUniqueId == rp.RoomUniqueId && mass.MassElementType == MassType.MASS3D
                                                select mass;
                    if (mass3dFound.Count() > 0)
                    {
                        MassProperties mp = mass3dFound.First();
                        rp.Linked3dMass = mp;
                        rp.Linked3d     = true;
                        rp.UserHeight   = mp.MassHeight;
                        strBuilder.AppendLine("Mass 3D Id: " + mp.MassId);
                        if (null != mp.MassSolid)
                        {
                            if (!rp.RoomSolidCentroid.IsAlmostEqualTo(mp.HostSolidCentroid))
                            {
                                rp.ModifiedHost = true;
                                strBuilder.Append(" (the room has been modified)");
                            }
                        }
                    }

                    var mass2dFound = from mass in massList
                                      where mass.HostType == SourceType.Rooms && mass.HostUniqueId == rp.RoomUniqueId && mass.MassElementType == MassType.MASS2D
                                      select mass;
                    if (mass2dFound.Count() > 0)
                    {
                        MassProperties mp = mass2dFound.First();
                        rp.Linked2dMass = mp;
                        rp.Linked2d     = true;
                        strBuilder.AppendLine("Mass 2D Id: " + mp.MassId);
                        if (null != mp.MassSolid)
                        {
                            if (!rp.RoomSolidCentroid.IsAlmostEqualTo(mp.HostSolidCentroid))
                            {
                                rp.ModifiedHost = true;
                                strBuilder.Append(" (the room has been modified)");
                            }
                        }
                    }

                    if (strBuilder.Length > 0)
                    {
                        rp.ToolTip = strBuilder.ToString();
                    }

                    if (!roomDictionary.ContainsKey(rp.RoomUniqueId))
                    {
                        roomDictionary.Add(rp.RoomUniqueId, rp);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to collect rooms Information.\n" + ex.Message, "Collect Rooms Information", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
示例#9
0
        private void bttnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                List <int> checkedRows = new List <int>();
                for (int i = 0; i < dataGridViewArea.Rows.Count; i++)
                {
                    if (Convert.ToBoolean(dataGridViewArea.Rows[i].Cells[0].Value))
                    {
                        checkedRows.Add(i);
                    }
                }

                if (checkedRows.Count > 0)
                {
                    double height = 0;
                    if (checkBoxHeight.Checked)
                    {
                        if (!ValidateHeight(out height))
                        {
                            MessageBox.Show("Please enter a valid area height.", "Area Height Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        else if (height == 0)
                        {
                            MessageBox.Show("Please enter a valid area height.", "Area Height Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }

                    massCreator.DefDictionary = defDictionary;

                    SaveHeightValues();
                    Dictionary <int, AreaProperties> createdAreas = new Dictionary <int, AreaProperties>();
                    Dictionary <int, MassProperties> placedMasses = new Dictionary <int, MassProperties>();

                    statusLabel.Text             = "Updating Masses . . .";
                    toolStripProgressBar.Maximum = checkedRows.Count;
                    toolStripProgressBar.Visible = true;

                    StringBuilder resultMessage = new StringBuilder();

                    foreach (int index in checkedRows)
                    {
                        toolStripProgressBar.PerformStep();
                        DataGridViewRow row = dataGridViewArea.Rows[index];
                        if (null != row.Tag)
                        {
                            AreaProperties ap = row.Tag as AreaProperties;
                            MassProperties mp = new MassProperties();
                            mp.HostElementId = ap.ID;
                            if (placedAreas.Contains(ap.ID))
                            {
                                FamilyInstance instance = MassUtils.FindMassById(doc, ap.ID);
                                if (null != instance)
                                {
                                    mp.MassFamilyInstance = instance;

                                    if (!placedMasses.ContainsKey(ap.ID))
                                    {
                                        placedMasses.Add(ap.ID, mp);
                                    }
                                    resultMessage.AppendLine(ap.ID + "\t" + ap.Number + "\t" + ap.Name);
                                }
                                continue;
                            }

                            if (areaDiscrepancy.Contains(ap.ID))
                            {
                                FamilyInstance instance = MassUtils.FindMassById(doc, ap.ID);
                                if (null != instance)
                                {
                                    using (Transaction trans = new Transaction(doc))
                                    {
                                        trans.Start("Delete Element");
                                        doc.Delete(instance.Id);
                                        trans.Commit();
                                    }
                                }
                            }

                            FamilyInstance familyInstance = massCreator.CreateFamily(ap);
                            if (null != familyInstance)
                            {
                                mp.MassFamilyInstance = familyInstance;
                                if (!placedMasses.ContainsKey(ap.ID))
                                {
                                    placedMasses.Add(ap.ID, mp);
                                }
                            }
                            createdAreas.Add(ap.ID, ap);
                            resultMessage.AppendLine(ap.ID + "\t" + ap.Number + "\t" + ap.Name);
                        }
                    }

                    foreach (int areaId in placedAreas)
                    {
                        FamilyInstance instance = MassUtils.FindMassById(doc, areaId);
                        MassProperties mp       = new MassProperties();
                        if (null != instance)
                        {
                            mp.MassFamilyInstance = instance;
                            if (!placedMasses.ContainsKey(areaId))
                            {
                                placedMasses.Add(areaId, mp);
                            }
                        }
                    }

                    statusLabel.Text            = "Done";
                    iniDataManager.CreatedAreas = createdAreas;
                    iniDataManager.WriteINI();

                    if (massCreator.FailureMessage.Length > 0)
                    {
                        DialogResult dr = MessageBox.Show("Errors occured while creating extrusion forms.\n" + massCreator.FailureMessage.ToString(), "Warning Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        if (dr == DialogResult.OK)
                        {
                            using (Transaction trans = new Transaction(doc))
                            {
                                trans.Start("Set Shared Parameters");
                                m_app.Application.SharedParametersFilename = originalDefFile;
                                trans.Commit();
                            }
                            this.Close();
                        }
                    }
                    else
                    {
                        if (resultMessage.Length > 0)
                        {
                            string         header      = "Area Masses are sucessfully created. \n[Area ID], [Area Number], [Area Name]\n";
                            MessageBoxForm messageForm = new MessageBoxForm("Completion Messages", header + resultMessage.ToString(), "", false, false);
                            if (DialogResult.OK == messageForm.ShowDialog())
                            {
                                using (Transaction trans = new Transaction(doc))
                                {
                                    trans.Start("Set Shared parameters");
                                    m_app.Application.SharedParametersFilename = originalDefFile;
                                    trans.Commit();
                                }
                                this.Close();
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select at leaset one Area item to proceed.", "Empty Selection", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create mass rooms.\n" + ex.Message, "Form_CreateMass:BttnCreate_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#10
0
        private void buttonCreate_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool   useDefaultHeight = (bool)checkBoxDefaultHeight.IsChecked;
                double defaultHeight    = 0;
                if (useDefaultHeight)
                {
                    if (!ValidateInput(out defaultHeight))
                    {
                        return;
                    }
                }

                List <RoomProperties> roomList = (List <RoomProperties>)dataGridRoom.ItemsSource;
                var roomsFound = from room in roomList where room.IsSelected select room;
                List <RoomProperties> selectedRooms = roomsFound.ToList();
                if (selectedRooms.Count > 0)
                {
                    statusLable.Text       = "Creating 3D Masses ..";
                    progressBar.Visibility = System.Windows.Visibility.Visible;
                    progressBar.Value      = 0;
                    progressBar.Maximum    = selectedRooms.Count;

                    bool createdParamMaps = (massConfig.UpdateType != ParameterUpdateType.None && massConfig.MassParameters.Count > 0) ? true : false;

                    UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
                    using (TransactionGroup tg = new TransactionGroup(m_doc))
                    {
                        tg.Start("Create 3D Masses");
                        try
                        {
                            double count = 0;
                            for (int i = 0; i < selectedRooms.Count; i++)
                            {
                                RoomProperties rp = selectedRooms[i];
                                if (useDefaultHeight)
                                {
                                    rp.UserHeight = defaultHeight;
                                }
                                using (Transaction trans = new Transaction(m_doc))
                                {
                                    trans.Start("Create 3D Mass");
                                    var options = trans.GetFailureHandlingOptions();
                                    options.SetFailuresPreprocessor(new DuplicateWarningSwallower());
                                    trans.SetFailureHandlingOptions(options);

                                    try
                                    {
                                        MassProperties createdMass = null;
                                        if (MassCreator.CreateRoomSolid(m_doc, rp, out createdMass))
                                        {
                                            if (roomDictionary.ContainsKey(rp.RoomUniqueId))
                                            {
                                                RoomProperties updatedRoom = new RoomProperties(rp);
                                                updatedRoom.IsSelected   = false;
                                                updatedRoom.Linked3d     = true;
                                                updatedRoom.Linked3dMass = createdMass;
                                                updatedRoom.ModifiedHost = false;
                                                updatedRoom.ToolTip      = "Mass 3D Id: " + createdMass.MassId;
                                                if (updatedRoom.Linked2d && null != updatedRoom.Linked2dMass)
                                                {
                                                    updatedRoom.ToolTip += "\nMass 2D Id: " + updatedRoom.Linked2dMass.MassId;
                                                }

                                                if (createdParamMaps)
                                                {
                                                    bool parameterUpdated = UpdateParameter(rp.RoomElement, createdMass.MassElement);
                                                }
                                                roomDictionary.Remove(rp.RoomUniqueId);
                                                roomDictionary.Add(rp.RoomUniqueId, updatedRoom);
                                            }
                                        }
                                        trans.Commit();
                                    }
                                    catch (Exception ex)
                                    {
                                        trans.RollBack();
                                        string message = ex.Message;
                                    }
                                }

                                count++;
                                Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, count });
                            }

                            DisplayRoomInfo();
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            tg.RollBack();
                            MessageBox.Show("Failed to create masses from the selected rooms\n" + ex.Message, "Create 3D Masses from Rooms", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }

                    progressBar.Visibility = System.Windows.Visibility.Hidden;
                    statusLable.Text       = "Ready";
                }
                else
                {
                    MessageBox.Show("Please select rooms to update masses.", "Select Rooms", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create 3d masses from the selected rooms.\n" + ex.Message, "Create 3D Masses from Rooms", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
示例#11
0
        private void bttnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                List <int> checkedRows = new List <int>();
                for (int i = 0; i < dataGridViewRoom.Rows.Count; i++)
                {
                    if (Convert.ToBoolean(dataGridViewRoom.Rows[i].Cells[0].Value))
                    {
                        checkedRows.Add(i);
                    }
                }

                if (checkedRows.Count > 0)
                {
                    using (TransactionGroup tg = new TransactionGroup(doc))
                    {
                        tg.Start("Update Masses");
                        try
                        {
                            double height = 0;
                            if (checkBoxHeight.Checked)
                            {
                                if (!ValidateHeight(out height))
                                {
                                    MessageBox.Show("Please enter a valid room height.", "Room Height Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                                else if (height == 0)
                                {
                                    MessageBox.Show("Please enter a valid room height.", "Room Height Required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    return;
                                }
                            }

                            massCreator.DefDictionary = defDictionary;

                            Dictionary <int, RoomProperties> createdRooms = new Dictionary <int, RoomProperties>(); //created rooms at this run
                            Dictionary <int, MassProperties> placedMasses = new Dictionary <int, MassProperties>();

                            statusLabel.Text             = "Updating Masses . . .";
                            toolStripProgressBar.Maximum = checkedRows.Count;
                            toolStripProgressBar.Visible = true;

                            StringBuilder resultMessage = new StringBuilder();

                            foreach (int index in checkedRows)
                            {
                                toolStripProgressBar.PerformStep();
                                DataGridViewRow row = dataGridViewRoom.Rows[index];
                                if (null != row.Tag)
                                {
                                    RoomProperties rp = row.Tag as RoomProperties;
                                    MassProperties mp = new MassProperties();
                                    mp.HostElementId   = rp.ID;
                                    rp.IsDefaultHeight = checkBoxHeight.Checked;
                                    rp.DefaultHeight   = height;

                                    if (placedRooms.Contains(rp.ID))
                                    {
                                        FamilyInstance instance = MassUtils.FindMassById(doc, rp.ID);
                                        if (null != instance)
                                        {
                                            mp.MassFamilyInstance = instance;
                                            double roomHeight = (rp.IsDefaultHeight == true) ? rp.DefaultHeight : rp.UnboundedHeight;
#if RELEASE2015 || RELEASE2016
                                            Parameter parameter = instance.LookupParameter("Height");
#elif RELEASE2013 || RELEASE2014
                                            Parameter parameter = instance.get_Parameter("Height");
#endif

                                            if (null != parameter)
                                            {
                                                using (Transaction trans = new Transaction(doc))
                                                {
                                                    trans.Start("Update Height");
                                                    try
                                                    {
                                                        parameter.Set(roomHeight);
                                                        trans.Commit();
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        string message = ex.Message;
                                                        trans.RollBack();
                                                    }
                                                }
                                            }

                                            if (!placedMasses.ContainsKey(rp.ID))
                                            {
                                                placedMasses.Add(rp.ID, mp);
                                            }

                                            resultMessage.AppendLine(rp.ID + "\t" + rp.Number + "\t" + rp.Name);
                                        }
                                        continue;
                                    }

                                    if (roomDiscrepancy.Contains(rp.ID))
                                    {
                                        FamilyInstance instance = MassUtils.FindMassById(doc, rp.ID);
                                        if (null != instance)
                                        {
                                            using (Transaction trans = new Transaction(doc))
                                            {
                                                trans.Start("Delete Element");
                                                doc.Delete(instance.Id);
                                                trans.Commit();
                                            }
                                        }
                                    }

                                    FamilyInstance familyInstance = massCreator.CreateFamily(rp);
                                    if (null != familyInstance)
                                    {
                                        mp.MassFamilyInstance = familyInstance;
                                        if (!placedMasses.ContainsKey(rp.ID))
                                        {
                                            placedMasses.Add(rp.ID, mp);
                                        }
                                    }

                                    createdRooms.Add(rp.ID, rp);
                                    resultMessage.AppendLine(rp.ID + "\t" + rp.Number + "\t" + rp.Name);
                                }
                            }
                            //to include placed masses from the previous run into the snapshot.png
                            foreach (int roomId in placedRooms)
                            {
                                FamilyInstance instance = MassUtils.FindMassById(doc, roomId);
                                MassProperties mp       = new MassProperties();
                                if (null != instance)
                                {
                                    mp.MassFamilyInstance = instance;
                                    if (!placedMasses.ContainsKey(roomId))
                                    {
                                        placedMasses.Add(roomId, mp);
                                    }
                                }
                            }

                            statusLabel.Text             = "Done";
                            roomDataManager.CreatedRooms = createdRooms;
                            roomDataManager.WriteINI();
                            if (massCreator.FailureMessage.Length > 0)
                            {
                                DialogResult dr = MessageBox.Show("Errors occured while creating extrusion forms.\n" + massCreator.FailureMessage.ToString(), "Warning Messages", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                if (dr == DialogResult.OK)
                                {
                                    using (Transaction trans = new Transaction(doc))
                                    {
                                        trans.Start("Set Shared Parameters");
                                        m_app.Application.SharedParametersFilename = originalDefFile;
                                        trans.Commit();
                                    }

                                    this.Close();
                                }
                            }
                            else
                            {
                                if (resultMessage.Length > 0)
                                {
                                    string         header      = "Room Masses are sucessfully updated. \n[Room ID], [Room Number], [Room Name]\n";
                                    MessageBoxForm messageForm = new MessageBoxForm("Completion Messages", header + resultMessage.ToString(), "", false, false);
                                    if (DialogResult.OK == messageForm.ShowDialog())
                                    {
                                        using (Transaction trans = new Transaction(doc))
                                        {
                                            trans.Start("Set Shared Parameters");
                                            m_app.Application.SharedParametersFilename = originalDefFile;
                                            trans.Commit();
                                        }
                                        this.Close();
                                    }
                                }
                            }
                            tg.Assimilate();
                        }
                        catch (Exception ex)
                        {
                            tg.RollBack();
                            MessageBox.Show("Failed to update masses from rooms.\n" + ex.Message, "Create Masses from Rooms", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Please select at leaset one Room item to proceed.", "Empty Selection", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create mass rooms.\n" + ex.Message, "Form_CreateMass:BttnCreate_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }