add parameters(family parameters/shared parameters) to the opened family file the parameters are recorded in txt file following certain formats
コード例 #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);
            }
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: AMEE/revit
        /// <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;
             }
        }
コード例 #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);
        }
コード例 #4
0
ファイル: Command.cs プロジェクト: AMEE/revit
        /// <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;
        }