/// <summary> /// This class contains information discovered about a (shared or non-shared) project parameter /// </summary> // ================= HELPER METHODS ====================================================================================== /// <summary> /// Returns a list of the objects containing references to the project parameter definitions /// </summary> /// <param name="projectDocument">The project document being quereied</param> /// <returns></returns> public static List <ProjectParameterData> GetProjectParameterData(Document projectDocument) { // Following good SOA practices, first validate incoming parameters if (projectDocument == null) { throw new ArgumentNullException("projectDocument"); } if (projectDocument.IsFamilyDocument) { throw new Exception("projectDocument can not be a family document."); } List <ProjectParameterData> result = new List <ProjectParameterData>(); BindingMap map = projectDocument.ParameterBindings; DefinitionBindingMapIterator it = map.ForwardIterator(); it.Reset(); while (it.MoveNext()) { ProjectParameterData newProjectParameterData = new ProjectParameterData() { Definition = it.Key, Binding = it.Current as ElementBinding }; result.Add(newProjectParameterData); } return(result); }
/// <summary> /// This method populates the appropriate values on a ProjectParameterData object with information from /// the given Parameter object. /// </summary> /// <param name="parameter">The Parameter object with source information</param> /// <param name="projectParameterDataToFill">The ProjectParameterData object to fill</param> public static void PopulateProjectParameterData(Parameter parameter, ProjectParameterData projectParameterDataToFill) { // Following good SOA practices, validat incoming parameters first. if (parameter == null) { throw new ArgumentNullException("parameter"); } if (projectParameterDataToFill == null) { throw new ArgumentNullException("projectParameterDataToFill"); } projectParameterDataToFill.IsSharedStatusKnown = true; projectParameterDataToFill.IsShared = parameter.IsShared; if (parameter.IsShared) { if (parameter.GUID != null) { projectParameterDataToFill.GUID = parameter.GUID.ToString(); } } } // end of PopulateProjectParameterData
/// <summary> /// This method takes a category and information about a project parameter and /// adds a binding to the category for the parameter. It will throw an exception if the parameter /// is already bound to the desired category. It returns whether or not the API reports that it /// successfully bound the parameter to the desired category. /// </summary> /// <param name="projectDocument">The project document in which the project parameter has been defined</param> /// <param name="projectParameterData">Information about the project parameter</param> /// <param name="category">The additional category to which to bind the project parameter</param> /// <returns></returns> public static bool AddProjectParameterBinding(Document projectDocument, ProjectParameterData projectParameterData, Category category) { // Following good SOA practices, first validate incoming parameters if (projectDocument == null) { throw new ArgumentNullException("projectDocument"); } if (projectDocument.IsFamilyDocument) { throw new Exception("projectDocument can not be a family document."); } if (projectParameterData == null) { throw new ArgumentNullException("projectParameterData"); } if (category == null) { throw new ArgumentNullException("category"); } bool result = false; CategorySet cats = projectParameterData.Binding.Categories; if (cats.Contains(category)) { // It's already bound to the desired category. Nothing to do. string errorMessage = string.Format("The project parameter '{0}' is already bound to the '{1}' category.", projectParameterData.Definition.Name, category.Name); throw new Exception(errorMessage); } cats.Insert(category); // See if the parameter is an instance or type parameter. InstanceBinding instanceBinding = projectParameterData.Binding as InstanceBinding; if (instanceBinding != null) { // Is an Instance parameter InstanceBinding newInstanceBinding = projectDocument.Application.Create.NewInstanceBinding(cats); if (projectDocument.ParameterBindings.ReInsert(projectParameterData.Definition, newInstanceBinding)) { result = true; } } else { // Is a type parameter TypeBinding typeBinding = projectDocument.Application.Create.NewTypeBinding(cats); if (projectDocument.ParameterBindings.ReInsert(projectParameterData.Definition, typeBinding)) { result = true; } } return(result); }