コード例 #1
0
        internal static void RevitFileProcessor(ObservableCollection <RevitFile> filenames)
        {
            var openOptions = new OpenOptions();

            openOptions.Audit = false;
            openOptions.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach;
            var num     = 2;
            var strList = new List <string> {
                "File Name", "Volume of Column", "Volume of Beam", "Volume of Floor", "Area of Floor", "Length of Beam"
            };

            Excel excel = new Excel();

            excel.initNew();
            excel.open(@"C:\Users\Raja\Desktop\hackathon test files\datawriter.xlsx");
            excel.writeRow("Tabelle1", 1, strList);

            foreach (var file in filenames)
            {
                var       fullPath  = file.FullPath;
                var       excelFile = file.Directory;
                ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(fullPath);
                var       openedDoc = CachedApp.OpenDocumentFile(modelPath, openOptions);

                double volColumn = 0.0, volBeam = 0.0, volFloor = 0.0, areaFloor = 0.0, lenBeam = 0.0;

                var fecColumn = new FilteredElementCollector(openedDoc)
                                .OfCategory(BuiltInCategory.OST_StructuralColumns)
                                .WhereElementIsNotElementType();

                var fecBeam = new FilteredElementCollector(openedDoc)
                              .OfCategory(BuiltInCategory.OST_StructuralFraming)
                              .WhereElementIsNotElementType();

                var fecFloor = new FilteredElementCollector(openedDoc)
                               .OfCategory(BuiltInCategory.OST_Floors)
                               .WhereElementIsNotElementType();

                volColumn = fecColumn.Select(x => x.LookupParameter("Volume").AsDouble()).ToList().Sum();
                volBeam   = fecBeam.Select(x => x.LookupParameter("Volume").AsDouble()).ToList().Sum();
                volFloor  = fecFloor.Select(x => x.LookupParameter("Volume").AsDouble()).ToList().Sum();
                areaFloor = fecFloor.Select(x => x.LookupParameter("Area").AsDouble()).ToList().Sum();
                lenBeam   = fecBeam.Select(x => x.LookupParameter("Length").AsDouble()).ToList().Sum();

                var valList = new List <string> {
                    file.Filename, volColumn.ToString(), volBeam.ToString(), volFloor.ToString(), areaFloor.ToString(), lenBeam.ToString()
                };

                excel.writeRow("Tabelle1", num, valList);

                num += 1;

                openedDoc.Close(false);
                //TaskDialog.Show("Wishbox", $"The Total volume of column is: {volColumn.ToString()} \n The Total volume of beam is: {lenBeam.ToString()}");
            }
        }
コード例 #2
0
        public static void get_all_paramters(List <string> full_files_name)
        {
//			foreach(DefinitionGroup myGroup in defFile.Groups)
//			{
//				SortedSet<string> tmp = new SortedSet<string>();
//				Globals.SP_with_groups.Add(myGroup.Name,tmp);
//				foreach(Definition df in myGroup.Definitions)
//				{
//					Globals.SP_with_groups[myGroup.Name].Add(df.Name);
            ////					TaskDialog.Show("Revit",df.Name);
            ////					return;
//				}
//			//	TaskDialog.Show("Revit",Globals.SP_with_groups[myGroup.Name].Count.ToString());
//
//			}
            Document doc;

            Globals.files_with_SP.Clear();

            foreach (string filename in full_files_name)
            {
                doc = CachedApp.OpenDocumentFile(filename);
                try{
                    if (doc.IsFamilyDocument)
                    {
                        SortedSet <FamilyParameter> tmp = new SortedSet <FamilyParameter>(new cmp());
                        FamilyManager      fm           = doc.FamilyManager;
                        FamilyParameterSet fmSet        = fm.Parameters;
                        Globals.files_with_SP.Add(filename, tmp);
                        foreach (FamilyParameter fp in fmSet)
                        {
                            if (fp.IsShared)
                            {
                                Globals.files_with_SP[filename].Add(fp);
                                //tmp.Add(fp.Definition.Name);
                            }

                            //fp.Definition.
                            //TaskDialog.Show("Revit",fp.Definition.Name);
                        }
                    }
                }
                catch (System.Exception ea)
                {
                    TaskDialog.Show("Revit", ea.Message.ToString());
                }
            }
        }
