Exemplo n.º 1
0
        /// <summary>
        /// Получаем словарь типов в которых имеются сам параметр и материал
        /// </summary>
        private Dictionary <FamilyType, Dictionary <FamilyParameter, Material> > GetParamValueDict(Document doc)
        {
            var DictTypes  = new Dictionary <FamilyType, Dictionary <FamilyParameter, Material> >();
            var DistParams = new Dictionary <FamilyParameter, Material>();

            FamilyManager FM          = doc.FamilyManager;
            FamilyTypeSet familyTypes = FM.Types;

            var familyParameters = FM.Parameters;

            foreach (FamilyType type in familyTypes)
            {
                var new_dict = new Dictionary <FamilyParameter, Material>();
                DictTypes.Add(type, new_dict);
                foreach (FamilyParameter param in familyParameters)
                {
                    if (param.Definition.ParameterType == ParameterType.Material)
                    {
                        //////////////////Обработать исключения если материала нет
                        ///
                        ElementId elid = type.AsElementId(param);
                        if (elid != ElementId.InvalidElementId)
                        {
                            Material material = (Material)doc.GetElement(elid);
                            new_dict.Add(param, material);
                        }
                    }
                }
            }

            return(DictTypes);
        }
Exemplo n.º 2
0
        public void GetFamilyTypesInFamily(Document familyDoc)
        {
            if (familyDoc.IsFamilyDocument)
            {
                FamilyManager         familyManager   = familyDoc.FamilyManager;
                string                types           = "Family Types: ";
                FamilyTypeSet         familyTypes     = familyManager.Types;
                FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator();
                familyTypesItor.Reset();

                while (familyTypesItor.MoveNext())
                {
                    FamilyType familyType = familyTypesItor.Current as FamilyType;
                    types += "\n" + familyType.Name;
                }
                TaskDialog.Show("Revit", types);
            }
        }
Exemplo n.º 3
0
        internal bool ProcessFamily()
        {
            if (!Doc.IsFamilyDocument)
            {
                return(false);
            }

            FamilyManager famMgr = Doc.FamilyManager;

            FamilyTypeSet         famTypes    = famMgr.Types;
            FamilyTypeSetIterator famTypeItor = famTypes.ForwardIterator();

            famTypeItor.Reset();
            while (famTypeItor.MoveNext())
            {
                FamilyType famType = famTypeItor.Current as FamilyType;
                logMsgDbLn2("fam type", famType.Name);
            }

            FamilyParameterSet         famParas    = famMgr.Parameters;
            FamilyParameterSetIterator famParaItor = famParas.ForwardIterator();

            famParaItor.Reset();
            while (famParaItor.MoveNext())
            {
                FamilyParameter famPara = famParaItor.Current as FamilyParameter;
                logMsgDbLn2("fam para", famPara.Definition.Name
                            + "  :: " + famPara.Definition.ParameterGroup.ToString()
                            + "  :: " + famPara.Definition.ParameterType.ToString());
            }

            famMgr.AddParameter("ASI", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true);

//			using (SubTransaction st = new SubTransaction(_doc))
//			{
//				st.Start();
//				famMgr.AddParameter("ASI", BuiltInParameterGroup.PG_IDENTITY_DATA, ParameterType.Text, true);
//				st.Commit();
//			}

            return(true);
        }
        /// <summary>
        /// Non-working sample code for
        /// http://forums.autodesk.com/t5/revit-api/family-types-amp-shared-parameter-values/m-p/6218767
        /// </summary>
        void SetFamilyParameterValueFails(
            Document doc,
            string paramNameToAmend)
        {
            FamilyManager         mgr         = doc.FamilyManager;
            FamilyTypeSet         familyTypes = mgr.Types;
            FamilyTypeSetIterator familyTypeItor
                = familyTypes.ForwardIterator();

            familyTypeItor.Reset();
            while (familyTypeItor.MoveNext())
            {
                FamilyParameter familyParam
                    = mgr.get_Parameter(paramNameToAmend);

                if (familyParam != null)
                {
                    FamilyType familyType = familyTypeItor.Current as FamilyType;
                    Debug.Print(familyType.Name);
                    mgr.Set(familyParam, 2);
                }
            }
        }
