AddParameters() public method

add parameters to the family file
public AddParameters ( ) : bool
return bool
Beispiel #1
0
        /// <summary>
        /// add parameters to the active document
        /// </summary>
        /// <returns>
        /// if succeeded, return true; otherwise false
        /// </returns>
        private bool AddParameters()
        {
            Document doc = m_app.ActiveUIDocument.Document;

            if (null == doc)
            {
                MessageManager.MessageBuff.Append("There's no available document. \n");
                return(false);
            }

            if (!doc.IsFamilyDocument)
            {
                MessageManager.MessageBuff.Append("The active document is not a family document. \n");
                return(false);
            }

            FamilyParameterAssigner assigner = new FamilyParameterAssigner(m_app.Application, doc);
            // the parameters to be added are defined and recorded in a text file, read them from that file and load to memory
            bool succeeded = assigner.LoadParametersFromFile();

            if (!succeeded)
            {
                return(false);
            }

            Transaction t = new Transaction(doc, Guid.NewGuid().GetHashCode().ToString());

            t.Start();
            succeeded = assigner.AddParameters();
            if (succeeded)
            {
                t.Commit();
                return(true);
            }
            else
            {
                t.RollBack();
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// add parameters to the active document
        /// </summary>
        /// <returns>
        /// if succeeded, return true; otherwise false
        /// </returns>
        private bool AddParameters()
        {
            Document doc = m_app.ActiveUIDocument.Document;
             if (null == doc)
             {
            MessageManager.MessageBuff.Append("There's no available document. \n");
            return false;
             }

             if (!doc.IsFamilyDocument)
             {
            MessageManager.MessageBuff.Append("The active document is not a family document. \n");
            return false;
             }

             FamilyParameterAssigner assigner = new FamilyParameterAssigner(m_app.Application, doc);
             // the parameters to be added are defined and recorded in a text file, read them from that file and load to memory
             bool succeeded = assigner.LoadParametersFromFile();
             if (!succeeded)
             {
            return false;
             }

             Transaction t = new Transaction(doc, Guid.NewGuid().GetHashCode().ToString());
             t.Start();
             succeeded = assigner.AddParameters();
             if (succeeded)
             {
            t.Commit();
            return true;
             }
             else
             {
            t.RollBack();
            return false;
             }
        }
Beispiel #3
0
        /// <summary>
        /// search for the family files and the corresponding parameter records
        /// load each family file, add parameters and then save and close.
        /// </summary>
        /// <returns>
        /// if succeeded, return true; otherwise false
        /// </returns>
        private bool LoadFamiliesAndAddParameters()
        {
            bool succeeded = true;

            List <string> famFilePaths = new List <string>();

            Environment.SpecialFolder myDocumentsFolder = Environment.SpecialFolder.MyDocuments;
            string myDocs   = Environment.GetFolderPath(myDocumentsFolder);
            string families = myDocs + "\\AutoParameter_Families";

            if (!Directory.Exists(families))
            {
                MessageManager.MessageBuff.Append("The folder [AutoParameter_Families] doesn't exist in [MyDocuments] folder.\n");
            }
            DirectoryInfo familiesDir = new DirectoryInfo(families);

            FileInfo[] files = familiesDir.GetFiles("*.rfa");
            if (0 == files.Length)
            {
                MessageManager.MessageBuff.Append("No family file exists in [AutoParameter_Families] folder.\n");
            }
            foreach (FileInfo info in files)
            {
                if (info.IsReadOnly)
                {
                    MessageManager.MessageBuff.Append("Family file: \"" + info.FullName + "\" is read only. Can not add parameters to it.\n");
                    continue;
                }

                string   famFilePath = info.FullName;
                Document doc         = m_app.OpenDocumentFile(famFilePath);

                if (!doc.IsFamilyDocument)
                {
                    succeeded = false;
                    MessageManager.MessageBuff.Append("Document: \"" + famFilePath + "\" is not a family document.\n");
                    continue;
                }

                // return and report the errors
                if (!succeeded)
                {
                    return(false);
                }

                FamilyParameterAssigner assigner = new FamilyParameterAssigner(m_app, doc);
                // the parameters to be added are defined and recorded in a text file, read them from that file and load to memory
                succeeded = assigner.LoadParametersFromFile();
                if (!succeeded)
                {
                    MessageManager.MessageBuff.Append("Failed to load parameters from parameter files.\n");
                    return(false);
                }
                Transaction t = new Transaction(doc, Guid.NewGuid().GetHashCode().ToString());
                t.Start();
                succeeded = assigner.AddParameters();
                if (succeeded)
                {
                    t.Commit();
                    doc.Save();
                    doc.Close();
                }
                else
                {
                    t.RollBack();
                    doc.Close();
                    MessageManager.MessageBuff.Append("Failed to add parameters to " + famFilePath + ".\n");
                    return(false);
                }
            }
            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// search for the family files and the corresponding parameter records
        /// load each family file, add parameters and then save and close.
        /// </summary>
        /// <returns>
        /// if succeeded, return true; otherwise false
        /// </returns>
        private bool LoadFamiliesAndAddParameters()
        {
            bool succeeded = true;

             List<string> famFilePaths = new List<string>();

             Environment.SpecialFolder myDocumentsFolder = Environment.SpecialFolder.MyDocuments;
             string myDocs = Environment.GetFolderPath(myDocumentsFolder);
             string families = myDocs + "\\AutoParameter_Families";
             if (!Directory.Exists(families))
             {
            MessageManager.MessageBuff.Append("The folder [AutoParameter_Families] doesn't exist in [MyDocuments] folder.\n");
             }
             DirectoryInfo familiesDir = new DirectoryInfo(families);
             FileInfo[] files = familiesDir.GetFiles("*.rfa");
             if (0 == files.Length)
             {
            MessageManager.MessageBuff.Append("No family file exists in [AutoParameter_Families] folder.\n");
             }
             foreach (FileInfo info in files)
             {
            if (info.IsReadOnly)
            {
               MessageManager.MessageBuff.Append("Family file: \"" + info.FullName + "\" is read only. Can not add parameters to it.\n");
               continue;
            }

            string famFilePath = info.FullName;
            Document doc = m_app.OpenDocumentFile(famFilePath);

            if (!doc.IsFamilyDocument)
            {
               succeeded = false;
               MessageManager.MessageBuff.Append("Document: \"" + famFilePath + "\" is not a family document.\n");
               continue;
            }

            // return and report the errors
            if (!succeeded)
            {
               return false;
            }

            FamilyParameterAssigner assigner = new FamilyParameterAssigner(m_app, doc);
            // the parameters to be added are defined and recorded in a text file, read them from that file and load to memory
            succeeded = assigner.LoadParametersFromFile();
            if (!succeeded)
            {
               MessageManager.MessageBuff.Append("Failed to load parameters from parameter files.\n");
               return false;
            }
            Transaction t = new Transaction(doc, Guid.NewGuid().GetHashCode().ToString());
            t.Start();
            succeeded = assigner.AddParameters();
            if (succeeded)
            {
               t.Commit();
               doc.Save();
               doc.Close();
            }
            else
            {
               t.RollBack();
               doc.Close();
               MessageManager.MessageBuff.Append("Failed to add parameters to " + famFilePath + ".\n");
               return false;
            }
             }
             return true;
        }