Esempio n. 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                ExternalApp.FirstTimeRun(); // analytics
                Document doc = commandData.Application.ActiveUIDocument.Document;

                IList <Document> allDocs = Utilities.RevitUtils.GetCurrentDocumentAndLinks(doc);

                string filename = String.Empty;


                UI.CompareForm form = new UI.CompareForm(doc, allDocs, this);
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancelled);
                }
                filename = form.SelectedFile;
                string folder  = Path.GetDirectoryName(filename);
                string tmpFile = GetFilenameHint(form.Document);

                bool dateStamp = form.DateStamp;

                Document chosenDoc = form.Document;

                ComparisonMaker comparison = new ComparisonMaker(chosenDoc, filename);
                comparison.AllCategories       = form.AllCategories;
                comparison.RequestedCategories = form.SelectedCategories;

                try
                {
                    double moveTol;
                    float  angTol;
                    Utilities.Settings.ReadTolerance(out moveTol, out angTol);
                    comparison.MoveTolerance   = moveTol;
                    comparison.RotateTolerance = angTol;
                }
                catch (Exception ex)
                {
                    doc.Application.WriteJournalComment("Exception reading tolerances from settings file: " + ex.GetType().Name + ": " + ex.Message, false);
                }
                doc.Application.WriteJournalComment("Tolerances: Distance: " + comparison.MoveTolerance + " Angle: " + comparison.RotateTolerance, false);

                IList <Objects.Change> changes = comparison.Compare();

                if (changes.Count > 0)
                {
                    string jsonFile = Path.Combine(folder, Path.GetFileNameWithoutExtension(tmpFile) + "-Changes-Latest.json");
                    comparison.Serialize(jsonFile, changes);
                    if (dateStamp)
                    {
                        jsonFile = Path.Combine(folder, Path.GetFileNameWithoutExtension(tmpFile) + "-Changes-" + DateTime.Now.ToString("yyyyMMdd_hhmm") + ".json");
                        comparison.Serialize(jsonFile, changes);
                    }


                    UI.CompareResultsForm results = new UI.CompareResultsForm(new UIDocument(doc), chosenDoc, changes);
                    int x, y;
                    Utilities.RevitUtils.GetExtents(commandData.Application, out x, out y);
                    results.Location = new System.Drawing.Point(x, y);


                    IntPtr currentRevitWin = Utilities.Utility.GetMainWindowHandle();
                    if (currentRevitWin != null)
                    {
                        Utilities.WindowHandle handle = new Utilities.WindowHandle(currentRevitWin);

                        results.Show(handle);
                    }
                    else
                    {
                        results.Show();
                    }
                }
                else
                {
                    MessageBox.Show("Found no changes between this model and the previous snapshot.");
                }



                return(Result.Succeeded);
            }
            catch (ApplicationException aex)
            {
                MessageBox.Show(aex.Message);
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex);
                return(Result.Failed);
            }
        }
Esempio n. 2
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                ExternalApp.FirstTimeRun(); // analytics
                Document doc = commandData.Application.ActiveUIDocument.Document;

                IList <Document> allDocs = Utilities.RevitUtils.GetCurrentDocumentAndLinks(doc);

                string filename = String.Empty;


                UI.ComparePreviousForm form = new UI.ComparePreviousForm(doc, allDocs, this);
                if (form.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancelled);
                }
                filename = form.SelectedFile;
                //string folder = Path.GetDirectoryName(filename);

                if (filename.ToUpper().StartsWith("HTTP"))
                {
                    filename = getFile(filename);
                }

                Document chosenDoc = form.Document;

                var cs = ComparisonMaker.DeSerialize(filename);

                // check if the filenames match?
                if (String.IsNullOrEmpty(chosenDoc.Title) == false)
                {
                    string f1 = System.IO.Path.GetFileName(cs.ModelName);
                    if (String.IsNullOrEmpty(f1) == false)
                    {
                        if (f1.ToUpper() != chosenDoc.Title.ToUpper())
                        {
                            TaskDialog td = new TaskDialog("Same File?");
                            td.MainContent = "The chosen document and the chosen results file appear to be from different sources?" + Environment.NewLine +
                                             " Document: " + chosenDoc.Title + Environment.NewLine +
                                             " File:     " + f1;

                            td.AddCommandLink(TaskDialogCommandLinkId.CommandLink1, "Continue Anyway", "If they really don't match, the highlighting might be suspect.");
                            td.AddCommandLink(TaskDialogCommandLinkId.CommandLink2, "Cancel This", "I'll look for a better match.");

                            var result = td.Show();

                            if (result != TaskDialogResult.CommandLink1)
                            {
                                return(Result.Cancelled);
                            }
                        }
                    }
                }


                IList <Objects.Change> changes = cs.Changes;

                if (changes.Count > 0)
                {
                    UI.CompareResultsForm results = new UI.CompareResultsForm(new UIDocument(doc), chosenDoc, changes);
                    int x, y;
                    Utilities.RevitUtils.GetExtents(commandData.Application, out x, out y);
                    results.Location = new System.Drawing.Point(x, y);


                    IntPtr currentRevitWin = Utilities.Utility.GetMainWindowHandle();
                    if (currentRevitWin != null)
                    {
                        Utilities.WindowHandle handle = new Utilities.WindowHandle(currentRevitWin);

                        results.Show(handle);
                    }
                    else
                    {
                        results.Show();
                    }
                }
                else
                {
                    MessageBox.Show("There were no changes in the change summary file?");
                }



                return(Result.Succeeded);
            }
            catch (ApplicationException aex)
            {
                MessageBox.Show(aex.Message);
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex);
                return(Result.Failed);
            }
        }