Exemplo n.º 5
0
        private List <Material> GetFamilyTypesMaterials(Document doc, Family modifiedFamily)
        {
            List <Material> typesMaterials = new List <Material>();

            Document              familyDoc     = doc.EditFamily(modifiedFamily);
            FamilyManager         familyManager = familyDoc.FamilyManager;
            FamilyTypeSet         familyTypes   = familyManager.Types;
            FamilyTypeSetIterator iterator      = familyTypes.ForwardIterator();

            iterator.Reset();
            string types = string.Empty;

            using (Transaction trans = new Transaction(familyDoc, "MaterialParameter"))
            {
                trans.Start();
                while (iterator.MoveNext())
                {
                    familyManager.CurrentType = iterator.Current as FamilyType;
                    FamilyType type  = familyManager.CurrentType;
                    string     param = string.Empty;
                    foreach (FamilyParameter parameter in familyManager.Parameters)
                    {
                        if (parameter.Definition.Name.Contains("Mat"))
                        {
                            Material material = doc.GetElement(type.AsElementId(parameter)) as Material;
                            if (material != null)
                            {
                                typesMaterials.Add(material);
                            }
                        }
                    }
                }
                trans.Commit();
            }

            return(typesMaterials);
        }
Exemplo n.º 6
0
        private List <FamilyTypeData> GetTypes(Family family, Document doc, string path)
        {
            Document              familyDoc     = doc.EditFamily(family);
            FamilyManager         familyManager = familyDoc.FamilyManager;
            FamilyTypeSet         familyTypes   = familyManager.Types;
            FamilyTypeSetIterator iterator      = familyTypes.ForwardIterator();

            iterator.Reset();

            List <FamilyTypeData> types = new List <FamilyTypeData>();

            while (iterator.MoveNext())
            {
                using (Transaction trans = new Transaction(familyDoc, "Getting Parameter"))
                {
                    trans.Start();
                    familyManager.CurrentType = iterator.Current as FamilyType;
                    FamilyType type = familyManager.CurrentType;

                    string paramDescription = string.Empty;
                    //FamilyParameter paramDescription;
                    try
                    {
                        paramDescription = type.AsString(familyManager.get_Parameter("Description"));
                        if (string.IsNullOrEmpty(paramDescription))
                        {
                            try
                            {
                                paramDescription = type.AsString(familyManager.get_Parameter("Beschreibung"));
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramMountType = string.Empty;
                    try
                    {
                        paramMountType = type.AsString(familyManager.get_Parameter("Installationsart"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramPlacement = string.Empty;
                    try
                    {
                        paramPlacement = type.AsString(familyManager.get_Parameter("Installationsort"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramInstallationMedium = string.Empty;
                    try
                    {
                        paramInstallationMedium = type.AsString(familyManager.get_Parameter("Installations Medium"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramDiameter = string.Empty;
                    try
                    {
                        paramDiameter = type.AsString(familyManager.get_Parameter("E_Durchmesser"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramWidth = string.Empty;
                    try
                    {
                        paramWidth = type.AsString(familyManager.get_Parameter("E_Breite"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramHeight = string.Empty;
                    try
                    {
                        paramHeight = type.AsString(familyManager.get_Parameter("E_Hohe"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramDepth = string.Empty;
                    try
                    {
                        paramDepth = type.AsString(familyManager.get_Parameter("E_Tiefe"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string param_eBKP_H = string.Empty;
                    try
                    {
                        param_eBKP_H = type.AsString(familyManager.get_Parameter("eBKP-H"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramBKP = string.Empty;
                    try
                    {
                        paramBKP = type.AsString(familyManager.get_Parameter("BKP"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramManufacturer = string.Empty;
                    try
                    {
                        paramManufacturer = type.AsString(familyManager.get_Parameter("Fabrikat"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramProduct = string.Empty;
                    try
                    {
                        paramProduct = type.AsString(familyManager.get_Parameter("Produkt"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramProductNumber = string.Empty;
                    try
                    {
                        paramProductNumber = type.AsString(familyManager.get_Parameter("Produkte-Nr."));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramE_Number = string.Empty;
                    try
                    {
                        paramE_Number = type.AsString(familyManager.get_Parameter("E-Nummer"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramRevitCategory = String.Empty;
                    try
                    {
                        paramRevitCategory = type.AsString(familyManager.get_Parameter("Revit Kategorie"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    string paramOmniClass = string.Empty;
                    try
                    {
                        paramOmniClass = type.AsString(familyManager.get_Parameter("OmniClass-Nummer"));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }

                    if (true /*type != null && paramMountType!= null && paramPlacement!= null && paramInstallationMedium!=null*/)
                    {
                        FamilyTypeData typeData = new FamilyTypeData
                        {
                            Name               = type.Name,
                            Description        = string.IsNullOrEmpty(paramDescription)? emptyParameter: paramDescription,
                            MountType          = string.IsNullOrEmpty(paramMountType)? emptyParameter: paramMountType,
                            Placement          = string.IsNullOrEmpty(paramPlacement)? emptyParameter :paramPlacement,
                            InstallationMedium = string.IsNullOrEmpty(paramInstallationMedium) ? emptyParameter : paramInstallationMedium,
                            Path               = path,
                            CombinedTypeData   = paramDescription + "\n" + type.Name,
                            Diameter           = string.IsNullOrEmpty(paramDiameter)? emptyParameter: paramDiameter,
                            Width              = string.IsNullOrEmpty(paramWidth) ? emptyParameter : paramWidth,
                            Hight              = string.IsNullOrEmpty(paramHeight) ? emptyParameter : paramHeight,
                            Depth              = string.IsNullOrEmpty(paramDepth) ? emptyParameter : paramDepth,
                            eBKP_H             = string.IsNullOrEmpty(param_eBKP_H) ? emptyParameter : param_eBKP_H,
                            BKP           = string.IsNullOrEmpty(paramBKP) ? emptyParameter : paramBKP,
                            Manufacturer  = string.IsNullOrEmpty(paramManufacturer) ? emptyParameter : paramManufacturer,
                            Product       = string.IsNullOrEmpty(paramProduct) ? emptyParameter : paramProduct,
                            ProductNumber = string.IsNullOrEmpty(paramProductNumber) ? emptyParameter : paramProductNumber,
                            E_Number      = string.IsNullOrEmpty(paramE_Number) ? emptyParameter : paramE_Number,
                            RevitCategory = string.IsNullOrEmpty(paramRevitCategory) ? emptyParameter : paramRevitCategory,
                            OmniClass     = string.IsNullOrEmpty(paramOmniClass) ? emptyParameter : paramOmniClass
                        };
                        types.Add(typeData);
                    }

                    //TaskDialog.Show("Params", paramDescription.Definition.Name + " * " + type.AsString(paramDescription));
                    //TaskDialog.Show("Params", paramMountType.Definition.Name + " * " + type.AsString(paramMountType));
                    //TaskDialog.Show("Params", paramPlacement.Definition.Name + " * " + type.AsString(paramPlacement));
                    //TaskDialog.Show("Params", paramInstallationMedium.Definition.Name + " * " + type.AsString(paramInstallationMedium));
                    trans.Commit();
                }
            }

            return(types);
        }
Exemplo n.º 7
0
        public AdminDataGFFRequest(UIApplication uiApp, String text)
        {
            //Items pertaining to the open UI
            MainUI        uiForm         = BARevitTools.Application.thisApp.newMainUi;
            List <string> itemsToCollect = uiForm.adminDataGFFItemsToCollect;

            //UI settings related to the proggress bar
            int filesToProcess = uiForm.adminDataGFFFiles.Count;

            uiForm.adminDataGFFDataProgressBar.Value   = 0;
            uiForm.adminDataGFFDataProgressBar.Minimum = 0;
            uiForm.adminDataGFFDataProgressBar.Maximum = filesToProcess;
            uiForm.adminDataGFFDataProgressBar.Step    = 1;
            uiForm.adminDataGFFDataProgressBar.Visible = true;

            //New objects
            DataTable dt             = new DataTable();
            int       selectionGroup = -2;

            //Getting the items from the list obtained from checked listbox items to determine what datatable columns are needed
            //The items below are able to be obtained without API calls. Statementselect remains -1 to indicate no API request will be needed, saving time.
            if (itemsToCollect.Contains("Family Name"))
            {
                DataColumn familyNameColumn = dt.Columns.Add("FamilyName", typeof(String));
                selectionGroup = -1;
            }

            if (itemsToCollect.Contains("Family Size"))
            {
                DataColumn familySizeColumn = dt.Columns.Add("FamilySize", typeof(Double));
                selectionGroup = -1;
            }

            if (itemsToCollect.Contains("Date Last Modified"))
            {
                DataColumn dateLastModifiedColumn = dt.Columns.Add("DateLastModified", typeof(String));
                selectionGroup = -1;
            }

            //Here is where items must be obtained via API calls. Statementselect changes from -1 to 0 to later indicate that API usage will be needed.
            if (itemsToCollect.Contains("Revit Version"))
            {
                DataColumn revitVersionColumn = dt.Columns.Add("RevitVersion", typeof(String));
                selectionGroup = 0;
            }

            if (itemsToCollect.Contains("Family Category"))
            {
                DataColumn familyCategoryColumn = dt.Columns.Add("FamilyCategory", typeof(String));
                selectionGroup = 0;
            }

            //From here, the IF statments indicate the files will need to be opened and API calls will be used, resulting in a slow data collection. Statementselect becomes 1
            if (itemsToCollect.Contains("Family Types"))
            {
                DataColumn familyTypeColumn = dt.Columns.Add("FamilyType", typeof(String));
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter Name"))
            {
                DataColumn parameterNameColumn = dt.Columns.Add("ParameterName", typeof(String));
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter Group"))
            {
                DataColumn parameterGroupColumn = dt.Columns.Add("ParameterGroup", typeof(String));
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter Type"))
            {
                DataColumn parameterTypeColumn = dt.Columns.Add("ParameterType", typeof(String));
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter Value"))
            {
                //If the parameter value is to be collected, it could be either an integer, double, or string, so create all three columns anyways
                DataColumn parameterValueIntegerColumn = dt.Columns.Add("ParameterValueInteger", typeof(Int32));
                parameterValueIntegerColumn.AllowDBNull = true;
                DataColumn parameterValueDoubleColumn = dt.Columns.Add("ParameterValueDouble", typeof(Double));
                parameterValueDoubleColumn.AllowDBNull = true;
                DataColumn parameterValueStringColumn = dt.Columns.Add("ParameterValueString", typeof(String));
                parameterValueStringColumn.AllowDBNull = true;
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter Is Instance"))
            {
                DataColumn parameterIsInstanceColumn = dt.Columns.Add("ParameterIsInstance", typeof(Boolean));
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter Is Shared"))
            {
                DataColumn parameterIsSharedColumn = dt.Columns.Add("ParameterIsShared", typeof(Boolean));
                selectionGroup = 1;
            }

            if (itemsToCollect.Contains("Parameter GUID"))
            {
                DataColumn parameterGUIDColumn = dt.Columns.Add("ParameterGUID", typeof(String));
                selectionGroup = 1;
            }

            //Cycle through the file paths obtained from the open UI
            foreach (string filePath in uiForm.adminDataGFFFiles)
            {
                //Increment the progress bar of the open UI
                uiForm.adminDataGFFDataProgressBar.PerformStep();
                // If selectionGroup is -1, no use of the API will be used
                if (selectionGroup == -1)
                {
                    DataRow row = dt.NewRow();
                    if (dt.Columns.Contains("FamilyName"))
                    {
                        row["FamilyName"] = GeneralOperations.GetFileName(filePath);
                    }

                    if (dt.Columns.Contains("FamilySize"))
                    {
                        row["FamilySize"] = GeneralOperations.GetFileSize(filePath);
                    }

                    if (dt.Columns.Contains("DateLastModified"))
                    {
                        row["DateLastModified"] = GeneralOperations.GetFileLastModifiedDate(filePath);
                    }

                    dt.Rows.Add(row);
                }

                //If selectionGroup is 0, then the API will be used, resulting in slower processing
                else if (selectionGroup == 0)
                {
                    //Get the Revit version year of the file
                    int rvtNumber = RVTOperations.GetRevitNumber(filePath);
                    //Check to see if the GetRevitNumber did not return 0 (could not be determined), and that the saved in version is not newer that the one running.
                    if (rvtNumber != 0 && Convert.ToInt32(uiApp.Application.VersionNumber) >= rvtNumber)
                    {
                        DataRow row = dt.NewRow();

                        if (dt.Columns.Contains("FamilyName"))
                        {
                            row["FamilyName"] = GeneralOperations.GetFileName(filePath);
                        }

                        if (dt.Columns.Contains("FamilySize"))
                        {
                            row["FamilySize"] = GeneralOperations.GetFileSize(filePath);
                        }

                        if (dt.Columns.Contains("DateLastModified"))
                        {
                            row["DateLastModified"] = GeneralOperations.GetFileLastModifiedDate(filePath);
                        }

                        if (dt.Columns.Contains("RevitVersion"))
                        {
                            row["RevitVersion"] = RVTOperations.GetRevitVersion(filePath);
                        }

                        RVTDocument doc = RVTOperations.OpenRevitFile(uiApp, filePath);
                        if (dt.Columns.Contains("FamilyCategory") && doc.IsFamilyDocument)
                        {
                            row["FamilyCategory"] = RVTOperations.GetRevitFamilyCategory(doc);
                        }

                        doc.Close(false);
                        dt.Rows.Add(row);
                    }
                }

                //If selectionGroup is 1, then the API will be used, and the file must be opened to obtain the information
                else if (selectionGroup == 1)
                {
                    //Verifying Revit version year
                    int rvtNumber = RVTOperations.GetRevitNumber(filePath);
                    if (rvtNumber != 0 && Convert.ToInt32(uiApp.Application.VersionNumber) >= rvtNumber)
                    {
                        //Open the Revit file
                        RVTDocument doc = RVTOperations.OpenRevitFile(uiApp, filePath);
                        //Ensure it is a family document
                        if (doc.IsFamilyDocument)
                        {
                            //Get the family manager of the family file
                            FamilyManager famMan = doc.FamilyManager;
                            //Get the set of family types from the family file
                            FamilyTypeSet familyTypes = famMan.Types;

                            Transaction t1 = new Transaction(doc, "CycleFamilyTypes");
                            t1.Start();
                            FailureHandlingOptions failureHandlingOptions = t1.GetFailureHandlingOptions();
                            failureHandlingOptions.SetFailuresPreprocessor(new RVTFailuresPreprocessor());
                            t1.SetFailureHandlingOptions(failureHandlingOptions);

                            //For each family type...
                            foreach (FamilyType famType in familyTypes)
                            {
                                //Create a subtransaction to change the current family type in the family manager
                                SubTransaction s1 = new SubTransaction(doc);
                                s1.Start();

                                famMan.CurrentType = famType;
                                s1.Commit();

                                //Get each parameter from the current family type, and create a row for each parameter
                                foreach (FamilyParameter param in famMan.GetParameters())
                                {
                                    DataRow row = dt.NewRow();
                                    if (dt.Columns.Contains("FamilyName"))
                                    {
                                        try { row["FamilyName"] = GeneralOperations.GetFileName(filePath); }
                                        catch { row["FamilyName"] = ""; }
                                    }
                                    if (dt.Columns.Contains("FamilySize"))
                                    {
                                        try { row["FamilySize"] = GeneralOperations.GetFileSize(filePath); }
                                        catch { row["FamilySize"] = 0; }
                                    }
                                    if (dt.Columns.Contains("DateLastModified"))
                                    {
                                        try { row["DateLastModified"] = GeneralOperations.GetFileLastModifiedDate(filePath); }
                                        catch { row["DateLastModified"] = ""; }
                                    }
                                    if (dt.Columns.Contains("RevitVersion"))
                                    {
                                        try { row["RevitVersion"] = RVTOperations.GetRevitVersion(filePath); }
                                        catch { row["RevitVersion"] = ""; }
                                    }
                                    if (dt.Columns.Contains("FamilyCategory"))
                                    {
                                        try { row["FamilyCategory"] = RVTOperations.GetRevitFamilyCategory(doc); }
                                        catch { row["FamilyCategory"] = ""; }
                                    }
                                    if (dt.Columns.Contains("FamilyType"))
                                    {
                                        try { row["FamilyType"] = famType.Name.ToString(); }
                                        catch { row["FamilyType"] = ""; }
                                    }

                                    if (dt.Columns.Contains("ParameterName"))
                                    {
                                        try { row["ParameterName"] = param.Definition.Name; }
                                        catch { row["ParameterName"] = ""; }
                                    }

                                    if (dt.Columns.Contains("ParameterGroup"))
                                    {
                                        try { row["ParameterGroup"] = param.Definition.ParameterGroup.ToString(); }
                                        catch { row["ParameterGroup"] = ""; }
                                    }

                                    if (dt.Columns.Contains("ParameterType"))
                                    {
                                        try { row["ParameterType"] = param.Definition.ParameterType.ToString(); }
                                        catch { row["ParameterType"] = ""; }
                                    }

                                    //Here is where the attempts to get the parameter values begins. Get the StorageType of the parameter, then determine which column the data goes in
                                    if (dt.Columns.Contains("ParameterValueInteger") && param.StorageType == StorageType.Integer)
                                    {
                                        try { row["ParameterValueInteger"] = famType.AsInteger(param); }
                                        catch { row["ParameterValueInteger"] = 0; }
                                    }

                                    if (dt.Columns.Contains("ParameterValueDouble") && param.StorageType == StorageType.Double)
                                    {
                                        try { row["ParameterValueDouble"] = famType.AsDouble(param); }
                                        catch { row["ParameterValueDouble"] = 0; }
                                    }

                                    if (dt.Columns.Contains("ParameterValueString") && param.StorageType == StorageType.ElementId)
                                    {
                                        //Instead of getting the ElementID, which is limited in value to someone reading the data, get the element name instead
                                        try { row["ParameterValueString"] = doc.GetElement(famType.AsElementId(param)).Name; }
                                        catch { row["ParameterValueString"] = ""; }
                                    }

                                    if (dt.Columns.Contains("ParameterValueString") && param.StorageType == StorageType.String)
                                    {
                                        //First, try getting the parameter string as a string. If that fails, try getting it as a ValueString
                                        try
                                        {
                                            string paramValue = famType.AsString(param);
                                            row["ParameterValueString"] = paramValue;
                                        }
                                        catch
                                        {
                                            try
                                            {
                                                string paramValue = famType.AsValueString(param).ToString();
                                                row["ParameterValueString"] = paramValue;
                                            }
                                            catch
                                            {
                                                row["ParameterValueString"] = "";
                                            }
                                        }
                                    }

                                    if (dt.Columns.Contains("ParameterIsInstance"))
                                    {
                                        try { row["ParameterIsInstance"] = param.IsInstance; }
                                        catch { row["ParameterIsInstance"] = false; }
                                    }

                                    if (dt.Columns.Contains("ParameterIsShared"))
                                    {
                                        try { row["ParameterIsShared"] = param.IsShared; }
                                        catch { row["ParameterIsShared"] = false; }
                                    }

                                    if (dt.Columns.Contains("ParameterGUID"))
                                    {
                                        try { row["ParameterGUID"] = param.GUID.ToString(); }
                                        catch { row["ParameterGUID"] = ""; }
                                    }
                                    //Add the datatable row to the datatable
                                    dt.Rows.Add(row);
                                }
                            }
                            //Commit the primary transaction
                            t1.Commit();
                        }
                        //Close the document, do not save
                        doc.Close(false);
                    }
                }
                else
                {
                    //selectionGroup is still -2, and thus nothing was selected. Do nothing.
                    continue;
                }
            }

            //Set the datatable of the open UI to the one with the obtained data
            uiForm.adminDataGFFDataTable = dt;
            //Indicate the collection is done with the label
            uiForm.adminDataGFFCollectDataWaitLabel.Text = "Done!";
            //Hide the progress bar when done, and clear out the list of data items to collect
            uiForm.adminDataGFFDataProgressBar.Visible = false;
            uiForm.adminDataGFFItemsToCollect.Clear();
        }
Exemplo n.º 8
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument    uidoc = uiapp.ActiveUIDocument;
            Application   app   = uiapp.Application;



            using (var formOpen = new FormOpenFile())
            {
                formOpen.ShowDialog();

                string[] filePath = System.IO.Directory.GetFiles(formOpen.filePath);

                foreach (string file in filePath)
                {
                    Document open_file = app.OpenDocumentFile(file);


                    FamilyManager fm = open_file.FamilyManager;


                    using (Transaction t = new Transaction(open_file, "Remove types"))
                    {
                        t.Start();

                        FamilyTypeSet familyTypes = fm.Types;

                        int count = familyTypes.Size;

                        while (count > 1)
                        {
                            fm.DeleteCurrentType();
                            count -= 1;
                        }

                        try
                        {
                            fm.RenameCurrentType("Default");
                        }
                        catch
                        {
                            //Do nothing
                        }


                        ICollection <ElementId> purgeableElements = null;

                        if (PurgeTool.GetPurgeableElements(open_file, ref purgeableElements) & purgeableElements.Count > 0)
                        {
                            open_file.Delete(purgeableElements);
                        }


                        t.Commit();


                        /*
                         * Press.Keys("PU");
                         * winForm.SendKeys.SendWait("{ENTER}");
                         *
                         * String s_commandToDisable = "ID_PURGE_UNUSED";
                         * RevitCommandId s_commandId = RevitCommandId.LookupCommandId(s_commandToDisable);
                         * uiapp.PostCommand(s_commandId);*/
                    }

                    //open_file.Save();
                    open_file.Close();
                }
            }

            return(Result.Succeeded);
        }
Exemplo n.º 9
0
        private void SetParameters(UIApplication uiApp, string familyFile, ExternalDefinition externalDefinition)
        {
            try
            {
                //Get the FileInfo of the family file and then get the LastWriteTime value as a date string in MM/DD/YYYY format
                FileInfo fileInfo     = new FileInfo(familyFile);
                string   lastModified = fileInfo.LastWriteTime.ToShortDateString();

                //Open the family file
                RVTDocument famDoc = RVTOperations.OpenRevitFile(uiApp, familyFile);
                if (famDoc != null)
                {
                    //Get the family manager for the family file
                    FamilyManager famMan = famDoc.FamilyManager;
                    //Get the family parameters and add them to a dictionary indexed by parameter name
                    FamilyParameter famParameter = null;
                    Dictionary <string, FamilyParameter> famParamDict = new Dictionary <string, FamilyParameter>();
                    foreach (FamilyParameter famParam in famMan.Parameters)
                    {
                        famParamDict.Add(famParam.Definition.Name, famParam);
                    }

                    //Get the number of family types because there must be at least one family type to make this work
                    FamilyTypeSet types         = famMan.Types;
                    int           numberOfTypes = types.Size;

                    Transaction t1 = new Transaction(famDoc, "SetParameters");
                    t1.Start();
                    if (numberOfTypes == 0)
                    {
                        //If the number of family types was 0, then one must be made. Thus Default is a family type created
                        try
                        {
                            famMan.NewType("Default");
                        }
                        catch { MessageBox.Show(String.Format("Could not make a default type or find any type for {0}", familyFile)); }
                    }

                    //Once the existence of a family type is confirmed, move on with determining if the version parameter already exists. If it doesn't add the parameter to the family and regenerate the document
                    if (!famParamDict.Keys.Contains(BARevitTools.Properties.Settings.Default.RevitUFVPParameter))
                    {
                        famParameter = famMan.AddParameter(externalDefinition, BuiltInParameterGroup.PG_IDENTITY_DATA, false);
                        famDoc.Regenerate();
                    }
                    else
                    {
                        famParameter = famParamDict[BARevitTools.Properties.Settings.Default.RevitUFVPParameter];
                    }

                    //Check to see if the value for the parameter is equal to the date last modified
                    if (famMan.CurrentType.AsString(famParameter) == lastModified)
                    {
                        //If so, roll back the transaction and just close the file.
                        t1.RollBack();
                        famDoc.Close(false);
                    }
                    else
                    {
                        //Otherwise set the formula of the version parameter to the quote encapsulated date, just like it would appear in Revit, commit it, then save.
                        famMan.SetFormula(famParameter, "\"" + lastModified + "\"");
                        t1.Commit();
                        RVTOperations.SaveRevitFile(uiApp, famDoc, true);
                    }
                }
                else
                {
                    //If the family could not be opened for any reason, let the user know
                    MessageBox.Show(String.Format("{0} could not be opened.", familyFile));
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }