Beispiel #1
0
        //Method deletes parameters
        public void RemoveSharedParameterBinding(Application app, string name, ParameterType type)
        {
            BindingMap map = (new UIApplication(app)).ActiveUIDocument.Document.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();

            Definition def = null;

            while (it.MoveNext())
            {
                if (it.Key != null && it.Key.Name == name && type == it.Key.ParameterType)
                {
                    def = it.Key;
                    break;
                }
            }

            if (def == null)
            {
                sbFeedback.Append("Parameter " + name + " does not exist.\n");
            }
            else
            {
                map.Remove(def);
                if (map.Contains(def))
                {
                    sbFeedback.Append("Failed to delete parameter " + name + " for some reason.\n");
                }
                else
                {
                    sbFeedback.Append("Parameter " + name + " deleted.\n");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns a list of the objects containing
        /// references to the project parameter definitions
        /// </summary>
        /// <param name="doc">The project document being quereied</param>
        /// <returns></returns>
        static List <ProjectParameterData> GetProjectParameterData(Document doc)
        {
            // Following good SOA practices, first validate incoming parameters

            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }

            if (doc.IsFamilyDocument)
            {
                throw new Exception("doc can not be a family document.");
            }

            List <ProjectParameterData> result = new List <ProjectParameterData>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it
                = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                ProjectParameterData newProjectParameterData = new ProjectParameterData();

                newProjectParameterData.Definition = it.Key;
                newProjectParameterData.Name       = it.Key.Name;
                newProjectParameterData.Binding    = it.Current
                                                     as ElementBinding;

                result.Add(newProjectParameterData);
            }
            return(result);
        }
Beispiel #3
0
        public static IList <SharedParameter> GetSharedParameters(Document doc)
        {
            IList <SharedParameter> extSharedParams = new List <SharedParameter>();
            BindingMap bindingMap           = doc.ParameterBindings;
            DefinitionBindingMapIterator it =
                bindingMap.ForwardIterator();

            it.Reset();

            while (it.MoveNext())
            {
                InternalDefinition        definition  = it.Key as InternalDefinition;
                Autodesk.Revit.DB.Binding currBinding = bindingMap.get_Item(definition);

                // unearth the parameter's GUID
                SharedParameterElement sharedParamElem =
                    doc.GetElement(definition.Id) as SharedParameterElement;

                if (sharedParamElem == null)
                {
                    continue;
                }

                SharedParameter sharedParam =
                    new SharedParameter(definition.Name, definition.ParameterType,
                                        sharedParamElem.GuidValue, currBinding, definition.ParameterGroup);

                extSharedParams.Add(sharedParam);
            }

            return(extSharedParams);
        }
Beispiel #4
0
        public static void ExportParameters(Document doc, string path)
        {
            DefinitionFile existingDefFile = doc.Application.OpenSharedParameterFile();

            //
            doc.Application.SharedParametersFilename = path;
            DefinitionFile tempDefFile = doc.Application.OpenSharedParameterFile();

            // Manager the Exported group
            DefinitionGroup exported = null;

            var query = from dg in tempDefFile.Groups
                        where dg.Name.Equals(doc.PathName + "-Exported")
                        select dg;

            if (query.Count() == 0)
            {
                exported = tempDefFile.Groups.Create(doc.PathName + "-Exported");
            }
            else
            {
                exported = query.First();
            }

            // Iterate over the shared parameters in the document
            BindingMap bindingMap           = doc.ParameterBindings;
            DefinitionBindingMapIterator it =
                bindingMap.ForwardIterator();

            it.Reset();

            while (it.MoveNext())
            {
                InternalDefinition        definition  = it.Key as InternalDefinition;
                Autodesk.Revit.DB.Binding currBinding = bindingMap.get_Item(definition);

                // Corroborate that the current parameter has not been exported previously
                Definition existingDef = exported.Definitions
                                         .Where(d => (d.Name.Equals(definition.Name))).FirstOrDefault();
                if (existingDef != null)
                {
                    continue;
                }

                // unearth and assign the parameter's GUID
                SharedParameterElement sharedParamElem =
                    doc.GetElement(definition.Id) as SharedParameterElement;

                if (sharedParamElem == null)
                {
                    continue;
                }

                ExternalDefinitionCreationOptions options =
                    new ExternalDefinitionCreationOptions(definition.Name, definition.ParameterType);
                options.GUID = sharedParamElem.GuidValue;

                Definition createdDefinition = exported.Definitions.Create(options);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Test if the Room binds a specified shared parameter
        /// </summary>
        /// <param name="paramName">Parameter name to be checked</param>
        /// <returns>true, the definition exists, false, doesn't exist.</returns>
        private bool ShareParameterExists(String paramName)
        {
            BindingMap bindingMap             = m_document.ParameterBindings;
            DefinitionBindingMapIterator iter = bindingMap.ForwardIterator();

            iter.Reset();

            while (iter.MoveNext())
            {
                Definition tempDefinition = iter.Key;

                // find the definition of which the name is the appointed one
                if (String.Compare(tempDefinition.Name, paramName) != 0)
                {
                    continue;
                }

                // get the category which is bound
                ElementBinding binding        = bindingMap.get_Item(tempDefinition) as ElementBinding;
                CategorySet    bindCategories = binding.Categories;
                foreach (Category category in bindCategories)
                {
                    if (category.Name
                        == m_document.Settings.Categories.get_Item(BuiltInCategory.OST_Rooms).Name)
                    {
                        // the definition with appointed name was bound to Rooms, return true
                        return(true);
                    }
                }
            }
            //
            // return false if shared parameter doesn't exist
            return(false);
        }
        /// <summary>
        /// Checks if a parameter exists based of a name
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="paramName"></param>
        /// <returns></returns>
        private bool ShareParameterExists(Document doc, String paramName)
        {
            BindingMap bindingMap             = doc.ParameterBindings;
            DefinitionBindingMapIterator iter = bindingMap.ForwardIterator();

            iter.Reset();

            while (iter.MoveNext())
            {
                Definition tempDefinition = iter.Key;

                // find the definition of which the name is the appointed one
                if (String.Compare(tempDefinition.Name, paramName) != 0)
                {
                    continue;
                }

                // get the category which is bound
                ElementBinding binding        = bindingMap.get_Item(tempDefinition) as ElementBinding;
                CategorySet    bindCategories = binding.Categories;
                foreach (Category category in bindCategories)
                {
                    if (category.Name
                        == doc.Settings.Categories.get_Item(BuiltInCategory.OST_Rebar).Name)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #7
0
        static public bool IsParameterInProject(Document doc, string parameterName, BuiltInCategory cat)
        {
            Category   category             = doc.Settings.Categories.get_Item(cat);
            BindingMap map                  = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();
            bool result = false;

            it.Reset();
            while (it.MoveNext())
            {
                result = result || (it.Key.Name == parameterName && (it.Current as ElementBinding).Categories.Contains(category));
            }
            return(result);
        }
Beispiel #8
0
        //Shared Parameters
        //-----------------
        public static bool CheckCreateProjectParameter(Document doc, string param, BuiltInCategory bicCheck)
        {
            try
            {
                BindingMap map = doc.ParameterBindings;

                DefinitionBindingMapIterator it = map.ForwardIterator();
                it.Reset();

                Category cat = Category.GetCategory(doc, bicCheck);

                CategorySet catSet = new CategorySet();
                catSet.Insert(Category.GetCategory(doc, bicCheck));

                ElementBinding eb = null;

                while (it.MoveNext())
                {
                    if (param == it.Key.Name)
                    {
                        eb = it.Current as ElementBinding;
                        if (eb.Categories.Contains(cat))
                        {
                            return(true);
                        }
                    }
                }

                Transaction trans = new Transaction(doc);

                try
                {
                    trans.Start("Project Parameters");
                    CreateSharedProjectParameters(doc, param, catSet);
                    trans.Commit();

                    return(true);
                }
                catch (Exception ex)
                {
                    trans.RollBack();
                    throw new Exception("Exception in Create Shared Parameters" + ex.Message);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Exception in Check Project Parameter.\n" + ex);
            }
        }
Beispiel #9
0
        static private ElementBinding GetParameterBinding(Document doc, string parameterName)
        {
            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                if (it.Key.Name == parameterName)
                {
                    return(it.Current as ElementBinding);
                }
            }
            return(null);
        }
Beispiel #10
0
        protected internal static Definition GetParameterDefinition(Document doc, string name)
        {
            BindingMap val = doc.get_ParameterBindings();
            DefinitionBindingMapIterator val2 = val.ForwardIterator();

            val2.Reset();
            while (val2.MoveNext())
            {
                InternalDefinition val3 = val2.get_Key();
                if (val3.get_Name().Equals(name))
                {
                    return(val3);
                }
            }
            return(null);
        }
Beispiel #11
0
        static List <RoomProjectParametersData> GetRoomProjectParametersData(Document doc)
        {
            // Following good SOA practices, first validate incoming parameters
            if (doc == null)
            {
                throw new ArgumentNullException("doc");
            }

            if (doc.IsFamilyDocument)
            {
                throw new Exception("This plugin cannot be run on a family document.");
            }

            List <RoomProjectParametersData> result
                = new List <RoomProjectParametersData>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it
                = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                RoomProjectParametersData newProjectParameterData
                    = new RoomProjectParametersData();

                newProjectParameterData.Binding = it.Current
                                                  as ElementBinding;

                Category roomCategory = Category.GetCategory(doc, BuiltInCategory.OST_Rooms);

                IEnumerable <Category> catSet = newProjectParameterData.Binding.Categories.Cast <Category>();

                if (catSet.Any(c => c.Id.Equals(roomCategory.Id)) && it.Key.ParameterType == ParameterType.Text)
                {
                    newProjectParameterData.category   = roomCategory;
                    newProjectParameterData.Definition = it.Key;
                    newProjectParameterData.Name       = it.Key.Name;
                    newProjectParameterData.type       = it.Key.ParameterType;

                    result.Add(newProjectParameterData);
                }
            }
            return(result);
        }
Beispiel #12
0
        public ParameterListForm(UIApplication revitUiApp, DataSet dataSet) : this()
        {
            this.m_revitUiApp                   = revitUiApp;
            this.m_revitApp                     = revitUiApp.Application;
            this.m_tableInfoSet                 = Command.TableInfoSet;
            this.m_parameterCreation            = new ParameterCreation(revitUiApp);
            this.m_dataSet                      = dataSet;
            this.parameterListBox.DisplayMember = "ParameterName";
            this.parameterListBox.Sorted        = true;
            DefinitionBindingMapIterator definitionBindingMapIterator = this.m_revitUiApp.ActiveUIDocument.Document.ParameterBindings.ForwardIterator();

            definitionBindingMapIterator.Reset();
            while (definitionBindingMapIterator.MoveNext())
            {
                Definition key  = definitionBindingMapIterator.Key;
                string     name = key.Name;
                if (!this.ParameterExists(name))
                {
                    this.parameterListBox.Items.Add(name);
                }
            }
        }
Beispiel #13
0
        public static List <RawProjectParameterInfo> RawGetProjectParametersInfo(Document doc)
        {
            RawProjectParameterInfo.FileName = doc.Title;
            List <RawProjectParameterInfo> paramList = new List <RawProjectParameterInfo>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();
            while (it.MoveNext())
            {
                ElementBinding  eleBinding = it.Current as ElementBinding;
                InstanceBinding insBinding = eleBinding as InstanceBinding;
                Definition      def        = it.Key;
                if (def != null)
                {
                    ExternalDefinition extDef = def as ExternalDefinition;
                    bool shared = extDef != null;
                    RawProjectParameterInfo param = new RawProjectParameterInfo
                    {
                        Name            = def.Name,
                        Group           = def.ParameterGroup,
                        Type            = def.ParameterType,
                        ReadOnly        = true, // def.IsReadOnly, def.IsReadOnly NOT working in either 2015 or 2014 but working in 2013
                        BoundToInstance = insBinding != null,
                        BoundCategories = RawConvertSetToList <Category>(eleBinding.Categories).Select(c => c.Name).ToArray(),

                        FromShared = shared,
                        GUID       = shared ? extDef.GUID.ToString() : string.Empty,
                        Owner      = shared ? extDef.OwnerGroup.Name : string.Empty,
                        Visible    = shared ? extDef.Visible : true,
                    };

                    paramList.Add(param);
                }
            }

            return(paramList);
        }
Beispiel #14
0
        /// <summary>
        /// Method to retrieve filtered project parameters ID by category
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="category"></param>
        /// <returns></returns>
        public static string[] ProjectParameters(Document doc, string categoryName)
        {
            List <string> parametersID = new List <string>();

            BindingMap map = doc.ParameterBindings;
            DefinitionBindingMapIterator it = map.ForwardIterator();

            it.Reset();

            while (it.MoveNext())
            {
                ElementBinding  eleBinding = it.Current as ElementBinding;
                InstanceBinding insBinding = eleBinding as InstanceBinding;

                if (insBinding != null && IsInstBindingOfCategory(insBinding, categoryName))
                {
                    Definition def = it.Key;
                    if (def != null)
                    {
                        ExternalDefinition extDef = def as ExternalDefinition;

                        if (extDef != null)
                        {
                            string GUID = extDef.GUID.ToString();
                            parametersID.Add(GUID);
                        }
                        else
                        {
                            InternalDefinition intDef = def as InternalDefinition;
                            string             ID     = intDef.Id.ToString();
                            parametersID.Add(ID);
                        }
                    }
                }
            }
            return(parametersID.ToArray());
        }
Beispiel #15
0
        private void AddSharedParameters(Application app, Document doc, CategorySet myCategorySet)
        {
            //Save the previous shared param file path
            string previousSharedParam = app.SharedParametersFilename;

            //Extract shared param to a txt file
            string tempPath = System.IO.Path.GetTempPath();
            string SPPath   = Path.Combine(tempPath, "FileProperties.txt");

            if (!File.Exists(SPPath))
            {
                //extract the familly
                List <string> files = new List <string>();
                files.Add("FileProperties.txt");
                Tools.ExtractEmbeddedResource(tempPath, "TimeStamp.Resources", files);
            }

            //set the shared param file
            app.SharedParametersFilename = SPPath;

            //Retrive shared parameters
            DefinitionFile myDefinitionFile = app.OpenSharedParameterFile();

            DefinitionGroup definitionGroup = myDefinitionFile.Groups.get_Item("FileProperties");

            foreach (Definition paramDef in definitionGroup.Definitions)
            {
                // Get the BingdingMap of current document.
                BindingMap bindingMap = doc.ParameterBindings;

                //the parameter does not exist
                if (!bindingMap.Contains(paramDef))
                {
                    //Create an instance of InstanceBinding
                    InstanceBinding instanceBinding = app.Create.NewInstanceBinding(myCategorySet);

                    bindingMap.Insert(paramDef, instanceBinding, BuiltInParameterGroup.PG_IDENTITY_DATA);
                }
                //the parameter is not added to the correct categories
                else if (bindingMap.Contains(paramDef))
                {
                    InstanceBinding currentBinding = bindingMap.get_Item(paramDef) as InstanceBinding;
                    currentBinding.Categories = myCategorySet;
                    bindingMap.ReInsert(paramDef, currentBinding, BuiltInParameterGroup.PG_IDENTITY_DATA);
                }
            }

            //SetAllowVaryBetweenGroups for these parameters
            string[] parameterNames = { "BIM42_Date", "BIM42_Version", "BIM42_File", "BIM42_Discipline" };

            DefinitionBindingMapIterator definitionBindingMapIterator = doc.ParameterBindings.ForwardIterator();

            definitionBindingMapIterator.Reset();

            while (definitionBindingMapIterator.MoveNext())
            {
                InternalDefinition paramDef = definitionBindingMapIterator.Key as InternalDefinition;
                if (paramDef != null)
                {
                    if (parameterNames.Contains(paramDef.Name))
                    {
                        paramDef.SetAllowVaryBetweenGroups(doc, true);
                    }
                }
            }

            //Reset to the previous shared parameters text file
            app.SharedParametersFilename = previousSharedParam;
            File.Delete(SPPath);
        }
Beispiel #16
0
        //private ParameterElement projectleider { get; set; }

        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            NewProjects        newProjects = new NewProjects();
            ProjectInformation information = new ProjectInformation(); // ProjectInformation Dialog

            information.OK += delegate
            {
                var templateFileName = @"C:\Users\Appie\Desktop\TestTemplate.rte";
                var file             = $"{information.FilePath}\\{information.FileName}";
                var app       = commandData?.Application?.Application;
                var activeDoc = app.NewProjectDocument(templateFileName);
                ActiveDocument = activeDoc;
                var date = DateTime.Now.ToString("dd/MM/yyyy");

                using (new TransactionManager.TransactionManager(activeDoc))
                {
                    activeDoc.ProjectInformation.Name                    = information.ProjectName;
                    activeDoc.ProjectInformation.Number                  = information.TotalProjectNumber;
                    activeDoc.ProjectInformation.BuildingName            = information.BuildingName;
                    activeDoc.ProjectInformation.Author                  = Environment.UserName;
                    activeDoc.ProjectInformation.IssueDate               = date;
                    activeDoc.ProjectInformation.ClientName              = information.ClientName;
                    activeDoc.ProjectInformation.Address                 = information.Project_adress;
                    activeDoc.ProjectInformation.Status                  = "Concept";
                    activeDoc.ProjectInformation.OrganizationName        = information.OrganizationName;
                    activeDoc.ProjectInformation.OrganizationDescription = information.OrganizationDesc;
                    // activeDoc.GetElement("").GetParameters("")[0].SetValueString("");
                    if (activeDoc == null)
                    {
                        throw new ArgumentNullException("doc");
                    }

                    if (activeDoc.IsFamilyDocument)
                    {
                        throw new Exception("doc can not be a family document.");
                    }

                    List <ProjectParameterData> result = new List <ProjectParameterData>();

                    BindingMap map = activeDoc.ParameterBindings;
                    DefinitionBindingMapIterator it
                        = map.ForwardIterator();
                    it.Reset();
                    while (it.MoveNext())
                    {
                        ProjectParameterData newProjectParameterData = new ProjectParameterData();

                        newProjectParameterData.Definition = it.Key;
                        newProjectParameterData.Name       = it.Key.Name;
                        newProjectParameterData.Binding    = it.Current
                                                             as ElementBinding;

                        result.Add(newProjectParameterData);
                    }
                }

                activeDoc.SaveAs(file);
                commandData.Application.OpenAndActivateDocument(file);
            };
            newProjects.ProjectInformation = information;
            newProjects.ShowDialog();
            return(Result.Succeeded);
        }
        public ElementBinding Add(Document document, string name, IEnumerable <BuiltInCategory> builtInCategories, BuiltInParameterGroup builtInParameterGroup, bool instance)
        {
            if (document == null || document.ParameterBindings == null || string.IsNullOrWhiteSpace(name) || builtInCategories == null || builtInCategories.Count() == 0)
            {
                return(null);
            }

            ElementBinding result = null;

            DefinitionBindingMapIterator definitionBindingMapIterator = document?.ParameterBindings?.ForwardIterator();

            if (definitionBindingMapIterator != null)
            {
                definitionBindingMapIterator.Reset();

                while (definitionBindingMapIterator.MoveNext())
                {
                    Definition definition_Temp = definitionBindingMapIterator.Key as Definition;
                    if (definition_Temp == null)
                    {
                        continue;
                    }

                    //if (aExternalDefinition.GUID.Equals(pExternalDefinition.GUID))
                    if (definition_Temp.Name.Equals(name))
                    {
                        result = (ElementBinding)definitionBindingMapIterator.Current;
                        break;
                    }
                }
            }

            if (result != null)
            {
                return(result);
            }

            Definition definition = Find(name);

            if (definition == null)
            {
                return(null);
            }

            CategorySet categorySet = Revit.Create.CategorySet(document, builtInCategories);

            if (categorySet == null || categorySet.Size == 0)
            {
                return(null);
            }

            if (result != null)
            {
            }
            else
            {
                if (instance)
                {
                    result = document.Application.Create.NewInstanceBinding(categorySet);
                }
                else
                {
                    result = document.Application.Create.NewTypeBinding(categorySet);
                }

                document.ParameterBindings.Insert(definition, result, builtInParameterGroup);
            }

            return(result);
        }