コード例 #3
0
        public static void Add_SP_To_Families(List <string> full_files_name, List <string> parm_to_add, bool instance)
        {
            Document doc;

            //Application app;
            //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1";

            // loop through all files in the directory
            //	TaskDialog.Show("Revit","Hey");
            foreach (string filename in full_files_name)
            {
                doc = CachedApp.OpenDocumentFile(filename);
                try
                {
                    if (doc.IsFamilyDocument)
                    {
                        Transaction trans = new Transaction(doc, "Add Param");

                        using (trans)
                        {
                            FamilyManager    fm       = doc.FamilyManager;
                            DefinitionFile   deFile   = CachedApp.OpenSharedParameterFile();
                            DefinitionGroups myGroups = deFile.Groups;

                            foreach (string s in parm_to_add)
                            {
                                foreach (DefinitionGroup myGroup in myGroups)
                                {                                  // DefinitionGroup myGroup = myGroups.get_Item("New len");
                                    trans.Start();
                                    Definitions myDefinitions = myGroup.Definitions;
                                    //TaskDialog.Show("Revit",s);
                                    ExternalDefinition eDef = myDefinitions.get_Item(s) as ExternalDefinition;
                                    if (eDef != null)
                                    {
                                        fm.AddParameter(eDef, eDef.ParameterGroup, instance);
                                    }
                                    //TaskDialog.Show("Revit","Hey");
                                    trans.Commit();
                                    //	if(eDef != null) break;
                                }
                            }
                        }

                        //		doc.SaveAs(filename);
                        doc.Close(true);
                        //int tmp = Form1.progressBar1.Maximum;
                        //	int c = tmp/Globals.full_files_name_variables.Count;
                        //Form1.progressBar1.Increment(c);
                    }
                }
                catch (Autodesk.Revit.Exceptions.ArgumentNullException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    //trans.Commit();
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FamilyContextException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileAccessException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileNotFoundException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (SystemException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //		return;
                }
            }
        }
コード例 #4
0
        public static void Remove_Parameter(List <string> full_files_name, List <string> parm_to_add)
        {
//			UIDocument uidoc = this.ActiveUIDocument;
//			Document CachedDoc = uidoc.Document;
            Document doc;

            //Application app;
            //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1";

            // loop through all files in the directory

            foreach (string filename in full_files_name)
            {
                doc = CachedApp.OpenDocumentFile(filename);
                try
                {
                    if (doc.IsFamilyDocument)
                    {
                        FamilyManager fm    = doc.FamilyManager;
                        Transaction   trans = new Transaction(doc, "Remove Param");

                        using (trans)
                        {
                            //ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName");

                            foreach (string s in parm_to_add)
                            {
                                trans.Start();
                                FamilyParameter fp = RawConvertSetToList <FamilyParameter>(fm.Parameters).
                                                     FirstOrDefault(e => e.Definition.Name.Equals(s, StringComparison.CurrentCultureIgnoreCase));
                                //		TaskDialog.Show("Revit","Shared Parameter !!");

                                if (fp == null)
                                {
                                    throw new Exception("Invalid ParameterName Input!");
                                }
                                fm.RemoveParameter(fp);
                                trans.Commit();
                            }
                            //		doc.SaveAs(filename);
                            doc.Close(true);
                        }
                    }
                }
                catch (Autodesk.Revit.Exceptions.ArgumentNullException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    //trans.Commit();
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FamilyContextException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileAccessException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileNotFoundException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (SystemException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //		return;
                }
            }

            //TaskDialog.Show("Iam","Here");
        }
コード例 #5
0
//		public void Rename_Shared_Parameters(string p_name,string new_name)
//		{
        ////			UIDocument uidoc = this.ActiveUIDocument;
        ////			Document CachedDoc = uidoc.Document;
//			Document doc;
//			//Application app;
//			string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1";
//
//			// loop through all files in the directory
//
//			foreach (string filename in System.IO.Directory.GetFiles(folder))
//			{
//				try
//				{
//					doc = Application.OpenDocumentFile(filename);
//					if (doc.IsFamilyDocument)
//					{
//
//						Transaction trans = new Transaction(doc, "Remove Param");
//						trans.Start();
//						using(trans)
//						{
//							//ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName");
//							FamilyManager fm = doc.FamilyManager;
//							FamilyParameter fp = RawConvertSetToList<FamilyParameter>(fm.Parameters).
//								FirstOrDefault(e => e.Definition.Name.Equals(p_name, StringComparison.CurrentCultureIgnoreCase));
//							if (fp == null) throw new Exception("Invalid ParameterName Input!");
//							if(fp.IsShared)
//							{
//								ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), p_name);
        ////									        Guid guid = extdef.GUID;
        ////									        ParameterType type = extdef.ParameterType;
        ////									        string group_name = extdef.ParameterGroup.ToString();
//
//								//Create_SP(new_name,type,group_name);
//
        ////									        fm.ReplaceParameter(fp,"temp_test",BuiltInParameterGroup.PG_TEXT,true);
        ////									        FamilyParameter new_fp = RawConvertSetToList<FamilyParameter>(fm.Parameters).
        ////									        FirstOrDefault(e => e.Definition.Name.Equals("temp_test", StringComparison.CurrentCultureIgnoreCase));
        ////									        ExternalDefinition new_extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), new_name);
        ////									        fm.ReplaceParameter(new_fp,new_extdef,new_extdef.ParameterGroup,true);
//							}
//							trans.Commit();
//							//		doc.SaveAs(filename);
//							doc.Close(true);
//						}
//					}
//
//				}
//				catch (Autodesk.Revit.Exceptions.ArgumentNullException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.FamilyContextException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.FileAccessException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.FileNotFoundException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//				//	return;
//				}
//				catch (Autodesk.Revit.Exceptions.ApplicationException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//					return;
//				}
//				catch (SystemException ae)
//				{
//					TaskDialog.Show("Revit",ae.ToString());
//					//return;
//				}
//			}
//
//			//TaskDialog.Show("Iam","Here");
//
//		}

        /*	public static string GetParameterValue(FamilyParameter p)
         *      {
         *              switch(p.StorageType)
         *              {
         *                      case StorageType.Double:
         *                              return p.AsValueString();
         *                      case StorageType.ElementId:
         *                              return p.AsElementId().IntegerValue.ToString();
         *                      case StorageType.Integer:
         *                              return p.AsValueString();
         *                      case StorageType.None:
         *                              return p.AsValueString();
         *                      case StorageType.String:
         *                              return p.AsString();
         *                      default:
         *                              return "";
         *
         *              }
         *      }*/

        public static void Rename_Family_Parameters(List <string> full_files_name)
        {
//			UIDocument uidoc = this.ActiveUIDocument;
//			Document CachedDoc = uidoc.Document;
            Document doc;

            //Application app;
            //string folder = @"F:\ECG work\ECG_Shared_Parameters\Samples\sample 1\f1";

            // loop through all files in the directory

            foreach (string filename in full_files_name)
            {
                doc = CachedApp.OpenDocumentFile(filename);
                try
                {
                    if (doc.IsFamilyDocument)
                    {
                        Transaction trans = new Transaction(doc, "Rename Param");

                        using (trans)
                        {
                            //string s = Globals.new_name_for_rename;


                            trans.Start();
                            FamilyManager   fm = doc.FamilyManager;
                            FamilyParameter fp = RawConvertSetToList <FamilyParameter>(fm.Parameters).
                                                 FirstOrDefault(e => e.Definition.Name.Equals(Globals.parm_to_Replace, StringComparison.CurrentCultureIgnoreCase));
                            //		TaskDialog.Show("Revit","Shared Parameter !!");
                            trans.Commit();
                            if (fp.IsShared)
                            {
                                //		TaskDialog.Show("Revit",fm.Types.Size.ToString());
                                //	Element e = FilteredElementCollector(doc).OfClass(fm.CurrentType);

                                //	Parameter p = fm.Parameter(fp.Definition);
//									if (fp == null) throw new Exception("Invalid ParameterName Input!");
//									string tmp = "Parameter name: "+ fp.Definition.Name + "\n" +"Is Shared!";

                                //TaskDialog.Show("Warrning",tmp);
                                ExternalDefinition edf;
                                //	if(!Globals.all_SP_variables.Contains(fp.Definition.Name))
                                edf = Create_SP(Globals.new_name_for_rename,
                                                Globals.new_type,
                                                Globals.new_group);

                                trans.Start();
                                fm.AddParameter(edf, edf.ParameterGroup, Globals.instance_or_not);
                                //	fm.Parameter(edf.Name).Set(fp.ToString());


                                FamilyParameter fp_tmp = fm.get_Parameter(Globals.new_name_for_rename);
                                foreach (FamilyType t in fm.Types)
                                {
                                    if (t.HasValue(fp))
                                    {
                                        //TaskDialog.Show("R","Here");
                                        fm.CurrentType = t;
                                        if (fp_tmp.StorageType == StorageType.Double)
                                        {
                                            fm.Set(fp_tmp, t.AsDouble(fp).Value);
                                        }
                                        else if (fp_tmp.StorageType == StorageType.Integer)
                                        {
                                            fm.Set(fp_tmp, t.AsInteger(fp).Value);
                                        }
                                        else if (fp_tmp.StorageType == StorageType.ElementId)
                                        {
                                            fm.Set(fp_tmp, t.AsElementId(fp).IntegerValue);
                                        }
                                        else if (fp_tmp.StorageType == StorageType.String)
                                        {
                                            fm.Set(fp_tmp, t.AsString(fp));
                                        }
                                    }
                                    // TaskDialog.Show("R",);
                                }
                                //fm.Types
                                trans.Commit();

                                trans.Start();
                                fm.RemoveParameter(fp);
                                trans.Commit();
                                //	string k = "Parameter name: "+ edf.Name + "\n" +"Is Shared!";

                                //	TaskDialog.Show("Warrning",k);

                                //	fm.AddParameter();
                                //		rename_in_shared_parm_file(fp.Definition.Name,Globals.new_name_for_rename);

                                //doc.Close(false);
                                continue;
                            }
//								if (fp == null) throw new Exception("Invalid ParameterName Input!");
//								fm.RenameParameter(fp,new_name);
                            //      Test();
                            trans.Commit();

                            //ExternalDefinition extdef = RawFindExternalDefinition(Application.OpenSharedParameterFile(), "CompanyName");
//										FamilyManager fm = doc.FamilyManager;
//										FamilyParameter fp = RawConvertSetToList<FamilyParameter>(fm.Parameters).
//									        FirstOrDefault(e => e.Definition.Name.Equals(p_name, StringComparison.CurrentCultureIgnoreCase));
//									    if (fp == null) throw new Exception("Invalid ParameterName Input!");
//									    fm.RenameParameter(fp,new_name);
                            //                                      trans.Commit();
                            //		doc.SaveAs(filename);
                            doc.Close(true);
                        }
                    }
                }
                catch (Autodesk.Revit.Exceptions.ArgumentNullException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    //trans.Commit();
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FamilyContextException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileAccessException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.FileNotFoundException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (Autodesk.Revit.Exceptions.ApplicationException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //	return;
                }
                catch (SystemException ae)
                {
                    TaskDialog.Show("Revit", ae.ToString());
                    doc.Close(false);
                    //		return;
                }
            }

            //TaskDialog.Show("Iam","Here");
        }