Exemplo n.º 1
0
        public static revit_pricing_request get_pricing_request(Document curDoc, List <string> categories)
        {
            revit_pricing_request price1 = new revit_pricing_request();

            price1.project_id = curDoc.ProjectInformation.UniqueId.ToString();//.ToLower().Replace(" ", "_");

            //formatted snake_case
            List <string> formCat = new List <string>();

            foreach (string cate in categories)
            {
                formCat.Add(cate);//.ToLower().Replace(" ", "_"));
            }


            //filter for family instances
            FilteredElementCollector famCol   = new FilteredElementCollector(curDoc).OfClass(typeof(FamilyInstance));
            IList <Element>          famElems = famCol.ToElements();

            //iterate
            foreach (Element myE in famElems)
            {
                p_element fIelem = new p_element();
                fIelem.id   = myE.Id.ToString(); //.ToLower().Replace(" ", "_");
                fIelem.name = myE.Name;          //.ToLower().Replace(" ", "_");
                fIelem.element_class_name = "Family Instance";
                FamilyInstance myFamInst = myE as FamilyInstance;
                fIelem.properties.Add("family_name", myFamInst.Symbol.FamilyName);  //.ToLower().Replace(" ", "_"));
                fIelem.properties.Add("family_symbol_name", myFamInst.Symbol.Name); //.ToLower().Replace(" ", "_"));

                foreach (Parameter myParam in myFamInst.Parameters)
                {
                    if (myParam.StorageType == StorageType.String)
                    {
                        if (myParam.AsString() != "" && myParam.AsString() != "null" && myParam.AsString() != null)
                        {
                            if (!fIelem.properties.ContainsKey(myParam.Definition.Name.ToLower().Replace(" ", "_")))
                            {
                                fIelem.properties.Add(myParam.Definition.Name.ToLower().Replace(" ", "_"), myParam.AsString());//.ToLower().Replace(" ", "_"));
                            }
                            else
                            {
                                fIelem.properties[myParam.Definition.Name.ToLower().Replace(" ", "_")] += "," + myParam.AsString();
                            }
                        }
                    }
                    else
                    {
                        if (myParam.AsValueString() != "" && myParam.AsValueString() != "null" && myParam.AsValueString() != null)
                        {
                            if (!fIelem.properties.ContainsKey(myParam.Definition.Name.ToLower().Replace(" ", "_")))
                            {
                                fIelem.properties.Add(myParam.Definition.Name.ToLower().Replace(" ", "_"), myParam.AsValueString());//.ToLower().Replace(" ", "_"));
                            }
                            else
                            {
                                fIelem.properties[myParam.Definition.Name.ToLower().Replace(" ", "_")] += "," + myParam.AsValueString();
                            }
                        }
                    }
                }
                if (categories.Count != 0)
                {
                    if (fIelem.properties.ContainsKey("category"))
                    {
                        foreach (string myc in formCat)
                        {
                            if (fIelem.properties["category"].Contains(myc))
                            {
                                price1.elements.Add(fIelem);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    price1.elements.Add(fIelem);
                }
            }
            ElementClassFilter       FamilyFilter    = new ElementClassFilter(typeof(Family));
            FilteredElementCollector FamilyCollector = new FilteredElementCollector(curDoc);
            ICollection <Element>    AllFamilies     = FamilyCollector.WherePasses(FamilyFilter).ToElements();

            foreach (Family Fmly in AllFamilies)
            {
                string FamilyName = Fmly.Name;



                foreach (ElementId symid in Fmly.GetFamilySymbolIds())
                {
                    FamilySymbol FmlyS = curDoc.GetElement(symid) as FamilySymbol;

                    p_element fIelem = new p_element();
                    fIelem.id   = FmlyS.Id.ToString(); //.ToLower().Replace(" ", "_");
                    fIelem.name = FmlyS.Name;          //.ToLower().Replace(" ", "_");
                    fIelem.element_class_name = "Family Symbol";

                    fIelem.properties.Add("family_name", FamilyName);        //.ToLower().Replace(" ", "_"));
                    fIelem.properties.Add("family_symbol_name", FmlyS.Name); //.ToLower().Replace(" ", "_"));



                    foreach (Parameter myParam in FmlyS.Parameters)
                    {
                        if (myParam.StorageType == StorageType.String)
                        {
                            if (myParam.AsString() != "" && myParam.AsString() != "null" && myParam.AsString() != null)
                            {
                                if (!fIelem.properties.ContainsKey(myParam.Definition.Name.ToLower().Replace(" ", "_")))
                                {
                                    fIelem.properties.Add(myParam.Definition.Name.ToLower().Replace(" ", "_"), myParam.AsString());//.ToLower().Replace(" ", "_"));
                                }
                                else
                                {
                                    fIelem.properties[myParam.Definition.Name.ToLower().Replace(" ", "_")] += "," + myParam.AsString();
                                }
                            }
                        }
                        else
                        {
                            if (myParam.AsValueString() != "" && myParam.AsValueString() != "null" && myParam.AsValueString() != null)
                            {
                                if (!fIelem.properties.ContainsKey(myParam.Definition.Name.ToLower().Replace(" ", "_")))
                                {
                                    fIelem.properties.Add(myParam.Definition.Name.ToLower().Replace(" ", "_"), myParam.AsValueString());//.ToLower().Replace(" ", "_"));
                                }
                                else
                                {
                                    fIelem.properties[myParam.Definition.Name.ToLower().Replace(" ", "_")] += "," + myParam.AsValueString();
                                }
                            }
                        }
                    }
                    if (categories.Count != 0)
                    {
                        if (fIelem.properties.ContainsKey("category"))
                        {
                            foreach (string myc in formCat)
                            {
                                if (fIelem.properties["category"].Contains(myc))
                                {
                                    price1.elements.Add(fIelem);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        price1.elements.Add(fIelem);
                    }
                    //    if (myParam.StorageType == StorageType.String)
                    //    {
                    //        if (!fIelem.properties.ContainsKey(myParam.Definition.Name.ToLower().Replace(" ", "_")) && myParam.AsString() != "" && myParam.AsString() != "null" && myParam.AsString() != null)
                    //            fIelem.properties.Add(myParam.Definition.Name.ToLower().Replace(" ", "_"), myParam.AsString());//.ToLower().Replace(" ", "_"));

                    //    }
                    //    else
                    //    {
                    //        if (!fIelem.properties.ContainsKey(myParam.Definition.Name.ToLower().Replace(" ", "_")) && myParam.AsValueString() != "" && myParam.AsValueString() != "null" && myParam.AsValueString() != null)
                    //            fIelem.properties.Add(myParam.Definition.Name.ToLower().Replace(" ", "_"), myParam.AsValueString());//.ToLower().Replace(" ", "_"));
                    //    }
                    //}

                    //if (categories.Count != 0)
                    //{
                    //    if (fIelem.properties.ContainsKey("category"))
                    //    {
                    //        if (formCat.Contains(fIelem.properties["category"]))
                    //        {
                    //            price1.elements.Add(fIelem);
                    //        }
                    //    }

                    //}
                    //else
                    //{
                    //    price1.elements.Add(fIelem);
                    //}
                }
            }
            return(price1);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Saves Revit model parameters to text file
        /// </summary>
        /// <param name="commandData">An object that is passed to the external application
        /// which contains data related to the command,
        /// such as the application object and active view.</param>
        /// <param name="message">A message that can be set by the external application
        /// which will be displayed if a failure or cancellation is returned by
        /// the external command.</param>
        /// <param name="elements">A set of elements to which the external application
        /// can add elements that are to be highlighted in case of failure or cancellation.</param>
        /// <returns>Return the status of the external command.
        /// A result of Succeeded means that the API external method functioned as expected.
        /// Cancelled can be used to signify that the user cancelled the external operation
        /// at some point. Failure should be returned if the application is unable to proceed with
        /// the operation.</returns>
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
                                                ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            // NOTES: Anything can be done in this method, such as create a message box,
            // a task dialog or fetch some information from revit and so on.
            // We mainly use the task dialog for example.

            // Get the application and document from external command data.
            Application app    = commandData.Application.Application;
            Document    curDoc = commandData.Application.ActiveUIDocument.Document;

            //for text file
            List <string> lines = new List <string>();

            //loads from settings.txt
            settings.LoadSettings();

            //get document handle

            lines.Add("Document Title: " + curDoc.Title);
            lines.Add("Project Information UniqueID: " + curDoc.ProjectInformation.UniqueId.ToString());
            lines.Add(" ");
            lines.Add("Family Instances:");


            //filter for family instances
            FilteredElementCollector famCol = new FilteredElementCollector(curDoc);

            famCol.OfClass(typeof(FamilyInstance));
            IList <Element> famElems = famCol.ToElements();

            //iterate
            foreach (Element myE in famElems)
            {
                lines.Add("Element ID:	"+ myE.Id.ToString() + "	.	"+ "Element Name:	"+ myE.Name);

                FamilyInstance myFamInst = myE as FamilyInstance;
                lines.Add("Family Symbol: " + myFamInst.Symbol.Name);
                foreach (Parameter myParam in myE.Parameters)
                {
                    if (myParam.StorageType == StorageType.String)
                    {
                        lines.Add("	Param ID:	"+ myParam.Id.IntegerValue.ToString() + "	,	Param name:	"+ myParam.Definition.Name + "	:	Param value:	"+ myParam.AsString());
                    }
                    else
                    {
                        lines.Add("	Param ID:	"+ myParam.Id.IntegerValue.ToString() + "	,	Param name:	"+ myParam.Definition.Name + "	:	Param value:	"+ myParam.AsValueString());
                    }
                }
            }
            lines.Add(" ");
            lines.Add("Families:");
            ElementClassFilter       FamilyFilter    = new ElementClassFilter(typeof(Family));
            FilteredElementCollector FamilyCollector = new FilteredElementCollector(curDoc);
            ICollection <Element>    AllFamilies     = FamilyCollector.WherePasses(FamilyFilter).ToElements();

            foreach (Family Fmly in AllFamilies)
            {
                string FamilyName = Fmly.Name;

                lines.Add("Family ID:	"+ Fmly.Id.ToString() + "	,	Family name:	"+ FamilyName);
                foreach (Parameter myParam in Fmly.Parameters)
                {
                    lines.Add("	Param ID:	"+ myParam.Id.IntegerValue.ToString() + "	,	Param name:	"+ myParam.Definition.Name + "	:	Param value:	"+ myParam.AsValueString());
                }

                lines.Add("Family Symbols:");

                foreach (ElementId symid in Fmly.GetFamilySymbolIds())
                {
                    FamilySymbol FmlyS = curDoc.GetElement(symid) as FamilySymbol;



                    lines.Add(" Family Symbol ID:	"+ FmlyS.Id.ToString() + "	,	Family Symbol name:	"+ FmlyS.Name);

                    foreach (Parameter myParam in FmlyS.Parameters)
                    {
                        if (myParam.StorageType == StorageType.String)
                        {
                            lines.Add("	Param ID:	"+ myParam.Id.IntegerValue.ToString() + "	,	Param name:	"+ myParam.Definition.Name + "	:	Param value:	"+ myParam.AsString());
                        }
                        else
                        {
                            lines.Add("	Param ID:	"+ myParam.Id.IntegerValue.ToString() + "	,	Param name:	"+ myParam.Definition.Name + "	:	Param value:	"+ myParam.AsValueString());
                        }
                    }
                }
            }

            System.Windows.Forms.SaveFileDialog saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            saveFileDialog1.Filter = "Text file|*.txt";
            saveFileDialog1.Title  = "Save model parameters";
            saveFileDialog1.ShowDialog();

            // If the file name is not an empty string open it for saving.
            if (saveFileDialog1.FileName != "")
            {
                System.IO.File.WriteAllLines(saveFileDialog1.FileName, lines.ToArray());
            }
            return(Autodesk.Revit.UI.Result.Succeeded);
        }