private void menuItemCheck_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (null != dataGridFloor.SelectedItems)
         {
             foreach (var selectedItem in dataGridFloor.SelectedItems)
             {
                 FloorProperties selectedFloor = (FloorProperties)selectedItem;
                 if (floorDictionary.ContainsKey(selectedFloor.FloorUniqueId))
                 {
                     FloorProperties fp = floorDictionary[selectedFloor.FloorUniqueId];
                     fp.IsSelected = true;
                     floorDictionary.Remove(fp.FloorUniqueId);
                     floorDictionary.Add(fp.FloorUniqueId, fp);
                 }
             }
             DisplayFloorInfo();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to check selected items.\n" + ex.Message, "Check Selected Items", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
示例#2
0
        private void CollectFloors()
        {
            try
            {
                progressForm            = new Form_ProgressBar();
                progressForm.LabelText  = "Collecting Information from the Revit Project..";
                progressForm.LabelCount = collectedFloors.Count + " floors found";
                progressForm.Show();
                progressForm.MaxValue = collectedFloors.Count;
                progressForm.Refresh();

                foreach (Floor floor in collectedFloors)
                {
                    progressForm.PerformStep();
                    FloorProperties fp = new FloorProperties(doc, floor);
                    if (!floorDictionary.ContainsKey(fp.ID))
                    {
                        floorDictionary.Add(fp.ID, fp);
                        if (!levelNames.Contains(fp.Level))
                        {
                            levelNames.Add(fp.Level);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                progressForm.Close();
                MessageBox.Show("Failed to collect Floors data. \n" + ex.Message, "Form_FloorMass:CollectFloors", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#3
0
 public FloorProperties(FloorProperties fp)
 {
     this.FloorElement       = fp.FloorElement;
     this.FloorDocument      = fp.FloorDocument;
     this.FloorElementId     = fp.FloorElementId;
     this.FloorId            = fp.FloorId;
     this.FloorUniqueId      = fp.FloorUniqueId;
     this.FloorName          = fp.FloorName;
     this.FloorTypeName      = fp.FloorTypeName;
     this.UserHeight         = fp.UserHeight;
     this.LevelId            = fp.LevelId;
     this.LevelName          = fp.LevelName;
     this.PhaseId            = fp.PhaseId;
     this.PhaseName          = fp.PhaseName;
     this.FloorDesignOption  = fp.FloorDesignOption;
     this.FloorSolid         = fp.FloorSolid;
     this.FloorSolidCentroid = fp.FloorSolidCentroid;
     this.FloorProfiles      = fp.FloorProfiles;
     this.Linked3dMass       = fp.Linked3dMass;
     this.Linked2dMass       = fp.Linked2dMass;
     this.Linked3d           = fp.Linked3d;
     this.Linked2d           = fp.Linked2d;
     this.ModifiedHost       = fp.ModifiedHost;
     this.IsSelected         = fp.IsSelected;
     this.ToolTip            = fp.ToolTip;
 }
示例#4
0
        public static bool CreateFloorSolid(Document doc, FloorProperties fp, out MassProperties createdMass)
        {
            bool created = false;

            createdMass = null;
            try
            {
                string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString();
                if (null != fp.Linked3dMass)
                {
                    //delete existing mass first
                    MassProperties existingMass = fp.Linked3dMass;
                    doc.Delete(new ElementId(existingMass.MassId));
                }

                IList <GeometryObject> floorGeometries = new List <GeometryObject>();
                if (fp.FloorProfiles.Count > 0)
                {
                    XYZ   extrusionDir = new XYZ(0, 0, 1);
                    Solid floorSolid   = GeometryCreationUtilities.CreateExtrusionGeometry(fp.FloorProfiles, extrusionDir, fp.UserHeight);
                    if (null != floorSolid)
                    {
                        floorGeometries.Add(floorSolid);
                    }
                }
#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.SetHostInfo(fp.FloorUniqueId, SourceType.Floors, fp.FloorSolidCentroid, fp.UserHeight);
                    bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Floors.ToString(), fp.FloorUniqueId, fp.FloorSolidCentroid, fp.UserHeight);
                    created = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create room solid.\n" + ex.Message, "Create Room Solid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(created);
        }
示例#5
0
        private void menuViewElement_Click(object sender, EventArgs e)
        {
            using (Transaction trans = new Transaction(doc))
            {
                trans.Start("Show Elements");
                try
                {
                    UIDocument       uidoc      = m_app.ActiveUIDocument;
                    List <ElementId> elementIds = new List <ElementId>();

#if RELEASE2013 || RELEASE2014
                    SelElementSet newSelection = SelElementSet.Create();

                    foreach (DataGridViewRow row in dataGridViewFloor.SelectedRows)
                    {
                        if (null != row.Tag)
                        {
                            FloorProperties fp        = row.Tag as FloorProperties;
                            ElementId       elementId = new ElementId(fp.ID);
                            Element         element   = doc.GetElement(elementId);
                            if (null != element)
                            {
                                newSelection.Add(element);
                                elementIds.Add(elementId);
                            }
                        }
                    }
                    uidoc.ShowElements(elementIds);
                    uidoc.Selection.Elements = newSelection;
#elif RELEASE2015 || RELEASE2016
                    Selection selection = uidoc.Selection;
                    foreach (DataGridViewRow row in dataGridViewFloor.SelectedRows)
                    {
                        if (null != row.Tag)
                        {
                            FloorProperties fp        = row.Tag as FloorProperties;
                            ElementId       elementId = new ElementId(fp.ID);
                            Element         element   = doc.GetElement(elementId);
                            if (null != element)
                            {
                                elementIds.Add(elementId);
                            }
                        }
                    }
                    uidoc.ShowElements(elementIds);
                    selection.SetElementIds(elementIds);
#endif
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to view elements.\n" + ex.Message, "Form_FloorMass: menuViewElement_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    trans.RollBack();
                }
            }
        }
示例#6
0
 private void SaveHeightValues()
 {
     try
     {
         foreach (DataGridViewRow row in dataGridViewFloor.Rows)
         {
             if (null != row.Tag && null != row.Cells[7].Value)
             {
                 FloorProperties fp = row.Tag as FloorProperties;
                 fp.Height = Convert.ToDouble(row.Cells[7].Value);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Failed to save height values.\n" + ex.Message, "Form_FloorMass:SaveHeightValues", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        private void menuItem2dMassView_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != dataGridFloor.SelectedItems)
                {
                    List <ElementId> selectedIds = new List <ElementId>();
                    foreach (var selectedItem in dataGridFloor.SelectedItems)
                    {
                        FloorProperties selectedFloor = (FloorProperties)selectedItem;
                        if (null != selectedFloor.Linked2dMass)
                        {
                            selectedIds.Add(selectedFloor.Linked2dMass.MassElement.Id);
                        }
                    }

                    if (selectedIds.Count > 0)
                    {
                        using (Transaction trans = new Transaction(m_doc))
                        {
                            trans.Start("Select Elements");
                            try
                            {
                                UIDocument uidoc     = m_app.ActiveUIDocument;
                                Selection  selection = uidoc.Selection;
                                uidoc.ShowElements(selectedIds);
                                selection.SetElementIds(selectedIds);

                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                string message = ex.Message;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to view 2d mass elements in the background.\n" + ex.Message, "View Selected Elements", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public void FindDiscrepancyOfFloor()
        {
            try
            {
                //find placed mass
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                IList <Element>          floorMass = collector.OfCategory(BuiltInCategory.OST_Mass).WhereElementIsNotElementType().ToElements().ToList();

                foreach (Element element in floorMass)
                {
                    FamilyInstance fi = element as FamilyInstance;
                    if (null != fi)
                    {
                        int floorId = 0;
                        if (fi.Symbol.Family.Name.Length > 5 && int.TryParse(fi.Symbol.Family.Name, out floorId))
                        {
                            //compare existing centroid
                            if (floorCenters.ContainsKey(floorId))
                            {
                                ElementId       elementId    = new ElementId(floorId);
                                Element         floorElement = doc.GetElement(elementId);
                                Floor           floor        = floorElement as Floor;
                                FloorProperties fp           = new FloorProperties(doc, floor);
                                if (fp.FloorCenter.IsAlmostEqualTo(floorCenters[floorId]))
                                {
                                    placedFloors.Add(floorId);
                                    continue;
                                }
                                else
                                {
                                    floorDiscrepancy.Add(floorId);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find discrepancy\n" + ex.Message, "INIDataManager:FindDiscrepancyOfFloor", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#9
0
        private bool CreateExtrusion(Document fdoc, FloorProperties fp)
        {
            bool result = false;

            try
            {
                if (true == fdoc.IsFamilyDocument)
                {
                    double maxCircum = 0;//to find out the largest outer loop.
                    List <ReferenceArray> profiles = new List <ReferenceArray>();

                    foreach (EdgeArray edgeArray in fp.EdgeArrayArray)
                    {
                        Curve          curve         = null;
                        List <XYZ>     pointList     = new List <XYZ>();
                        ReferenceArray refArray      = new ReferenceArray();
                        bool           first         = true;
                        double         circumference = 0;

                        foreach (Edge edge in edgeArray)
                        {
                            circumference += edge.ApproximateLength;
                            int pointCount = edge.Tessellate().Count;
                            if (pointCount > 2)//edge from a circular face
                            {
                                IList <XYZ> tPoints = edge.Tessellate();
                                tPoints.RemoveAt(tPoints.Count - 1);
                                foreach (XYZ point in tPoints)
                                {
                                    XYZ tempPoint = new XYZ(point.X, point.Y, 0);
                                    pointList.Add(tempPoint);
                                }
                            }
                            else if (pointCount == 2)
                            {
                                curve = edge.AsCurve();
#if RELEASE2013
                                XYZ point = curve.get_EndPoint(0);
#elif RELEASE2014 || RELEASE2015 || RELEASE2016
                                XYZ point = curve.GetEndPoint(0);
#endif
                                XYZ tempPoint = new XYZ(point.X, point.Y, 0);
                                if (first)
                                {
                                    pointList.Add(tempPoint); first = false;
                                }
                                else if (pointList[pointList.Count - 1].DistanceTo(tempPoint) > 0.0026)
                                {
                                    pointList.Add(tempPoint);
                                }
                            }
                        }

                        if (maxCircum == 0)
                        {
                            maxCircum = circumference;
                        }
                        else if (maxCircum < circumference)
                        {
                            maxCircum = circumference;
                        }

                        int num = pointList.Count;
                        if (num > 0)
                        {
                            Plane plane = fdoc.Application.Create.NewPlane(XYZ.BasisZ, new XYZ(0, 0, 0));
#if RELEASE2013
                            SketchPlane skPlane = fdoc.FamilyCreate.NewSketchPlane(plane);
#elif RELEASE2014 || RELEASE2015 || RELEASE2016
                            SketchPlane skPlane = SketchPlane.Create(fdoc, plane);
#endif

                            for (int i = 0; i < num; i++)
                            {
                                if (i == num - 1)
                                {
#if RELEASE2013
                                    curve = fdoc.Application.Create.NewLineBound(pointList[i], pointList[0]);
#elif RELEASE2014 || RELEASE2015 || RELEASE2016
                                    curve = Autodesk.Revit.DB.Line.CreateBound(pointList[i], pointList[0]);
#endif
                                }
                                else
                                {
#if RELEASE2013
                                    curve = fdoc.Application.Create.NewLineBound(pointList[i], pointList[i + 1]);
#elif RELEASE2014 || RELEASE2015 || RELEASE2016
                                    curve = Autodesk.Revit.DB.Line.CreateBound(pointList[i], pointList[i + 1]);
#endif
                                }
                                ModelCurve modelCurve = fdoc.FamilyCreate.NewModelCurve(curve, skPlane);
                                refArray.Append(modelCurve.GeometryCurve.Reference);
                            }
                            //first index of profile list will be the outer loop
                            if (maxCircum == circumference)
                            {
                                profiles.Insert(0, refArray);
                            }
                            else
                            {
                                profiles.Add(refArray);
                            }
                        }
                    }

                    if (profiles.Count > 0)
                    {
                        XYZ             direction = new XYZ(0, 0, fp.Height);
                        FamilyParameter fparam    = fdoc.FamilyManager.get_Parameter("Height");
                        fdoc.FamilyManager.Set(fparam, fp.Height);

                        for (int i = 0; i < profiles.Count; i++)
                        {
                            Autodesk.Revit.DB.Form solidForm = fdoc.FamilyCreate.NewExtrusionForm(true, profiles[i], direction);
                            CreateHeightLabel(fdoc, solidForm);

                            if (i > 0)
                            {
                                Parameter param = solidForm.get_Parameter(BuiltInParameter.ELEMENT_IS_CUTTING);
                                param.Set(1); //void form
                            }
                        }
                    }
                    result = true;
                }
                else
                {
                    result = false;
                    throw new Exception("Please open a Family document before invoking this command.");
                }
                return(result);
            }
            catch (Exception ex)
            {
                result = false;
                MessageBox.Show("Failed to create an extruded form.\n\nFloorName: " + fp.TypeName + "  FloorLevel: " + fp.Level + "\nBoundary lines of floor cannot create a profile..\n\n" + ex.Message, "MassCreator: CreateExtrusion", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(result);
            }
        }
示例#10
0
        public FamilyInstance CreateFamily(FloorProperties fp)
        {
            FamilyInstance familyInstance = null;

            try
            {
                string   currentAssembly = System.Reflection.Assembly.GetAssembly(this.GetType()).Location;
                string   massTemplate    = Path.GetDirectoryName(currentAssembly) + "/Resources/Mass.rfa";
                Document familyDoc       = null;
                using (Transaction trans = new Transaction(doc))
                {
                    trans.Start("Open Document");
                    familyDoc = m_app.OpenDocumentFile(massTemplate);
                    trans.Commit();
                }

                if (null != familyDoc)
                {
                    bool createdParam = false;
                    using (Transaction trans = new Transaction(familyDoc))
                    {
                        FailureHandlingOptions failureHandlingOptions = trans.GetFailureHandlingOptions();
                        FailureHandler         failureHandler         = new FailureHandler();
                        failureHandlingOptions.SetFailuresPreprocessor(failureHandler);
                        failureHandlingOptions.SetClearAfterRollback(true);
                        trans.SetFailureHandlingOptions(failureHandlingOptions);

                        trans.Start("Create Extrusion");
                        try
                        {
                            FamilyType newFamilyType = familyDoc.FamilyManager.NewType(fp.TypeName);
                            bool       createdMass   = CreateExtrusion(familyDoc, fp);

                            Dictionary <string, Parameter> parameters = new Dictionary <string, Parameter>();
                            parameters = fp.Parameters;
                            if (createdMass)
                            {
                                createdParam = CreateNewParameters(familyDoc, parameters);
                            }

                            if (failureHandler.FailureMessageInfoList.Count > 0)
                            {
                                failureMessage.AppendLine("[" + fp.ID + ": " + fp.TypeName + "] :" + failureHandler.FailureMessageInfoList[0].ErrorMessage);
                            }
                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Failed to create family.\n" + ex.Message, "MassCreator: CreateFamily", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            trans.RollBack();
                        }
                    }
                    if (createdParam)
                    {
                        SaveAsOptions opt = new SaveAsOptions();
                        opt.OverwriteExistingFile = true;
                        string fileName = Path.Combine(massFolder, fp.ID + ".rfa");
                        familyDoc.SaveAs(fileName, opt);
                        familyDoc.Close(true);
                        familyInstance = LoadMassFamily(fileName, fp.LevelObj);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create family.\n" + ex.Message, "MassCreator: CreateFamily", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(familyInstance);
        }
        private void buttonUpdateParameters_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (massConfig.UpdateType != ParameterUpdateType.None && massConfig.MassParameters.Count > 0)
                {
                    List <FloorProperties> floorList = (List <FloorProperties>)dataGridFloor.ItemsSource;
                    var selectedFloors = from floor in floorList where floor.IsSelected select floor;

                    if (selectedFloors.Count() > 0)
                    {
                        statusLable.Text       = "Updating Parameters ...";
                        progressBar.Visibility = System.Windows.Visibility.Visible;
                        progressBar.Value      = 0;
                        progressBar.Maximum    = selectedFloors.Count();

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

                                        try
                                        {
                                            bool updated = false;
                                            if (null != fp.Linked2dMass)
                                            {
                                                updated = UpdateParameter(fp.FloorElement, fp.Linked2dMass.MassElement);
                                            }
                                            if (null != fp.Linked3dMass)
                                            {
                                                updated = UpdateParameter(fp.FloorElement, fp.Linked3dMass.MassElement);
                                            }

                                            if (updated)
                                            {
                                                FloorProperties updatedFloor = new FloorProperties(fp);
                                                updatedFloor.IsSelected = false;
                                                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 update parameters of linked masses.\n" + ex.Message, "Update Parameters", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                        }

                        progressBar.Visibility = System.Windows.Visibility.Hidden;
                        statusLable.Text       = "Ready";
                    }
                }
                else
                {
                    MessageBox.Show("Please set the configuration for the parameter mappings.\nGo to the Parameters Settings button for more detail.", "Parameters Settings Missing", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update parameter values.\n" + ex.Message, "Update Parameters", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        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);
            }
        }
示例#14
0
        private void DisplayFloorData()
        {
            try
            {
                progressForm.LabelText = "Preparing Components to be Displayed..";
                progressForm.CurValue  = 1;
                progressForm.Refresh();

                foreach (int floorId in floorDictionary.Keys)
                {
                    progressForm.PerformStep();
                    FloorProperties fp = floorDictionary[floorId];

                    int             index = dataGridViewFloor.Rows.Add();
                    DataGridViewRow row   = dataGridViewFloor.Rows[index];
                    row.Tag            = fp;
                    row.Cells[0].Value = false;
                    row.Cells[1].Value = fp.TypeName;
                    row.Cells[2].Value = fp.Level;
                    row.Cells[3].Value = fp.Phase;
                    row.Cells[4].Value = fp.DesignOption;
                    row.Cells[5].Value = fp.Comments;
                    row.Cells[6].Value = 10;//default height

                    if (placedFloors.Contains(fp.ID))
                    {
                        row.Cells[0].Value             = false;
                        row.DefaultCellStyle.ForeColor = System.Drawing.Color.Gray;
                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            cell.ToolTipText = fp.ID + ": Mass family is already placed in the project.";
                        }
                    }
                    if (floorDiscrepancy.Contains(fp.ID))
                    {
                        row.Cells[0].Value             = true;
                        row.DefaultCellStyle.ForeColor = System.Drawing.Color.Red;
                        foreach (DataGridViewCell cell in row.Cells)
                        {
                            cell.ToolTipText = fp.ID + ": Floor boundary lines have been changed.";
                        }
                    }
                }

                if (defDictionary.Count > 0)
                {
                    string parameters = "";
                    foreach (string defName in defDictionary.Keys)
                    {
                        parameters += "[" + defName + "]   ";
                    }
                    richTextBoxParameters.Text = parameters;
                }

                progressForm.Close();
            }
            catch (Exception ex)
            {
                progressForm.Close();
                MessageBox.Show("Failed to display floor data.\n" + ex.Message, "Form_CreateMass:DisplayFloorData", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#15
0
        private void bttnCreate_Click(object sender, EventArgs e)
        {
            try
            {
                List <int> checkedRows = new List <int>();
                for (int i = 0; i < dataGridViewFloor.Rows.Count; i++)
                {
                    if (Convert.ToBoolean(dataGridViewFloor.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 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;

                    SaveHeightValues();
                    Dictionary <int, FloorProperties> createdFloors = new Dictionary <int, FloorProperties>();
                    Dictionary <int, MassProperties>  placedMasses  = new Dictionary <int, MassProperties>();

                    statusLabel.Text             = "Updating Masses . . .";
                    toolStripProgressBar.Maximum = dataGridViewFloor.Rows.Count;
                    toolStripProgressBar.Visible = true;
                    StringBuilder resultMessage = new StringBuilder();

                    foreach (int index in checkedRows)
                    {
                        toolStripProgressBar.PerformStep();
                        DataGridViewRow row = dataGridViewFloor.Rows[index];
                        if (null != row.Tag)
                        {
                            FloorProperties fp = row.Tag as FloorProperties;
                            MassProperties  mp = new MassProperties();
                            mp.HostElementId = fp.ID;

                            if (placedFloors.Contains(fp.ID))
                            {
                                FamilyInstance instance = MassUtils.FindMassById(doc, fp.ID);
                                if (null != instance)
                                {
                                    mp.MassFamilyInstance = instance;

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

                                    resultMessage.AppendLine(fp.ID + "\t" + fp.TypeName + "\t" + fp.Level);
                                }
                                continue;
                            }

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

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

                            createdFloors.Add(fp.ID, fp);
                            resultMessage.AppendLine(fp.ID + "\t" + fp.TypeName + "\t" + fp.Level);
                        }
                    }

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

                    statusLabel.Text = "Done";
                    floorDataManager.CreatedFloors = createdFloors;
                    floorDataManager.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      = "Floor Masses are sucessfully created. \n[Floor ID], [Floor Type], [Floor Level]\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 Floor item to proceed.", "Empty Selection", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create mass floors.\n" + ex.Message, "Form_CreateMass:BttnCreate_Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }