Ejemplo n.º 1
0
        private void SharedParameterForm_Load(object sender, EventArgs e)
        {
            //Create a sorted list to hold the Shared Parameter Definition Groups that are read from the Shared Parameter File
            SortedList <string, DefinitionGroup> DefinitionGroupList = new SortedList <string, DefinitionGroup>();
            //Create a definition file to hole the Shared Parameters File Definitions
            DefinitionFile definitionFile;

            //Check to make sure there is a Shared Parameter File
            if ((definitionFile = doc.Application.OpenSharedParameterFile()) == null)
            {
                TaskDialog.Show("No Shared Parameter File", "No Shared Parameter Definition File could be found in the current Document.");
                return;
            }

            //Set the Form Label to the File Name of the Shared Parameter File
            txtSPFile.Text = definitionFile.Filename;

            //Add an item to the top of the DefinitionGroupList
            DefinitionGroupList.Add("--Select Group--", null);

            //Loop each Definition Group and add it to the Sorted List created earlier
            foreach (DefinitionGroup current in definitionFile.Groups)
            {
                DefinitionGroupList.Add(current.Name, current);
            }

            //Use the Sorted List as the Data source for the Shared Parameter Group Dropdown
            cboGroups.DataSource    = DefinitionGroupList.ToList();
            cboGroups.DisplayMember = "Key";
            cboGroups.ValueMember   = "Value";
        }
Ejemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //Verify that the User wants to proceed adding the Shared Parameters
            if (TaskDialog.Show("Modify Families", "This will add Shared Parameters and Upgrade " + Directory.GetFiles(FamilyDirectoryPath, "*.rfa").Length + " Revit Families.\n\nDo you want to Continue?", Autodesk.Revit.UI.TaskDialogCommonButtons.Yes | Autodesk.Revit.UI.TaskDialogCommonButtons.No, Autodesk.Revit.UI.TaskDialogResult.Yes) != Autodesk.Revit.UI.TaskDialogResult.Yes)
            {
                return;
            }

            //Find every Revit Family in the selected Directory
            foreach (string file in Directory.GetFiles(FamilyDirectoryPath, "*.rfa"))
            {
                //Wrap the events in a Try / Catch block to prevent any exceptions thrown from crashing or corrupting Revit
                try
                {
                    //Open the Revit Family File
                    if ((doc.Application.OpenDocumentFile(file)) is Document FamilyDoc)
                    {
                        //Verify is it in face a Family Document
                        if (FamilyDoc.IsFamilyDocument)
                        {
                            //Create a Transaction to make the changes in the Family Document
                            using (Transaction transaction = new Transaction(FamilyDoc))
                            {
                                //Start the Transaction and give it a Name
                                transaction.Start("Add Shared Parameters");
                                //Loop through each Shared Parameter checking in the List View
                                foreach (ListViewItem checkedItem in ltvParameters.CheckedItems)
                                {
                                    //Get the Parameter definition from the Tag property of the List View Item
                                    Definition paramDefinition = (Definition)checkedItem.Tag;
                                    //Cast the Definition as an External Defintion for use as a Shared Parameter
                                    ExternalDefinition externalDefinition = paramDefinition as ExternalDefinition;
                                    //Add the Shared Parameter to the family. Use the Instance Check box to indicated Type or Instance Parameters
                                    FamilyDoc.FamilyManager.AddParameter(externalDefinition, paramDefinition.ParameterGroup, chkInstance.Checked);
                                }
                                //Commit the transaction to keep the changes.
                                transaction.Commit();
                            }
                            //Close the Family and save the changes with "True"
                            FamilyDoc.Close(true);
                        }
                    }
                    else
                    {
                        TaskDialog.Show("Parameter Error", "There was a problem adding the Shared Parameters to the File: " + Environment.NewLine + file);
                    }
                }
                //Catch and exceptions to keep Revit from crashing and display the exception information.
                catch (Exception ex)
                {
                    TaskDialog.Show("Shared Parameter Error", ex.ToString());
                    //Try to continue to the next file
                    continue;
                }
            }
            //Set the Dialog result of the Form to OK so the Comamnd knows it finished
            DialogResult = DialogResult.OK;
            //Close the form
            Close();
        }
Ejemplo n.º 3
0
        private void performShow()
        {
            try
            {
                Autodesk.Revit.DB.ElementId toShow = Autodesk.Revit.DB.ElementId.InvalidElementId;

                Models.ClearWidth cw = treeView1.SelectedNode.Tag as Models.ClearWidth;
                if (cw != null)
                {
                    toShow = cw.Id;
                }

                Models.Node node = treeView1.SelectedNode.Tag as Models.Node;
                if (node != null)
                {
                    toShow = node.RoomId;
                }

                if (toShow == Autodesk.Revit.DB.ElementId.InvalidElementId)
                {
                    return;
                }
                _controller.Show(toShow);
            }
            catch (Exception ex)
            {
                Autodesk.Revit.UI.TaskDialog td = new Autodesk.Revit.UI.TaskDialog("Error");
                td.MainContent     = "Unexpected error: " + ex.GetType().Name + ":  " + ex.Message;
                td.ExpandedContent = ex.StackTrace;
                td.Show();
            }
        }
Ejemplo n.º 4
0
        private bool retrieveAndRender()
        {
            try
            {
                List <Autodesk.Revit.DB.Document> docs = new List <Autodesk.Revit.DB.Document>();
                foreach (var doc in _docsToProcess)
                {
                    docs.Add(doc.Doc);
                }

                _controller = new Controller(docs, _currentDoc, cbParameter.SelectedItem.ToString(), _config);

                Autodesk.Revit.DB.Parameter p = _currentDoc.ActiveView.get_Parameter(Autodesk.Revit.DB.BuiltInParameter.VIEW_PHASE);
                if (p == null)
                {
                    throw new ApplicationException("No view phase info?");
                }
                string phaseName = _currentDoc.GetElement(p.AsElementId()).Name;

                _rooms = _controller.RetrieveRooms(_currentDoc.ActiveView.GenLevel.Name, phaseName);

                // if this is only the current model, we can do more.

                if (docs[0].Title == _currentDoc.Title)
                {
                    int openCount = Controller.CountOpenSpots(_currentDoc, _currentDoc.ActiveView.GenLevel.Name, phaseName);
                    linkOpenSpots.Text    = "NOTE: There are " + openCount + " open areas in your room model that do not have Room elements. PLEASE REVIEW!";
                    linkOpenSpots.Visible = (openCount > 0);
                }
                else
                {
                    linkOpenSpots.Text    = "NOTE: please ensure that all possible rooms are created, including vertical penetration.";
                    linkOpenSpots.Visible = true;
                }


                IList <RoomObjectSummary> summaries = RoomObjectSummary.Summarize(_rooms, _config);
                dataGridView1.DataSource = null;
                dataGridView1.DataSource = summaries.ToArray();

                return(true);
            }
            catch (ApplicationException aex)
            {
                MessageBox.Show(aex.Message);
            }
            catch (Exception ex)
            {
                var td = new Autodesk.Revit.UI.TaskDialog("Unexpected issue");
                td.MainContent     = ex.GetType().Name + ": " + ex.Message;
                td.ExpandedContent = "Developer Info: " + Environment.NewLine + ex.StackTrace;
                td.Show();
            }
            return(false);
        }
Ejemplo n.º 5
0
        public static void ShowRevitDialog(this Exception exception, string largeText)
        {
            var td = new TaskDialog($"{exception.GetType().Name}")
            {
                MainIcon        = TaskDialogIcon.TaskDialogIconError,
                TitleAutoPrefix = false,
                MainInstruction = largeText,
                MainContent     = exception.Message,
                CommonButtons   = TaskDialogCommonButtons.Ok
            };

            td.Show();
        }
