Esempio n. 1
0
        public static void Start()
        {
            Command.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Command.Database = Document.Database;
            Command.Editor   = Command.Document.Editor;
            //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client();

            // Create new Grevit Client sending existing Families
            Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow();
            //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client(document.GetFamilies());

            // Show Client Dialog
            grevitClientDialog.ShowWindow();

            // if (grevitClientDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;

            List <Grevit.Types.Component> stalled = new List <Grevit.Types.Component>();

            existing_objects = Utilities.getExistingObjectIDs(grevitClientDialog.componentCollection);
            created_objects  = new Dictionary <string, ObjectId>();

            foreach (Grevit.Types.Component component in grevitClientDialog.componentCollection.Items)
            {
                if (!component.stalledForReference)
                {
                    try
                    {
                        component.Build(false);
                    }
                    catch (System.Exception e) { Grevit.Reporting.MessageBox.Show("Error", e.Message + e.StackTrace); }
                }
                else
                {
                    stalled.Add(component);
                }
            }



            try
            {
                foreach (Grevit.Types.Component c in stalled)
                {
                    try
                    {
                        c.Build(true);
                    }
                    catch (System.Exception e) { Grevit.Reporting.MessageBox.Show("Error", e.Message + e.StackTrace); }
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                //ed.WriteMessage(e.Message);
            }
        }
Esempio n. 2
0
        public static void Start()
        {
            Command.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Command.Database = Document.Database;
            Command.Editor = Command.Document.Editor;
            //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client();

            // Create new Grevit Client sending existing Families 
            Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow();
            //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client(document.GetFamilies());

            // Show Client Dialog
            grevitClientDialog.ShowWindow();

           // if (grevitClientDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return;

            List<Grevit.Types.Component> stalled = new List<Grevit.Types.Component>();

            existing_objects = Utilities.getExistingObjectIDs(grevitClientDialog.componentCollection);
            created_objects = new Dictionary<string, ObjectId>();

            foreach (Grevit.Types.Component component in grevitClientDialog.componentCollection.Items)
            {
                if (!component.stalledForReference)
                    component.Build(false);
                else
                    stalled.Add(component);
            }



            try
            {
                foreach (Grevit.Types.Component c in stalled)  c.Build(true);               
            }
            catch (Autodesk.AutoCAD.Runtime.Exception e)
            {
                //ed.WriteMessage(e.Message);
            }

        }
Esempio n. 3
0
        /// <summary>
        /// Build Revit Model from a Grevit Component Collection
        /// Make sure the Component Collection has update, delete and scale properties set
        /// </summary>
        /// <param name="components">Grevit Component Collection</param>
        /// <returns></returns>
        public Result BuildModel(Grevit.Types.ComponentCollection components)
        {
            bool delete = false;

            // if components collection hasn't been supplied
            // open the Grevit UI and retrieve components from a Grevit Server
            if (components == null)
            {
                // Create new Grevit Client sending existing Families
                Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow(document.GetFamilies());

                // Show Client Dialog
                grevitClientDialog.ShowWindow();

                // Set the received component collection
                components = grevitClientDialog.componentCollection;
            }

            // set element deletion flag and scale factor from collection
            delete = components.delete;
            Scale  = components.scale;


            RoofShapePoints = new List <Tuple <ElementId, CurveArray> >();


            // Set up a List for stalled components (with References)
            List <Component> componentsWithReferences = new List <Component>();

            // Get all existing Grevit Elements from the Document
            // If Update is false this will just be an empty List
            existing_Elements = document.GetExistingGrevitElements(components.update);

            // Set up an empty List for created Elements
            created_Elements = new Dictionary <string, ElementId>();


            #region createComponents

            // using one transaction for all elements
            // this way a Grevit import is one simple UNDO step in Revit
            Transaction trans = new Transaction(GrevitBuildModel.document, "GrevitCreate");
            trans.Start();

            // Walk thru all received components
            foreach (Component component in components.Items)
            {
                // If they are not reference dependent, create them directly
                // Otherwise add the component to a List of stalled elements
                if (!component.stalledForReference)
                {
                    try
                    {
                        component.Build(false);
                    }
                    catch (Exception e) { Grevit.Reporting.MessageBox.Show(component.GetType().Name + " Error", e.InnerException.Message); }
                }
                else
                {
                    componentsWithReferences.Add(component);
                }
            }

            // Walk thru all elements which are stalled because they are depending on
            // an Element which needed to be created first


            foreach (Component component in componentsWithReferences)
            {
                try
                {
                    component.Build(true);
                }
                catch (Exception e) { Grevit.Reporting.MessageBox.Show(component.GetType().Name + " Error", e.InnerException.Message); }
            }

            trans.Commit();
            trans.Dispose();



            foreach (Tuple <ElementId, CurveArray> rsp in RoofShapePoints)
            {
                if (rsp.Item1 != ElementId.InvalidElementId)
                {
                    Autodesk.Revit.DB.RoofBase roof = (Autodesk.Revit.DB.RoofBase)document.GetElement(rsp.Item1);
                    if (roof != null)
                    {
                        if (roof.SlabShapeEditor != null)
                        {
                            if (roof.SlabShapeEditor.IsEnabled)
                            {
                                Transaction pp = new Transaction(GrevitBuildModel.document, "GrevitPostProcessing");
                                pp.Start();
                                roof.SlabShapeEditor.Enable();
                                pp.Commit();
                                pp.Dispose();
                            }

                            List <XYZ> points = new List <XYZ>();
                            foreach (Curve c in rsp.Item2)
                            {
                                points.Add(c.GetEndPoint(0));
                            }

                            Transaction ppx = new Transaction(GrevitBuildModel.document, "GrevitPostProcessing");
                            ppx.Start();

                            foreach (SlabShapeVertex v in roof.SlabShapeEditor.SlabShapeVertices)
                            {
                                double Zdiff = 0;

                                foreach (XYZ pt in points)
                                {
                                    if (Math.Abs(v.Position.X - pt.X) < double.Epsilon &&
                                        Math.Abs(v.Position.Y - pt.Y) < double.Epsilon &&
                                        Math.Abs(v.Position.Z - pt.Z) > double.Epsilon)
                                    {
                                        Zdiff = pt.Z;
                                    }
                                }

                                if (Zdiff != 0)
                                {
                                    roof.SlabShapeEditor.ModifySubElement(v, Zdiff);
                                }
                            }

                            ppx.Commit();
                            ppx.Dispose();
                        }
                    }
                }
            }



            #endregion


            // If Delete Setting is activated
            if (delete)
            {
                // Create a new transaction
                Transaction transaction = new Transaction(document, "GrevitDelete");
                transaction.Start();

                // get the Difference between existing and new elements to erase them
                IEnumerable <KeyValuePair <string, ElementId> > unused =
                    existing_Elements.Except(created_Elements).Concat(created_Elements.Except(existing_Elements));

                // Delete those elements from the document
                foreach (KeyValuePair <string, ElementId> element in unused)
                {
                    document.Delete(element.Value);
                }

                // commit and dispose the transaction
                transaction.Commit();
                transaction.Dispose();
            }



            return(Result.Succeeded);
        }
Esempio n. 4
0
        public Result BuildModel(Grevit.Types.ComponentCollection components)
        {
            bool delete = false;

            if (components == null)
            {
                // Create new Grevit Client sending existing Families 
                Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow(document.GetFamilies());
                //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client(document.GetFamilies());

                // Show Client Dialog
                grevitClientDialog.ShowWindow();
                //if (grevitClientDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return Result.Cancelled;

                // Set the received component collection
                components = grevitClientDialog.componentCollection;

                delete = grevitClientDialog.componentCollection.delete;

                Scale = grevitClientDialog.componentCollection.scale;
            }



            // Set up a List for stalled components (with References)
            List<Component> componentsWithReferences = new List<Component>();

            // Get all existing Grevit Elements from the Document
            // If Update is false this will just be an empty List
            existing_Elements = document.GetExistingGrevitElements(components.update);

            // Set up an empty List for created Elements
            created_Elements = new Dictionary<string, ElementId>();


            #region createComponents

            Transaction trans = new Transaction(GrevitBuildModel.document, "GrevitCreate");
            trans.Start();

            // Walk thru all received components
            foreach (Component component in components.Items)
            {
                // If they are not reference dependent, create them directly
                // Otherwise add the component to a List of stalled elements
                if (!component.stalledForReference)
                    component.Build(false);       
                else
                    componentsWithReferences.Add(component);
            }

            // Walk thru all elements which are stalled because they are depending on
            // an Element which needed to be created first


            foreach (Component component in componentsWithReferences) component.Build(true);

            trans.Commit();
            trans.Dispose();

            #endregion


            // If Delete Setting is activated
            if (delete)
            {
                // Create a new transaction
                Transaction transaction = new Transaction(document, "GrevitDelete");
                transaction.Start();

                // get the Difference between existing and new elements to erase them
                IEnumerable<KeyValuePair<string, ElementId>> unused = 
                    existing_Elements.Except(created_Elements).Concat(created_Elements.Except(existing_Elements));

                // Delete those elements from the document
                foreach (KeyValuePair<string, ElementId> element in unused) document.Delete(element.Value);

                // commit and dispose the transaction
                transaction.Commit();
                transaction.Dispose();
            }



            return Result.Succeeded;
        }
Esempio n. 5
0
        public Result BuildModel(Grevit.Types.ComponentCollection components)
        {
            bool delete = false;

            if (components == null)
            {
                // Create new Grevit Client sending existing Families
                Grevit.Client.ClientWindow grevitClientDialog = new Grevit.Client.ClientWindow(document.GetFamilies());
                //Grevit.Serialization.Client grevitClientDialog = new Grevit.Serialization.Client(document.GetFamilies());

                // Show Client Dialog
                grevitClientDialog.ShowWindow();
                //if (grevitClientDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel) return Result.Cancelled;

                // Set the received component collection
                components = grevitClientDialog.componentCollection;

                delete = grevitClientDialog.componentCollection.delete;

                Scale = grevitClientDialog.componentCollection.scale;
            }



            // Set up a List for stalled components (with References)
            List <Component> componentsWithReferences = new List <Component>();

            // Get all existing Grevit Elements from the Document
            // If Update is false this will just be an empty List
            existing_Elements = document.GetExistingGrevitElements(components.update);

            // Set up an empty List for created Elements
            created_Elements = new Dictionary <string, ElementId>();


            #region createComponents

            Transaction trans = new Transaction(GrevitBuildModel.document, "GrevitCreate");
            trans.Start();

            // Walk thru all received components
            foreach (Component component in components.Items)
            {
                // If they are not reference dependent, create them directly
                // Otherwise add the component to a List of stalled elements
                if (!component.stalledForReference)
                {
                    try
                    {
                        component.Build(false);
                    }
                    catch (Exception e) { Grevit.Reporting.MessageBox.Show(component.GetType().Name + " Error", e.InnerException.Message); }
                }
                else
                {
                    componentsWithReferences.Add(component);
                }
            }

            // Walk thru all elements which are stalled because they are depending on
            // an Element which needed to be created first


            foreach (Component component in componentsWithReferences)
            {
                try
                {
                    component.Build(true);
                }
                catch (Exception e) { Grevit.Reporting.MessageBox.Show(component.GetType().Name + " Error", e.InnerException.Message); }
            }

            trans.Commit();
            trans.Dispose();

            #endregion


            // If Delete Setting is activated
            if (delete)
            {
                // Create a new transaction
                Transaction transaction = new Transaction(document, "GrevitDelete");
                transaction.Start();

                // get the Difference between existing and new elements to erase them
                IEnumerable <KeyValuePair <string, ElementId> > unused =
                    existing_Elements.Except(created_Elements).Concat(created_Elements.Except(existing_Elements));

                // Delete those elements from the document
                foreach (KeyValuePair <string, ElementId> element in unused)
                {
                    document.Delete(element.Value);
                }

                // commit and dispose the transaction
                transaction.Commit();
                transaction.Dispose();
            }



            return(Result.Succeeded);
        }