Пример #1
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);
        }
        /// <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>
        static void PopulateProjectParameterData(
            Parameter parameter,
            ProjectParameterData projectParameterDataToFill)
        {
            // Following good SOA practices, validate 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="doc">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>
        static bool AddProjectParameterBinding(
            Document doc,
            ProjectParameterData projectParameterData,
            Category category)
        {
            // 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.");
            }

            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
                    = doc.Application.Create
                      .NewInstanceBinding(cats);

                if (doc.ParameterBindings.ReInsert(
                        projectParameterData.Definition,
                        newInstanceBinding))
                {
                    result = true;
                }
            }
            else
            {
                // Is a type parameter
                TypeBinding typeBinding
                    = doc.Application.Create
                      .NewTypeBinding(cats);

                if (doc.ParameterBindings.ReInsert(
                        projectParameterData.Definition, typeBinding))
                {
                    result = true;
                }
            }
            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>
        static void PopulateProjectParameterData(
            Parameter parameter,
            ProjectParameterData projectParameterDataToFill)
        {
            // Following good SOA practices, validate 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();
            }
              }
        }
        /// <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;
        }
        /// <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="doc">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>
        static bool AddProjectParameterBinding(
            Document doc,
            ProjectParameterData projectParameterData,
            Category category)
        {
            // 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." );
              }

              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
              = doc.Application.Create
            .NewInstanceBinding( cats );

            if( doc.ParameterBindings.ReInsert(
              projectParameterData.Definition,
              newInstanceBinding ) )
            {
              result = true;
            }
              }
              else
              {
            // Is a type parameter
            TypeBinding typeBinding
              = doc.Application.Create
            .NewTypeBinding( cats );

            if( doc.ParameterBindings.ReInsert(
              projectParameterData.Definition, typeBinding ) )
            {
              result = true;
            }
              }
              return result;
        }
Пример #7
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);
        }