Ejemplo n.º 6
0
 private void performDrawAll()
 {
     try
     {
         _controller.DrawAll();
     }
     catch (Exception ex)
     {
         Autodesk.Revit.UI.TaskDialog td = new Autodesk.Revit.UI.TaskDialog("Error");
         td.MainContent     = "Unexpected error: " + ex.GetType().Name + ":  " + ex.Message;
         td.ExpandedContent = ex.StackTrace;
         td.Show();
     }
 }
Ejemplo n.º 7
0
        private void performGetAllRoutes()
        {
            try
            {
                DateTime start    = DateTime.Now;
                var      egresses = _controller.GetEgressNodes();
                double   total    = (double)treeView1.Nodes[0].Nodes.Count;
                UpdateStatus("Calculating Egress Routes to " + egresses.Count + " egress locations...");
                double count   = 0;
                double percent = 0.0;

                foreach (TreeNode child in treeView1.Nodes[0].Nodes)
                {
                    percent = count / total * 100.0;
                    count++;
                    UpdateStatus("Calculating Egress Routes to " + egresses.Count + " egress locations...(" + percent.ToString("F0") + "%)");
                    child.Nodes.Clear();
                    Models.Node roomNode = child.Tag as Models.Node;
                    foreach (var egress in egresses)
                    {
                        ExternalApp.Log("PathFinding " + roomNode + " to " + egress);
                        try
                        {
                            Models.Route r = Utilities.GraphUtility.FindShortest(roomNode, egress);
                            if (r != null)
                            {
                                addRouteNode(child, egress, r);
                            }
                        }
                        catch (Exception ex)
                        {
                            ExternalApp.Log("Exception while pathfinding:  " + ex.GetType().Name + ": " + ex.Message);
                            ExternalApp.Log(ex.StackTrace);
                        }
                    }
                }
                reCheckMaxPath();
                reCheckDoorCW();
                TimeSpan analysis = DateTime.Now - start;
                UpdateStatus("Analysis Completed in " + analysis);
            }
            catch (Exception ex)
            {
                Autodesk.Revit.UI.TaskDialog td = new Autodesk.Revit.UI.TaskDialog("Error");
                td.MainContent     = "Unexpected error: " + ex.GetType().Name + ":  " + ex.Message;
                td.ExpandedContent = ex.StackTrace;
                td.Show();
            }
        }
Ejemplo n.º 8
0
        private void ButtonOK_Click(object sender, EventArgs e)
        {
            //Cycle through each Checked Sheet in the ListView
            foreach (ListViewItem item in lvSheets.CheckedItems)
            {
                //Display a TaskDialog box with each Checked Sheet Number after casting it from the Tag property
                ViewSheet sheet = item.Tag as ViewSheet;
                TaskDialog.Show("Selected Sheet", "You selected sheet number " + sheet.SheetNumber);
            }
            //Set the DialogResult to make sure the form was successfuly used
            DialogResult = DialogResult.OK;

            //Close the form and return the DialogResult to the Command
            Close();
        }
Ejemplo n.º 9
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     try
     {
         //var archDoc = cbModel.SelectedItem as DocName;
         _controller.Create(_docsToProcess[0].Doc, _rooms, _currentDoc.ActiveView.GenLevel);
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     catch (ApplicationException aex)
     {
         Autodesk.Revit.UI.TaskDialog.Show("Error", aex.Message);
     }
     catch (Exception ex)
     {
         var td = new Autodesk.Revit.UI.TaskDialog("Unexpected Error");
         td.MainContent     = ex.GetType().Name + ": " + ex.Message;
         td.ExpandedContent = "Developer Info: " + Environment.NewLine + ex.StackTrace;
         td.Show();
     }
 }
