コード例 #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
ファイル: AutoParameter.cs プロジェクト: alnjxn/opnRvt
        /// <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.MyComputer;
            string myDocs = Environment.GetFolderPath(myDocumentsFolder);

            FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

            folderBrowserDialog1.RootFolder          = myDocumentsFolder;
            folderBrowserDialog1.ShowNewFolderButton = false;
            folderBrowserDialog1.Description         = "Select the Folder containing the families to be processed:";

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                string families = folderBrowserDialog1.SelectedPath;
                //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);
            }
            return(false);
        }
コード例 #4
0
ファイル: AutoParameter.cs プロジェクト: alnjxn/opnRvt
        /// <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.MyComputer;
               string myDocs = Environment.GetFolderPath(myDocumentsFolder);

               FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
               folderBrowserDialog1.RootFolder = myDocumentsFolder;
               folderBrowserDialog1.ShowNewFolderButton = false;
               folderBrowserDialog1.Description = "Select the Folder containing the families to be processed:";

               if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
               {
               string families = folderBrowserDialog1.SelectedPath;
               //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;
               }
               return false;
        }