private void OnSaveDaxToBimQueryStatus(object sender, EventArgs e)
 {
     try
     {
         OleMenuCommand myCommand = sender as OleMenuCommand;
         if (myCommand != null)
         {
             bool isEnabled = false;
             if (_envDte != null)
             {
                 var wnd = _envDte.ActiveWindow;
                 if (wnd != null && wnd.Caption != null && wnd.Caption.ToLower().EndsWith(".dax"))
                 {
                     Document activeDocument = _envDte.ActiveDocument;
                     if (activeDocument != null && activeDocument.FullName != null)
                     {
                         isEnabled = BimFileIntegration.IsAvailable(activeDocument.FullName);
                     }
                 }
             }
             myCommand.Enabled = isEnabled;
         }
     }
     catch (Exception exc)
     {
         Debug.Fail(exc.Message, exc.StackTrace);
     }
 }
        private void EditAdvancedGetBimFileContentCommandExecute(object sender, EventArgs e)
        {
            try
            {
                Document activeDocument = _envDte.ActiveDocument;
                if (activeDocument != null)
                {
                    string bimFileName = activeDocument.FullName;
                    if (bimFileName == null || !bimFileName.EndsWith(".bim", StringComparison.InvariantCultureIgnoreCase))
                    {
                        System.Windows.Forms.MessageBox.Show("Command to be called on active .BIM file", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }

                    string daxFilePath = BimFileIntegration.ConvertBimPathToDaxPath(bimFileName);
                    if (File.Exists(daxFilePath) && (new FileInfo(daxFilePath)).IsReadOnly)
                    {
                        System.Windows.Forms.MessageBox.Show(string.Format("{0} file is read only", daxFilePath), "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return;
                    }

                    string fileContents = BimFileIntegration.GetMeasuresFromBimFile(bimFileName);
                    if (fileContents != null)
                    {
                        System.IO.File.WriteAllText(daxFilePath, fileContents);
                        _envDte.ExecuteCommand(string.Format(@"File.OpenFile ""{0}""", daxFilePath));
                    }
                }
            }
            catch (Exception exc)
            {
                DisplayExceptionWindow(exc);
            }
        }
 private void EditAdvancedSaveBimFileContentCommandExecute(object sender, EventArgs e)
 {
     try
     {
         _envDte.ExecuteCommand("File.SaveSelectedItems");
         Document activeDocument = _envDte.ActiveDocument;
         BimFileIntegration.SaveMeasuresToBimFile(activeDocument.FullName);
     }
     catch (Exception exc)
     {
         DisplayExceptionWindow(exc);
     }
 }
 private void CreateDaxFileCommandExecute(object sender, EventArgs e)
 {
     try
     {
         Document    activeDocument = _envDte.ActiveDocument;
         string      daxFilePath    = BimFileIntegration.CreateDaxFile(activeDocument.FullName);
         ProjectItem daxItem        = _envDte.ActiveDocument.ProjectItem.ContainingProject.ProjectItems.AddFromFile(daxFilePath);
         var         daxWindow      = daxItem.Open();
         daxItem.Document.Activate();
     }
     catch (Exception exc)
     {
         DisplayExceptionWindow(exc);
     }
 }
        /// <summary>
        /// Create DAX file from active BIM document
        /// </summary>
        /// <param name="activeDocumentPath">Path to currently opened BIM model</param>
        /// <returns>Path to created DAX file</returns>
        public static string CreateDaxFile(string activeDocumentPath)
        {
            string extension = Path.GetExtension(activeDocumentPath);

            if (!extension.Equals(BimExtension, StringComparison.InvariantCultureIgnoreCase))
            {
                throw new ArgumentException("DAX file can only be created from opened BIM model");
            }
            string daxFilePath = activeDocumentPath.Substring(0, activeDocumentPath.Length - BimExtension.Length) + DaxExtension;

            if (File.Exists(daxFilePath))
            {
                throw new ApplicationException(string.Format("DAX file {0} already exists", daxFilePath));
            }

            string fileContents = BimFileIntegration.GetMeasuresFromBimFile(daxFilePath);

            File.WriteAllText(daxFilePath, string.IsNullOrEmpty(fileContents) ? "" : fileContents);
            return(daxFilePath);
        }