Ejemplo n.º 10
0
        private void performDrawRoute()
        {
            try
            {
                Models.Route r = treeView1.SelectedNode.Tag as Models.Route;

                if (r == null)
                {
                    return;
                }

                _controller.DrawRoute(r);
            }
            catch (Exception ex)
            {
                Autodesk.Revit.UI.TaskDialog td = new Autodesk.Revit.UI.TaskDialog("Error");
                td.MainContent     = "Unexpected error: " + ex.GetType().Name + ":  " + ex.Message;
                td.ExpandedContent = ex.StackTrace;
                td.Show();
            }
        }
Ejemplo n.º 11
0
        private void performRun()
        {
            try
            {
                _controller.BuildNetwork();

                var rooms = _controller.GetRoomNodes();
                renderTree(rooms);

                _action = ActionEnum.GetAllRoutes;

                //var ids = _uiApp.ActiveUIDocument.Selection.GetElementIds();

                //if (ids.Count==2)
                //{
                //    Models.Node n1 = _controller.GetNodeByElementId(ids.First());
                //    Models.Node n2 = _controller.GetNodeByElementId(ids.Last());

                //    if ((n1 != null) && (n2 != null))
                //    {
                //        Models.Route r = Utilities.GraphUtility.FindShortest(n1, n2);

                //        MessageBox.Show("Route from: " + n1.Id + " to " + n2.Id + " Route: " + r);

                //    }
                //    else
                //    {
                //        MessageBox.Show("Both nodes were not found!");
                //    }
                //}
            }
            catch (Exception ex)
            {
                Autodesk.Revit.UI.TaskDialog td = new Autodesk.Revit.UI.TaskDialog("Error");
                td.MainContent     = "An unexpected error occurred: " + ex.GetType().Name + ": " + ex.Message;
                td.ExpandedContent = ex.StackTrace;
                td.Show();
            }
        }
Ejemplo n.º 12
0
        public static List <Element> DrawLines(Document doc, IEnumerable <Line> lines)
        {
            List <Element> modelLines = new List <Element>();

            SubTransaction st = new SubTransaction(doc);

            st.Start();

            XYZ lastNormal = new XYZ(999, 992, 200); // random

            Plane       p        = null;
            SketchPlane sp       = null;
            bool        useLines = false;

            FilteredElementCollector coll = new FilteredElementCollector(doc);
            var fs = coll.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_DetailComponents).Cast <FamilySymbol>().Where(f => f.Name.ToUpper().Replace(" ", "") == "EGRESSPATH").FirstOrDefault();

            if (fs == null)
            {
                //ugly to do this here.
                Autodesk.Revit.UI.TaskDialog td = new Autodesk.Revit.UI.TaskDialog("Egress Path");
                td.MainContent = "The 'EgressPath' Line-based detail family is not loaded. Model Lines will be shown instead.";
                td.Show();
                useLines = true;
            }


            foreach (Line ln in lines)
            {
                if (ln.Length < (1.0 / 24.0 / 12.0))
                {
                    continue;                                  // too short for Revit!
                }
                // see what the plane is
                XYZ vector = ln.Direction;
                XYZ normal = null;
                if (vector.Normalize().IsAlmostEqualTo(XYZ.BasisZ) == false)
                {
                    normal = vector.CrossProduct(XYZ.BasisZ);
                }
                else
                {
                    normal = vector.CrossProduct(XYZ.BasisX);
                }

                if (lastNormal.IsAlmostEqualTo(normal) == false)
                {
                    p      = Plane.CreateByNormalAndOrigin(normal, ln.GetEndPoint(0));
                    sp     = SketchPlane.Create(doc, p);
                    normal = lastNormal;
                }

                if (!useLines)
                {
                    if (fs.IsActive == false)
                    {
                        fs.Activate();
                    }
                    FamilyInstance fi = doc.Create.NewFamilyInstance(ln, fs, doc.ActiveView);
                    modelLines.Add(fi);
                }
                else
                {
                    ModelCurve curve = doc.Create.NewModelCurve(ln, sp);
                    modelLines.Add(curve as ModelLine);
                }
            }

            st.Commit();

            return(modelLines);
        }