コード例 #1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiApp = commandData.Application;
            Document   doc   = _uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = _uiApp.ActiveUIDocument;

            // take care of AppDomain load issues
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            Transaction trans = null;

            try
            {
                if (uidoc.ActiveGraphicalView.ViewType != ViewType.ThreeD)
                {
                    throw new ApplicationException("Please run this command from a 3D View!");
                }

                string WebURL = "http://128.8.215.91";
                //DOCQRclient client = new DOCQRclient(WebURL);

                LogInFrm loginForm = new LogInFrm(WebURL, false);



                if (loginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    DOCQRclient client = loginForm.DClient;

                    WebURL = client.Server;
                    ProjectSelectFrm ProjectSelectFrm = new ProjectSelectFrm(client);
                    if (ProjectSelectFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        List <SheetInfo> sheets        = GetSheetViewInfo(doc);
                        List <ElementId> ViewsToDelete = new List <ElementId>();
                        ViewNames        names         = new ViewNames();
                        client.GetModelID(ProjectSelectFrm.SelectedProject.id);

                        ProgressForm progress = new ProgressForm(_viewCount * 3);
                        progress.Show();

                        trans = new Transaction(doc, "QR");
                        trans.Start();

                        // go through all the sheets and then views
                        // make a 3d view
                        // save each 3d view json file
                        foreach (SheetInfo sheet in sheets)
                        {
                            foreach (ViewPortInfo vpInfo in sheet.ViewPorts)
                            {
                                Spectacles.RevitExporter.Command cmd = new Spectacles.RevitExporter.Command();
                                string tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), doc.Title + vpInfo.view.Id + ".json");

                                if (progress.IsCancelled)
                                {
                                    throw new ApplicationException("DOCQR Cancelled...");
                                }
                                progress.SetStatus("Exporting View: " + vpInfo.view.Name + " to Spectacles...");
                                System.Diagnostics.Debug.WriteLine("Exporting View " + vpInfo.view.Name + " to Spectacles...");
                                View3D temp3dView = vpInfo.view.GetMatching3DView(doc);
                                cmd.ExportEntireModel(temp3dView, tempFile);
                                ViewsToDelete.Add(temp3dView.Id);

                                if (progress.IsCancelled)
                                {
                                    throw new ApplicationException("DOCQR Cancelled...");
                                }
                                progress.Step();
                                progress.SetStatus("Sending View: " + vpInfo.view.Name + " to DOCQR...");
                                vpInfo.docQRid = client.SendModelInfo(ProjectSelectFrm.SelectedProject, tempFile);            // send the model and view info to the web server
                                names.Views.Add(new ViewName()
                                {
                                    Name = vpInfo.view.Name, ID = vpInfo.docQRid
                                });
                                progress.Step();
                            }
                        }

                        //client.SendViewInfo(names);

                        progress.SetStatus("Adding QR Codes...");
                        foreach (SheetInfo sheet in sheets)
                        {
                            if (progress.IsCancelled)
                            {
                                throw new ApplicationException("DOCQR Cancelled...");
                            }
                            progress.Step();
                            RevitQR QR = new RevitQR(doc, sheet, true, WebURL);                                                   // create QR codes
                        }

                        progress.Close();

                        doc.Delete(ViewsToDelete);

                        trans.Commit();
                        trans.Dispose();

                        TaskDialog.Show("DOCQR", "QR Codes added to " + _viewCount + " viewports!");
                    }
                }
            }
            catch (ApplicationException aex)
            {
                TaskDialog.Show("DOCQR", aex.Message);
                if ((trans != null) && (trans.HasStarted()))
                {
                    trans.RollBack();
                }
                return(Result.Cancelled);
            }
            catch (Exception ex)
            {
                TaskDialog td = new TaskDialog("Unexpected Issue");
                td.MainInstruction = ex.GetType().Name + ": " + ex.Message;
                string expanded = "";
                if (ex.InnerException != null)
                {
                    expanded += Environment.NewLine + "Inner: " + ex.InnerException.GetType().Name + ": " + ex.InnerException.Message;
                }
                expanded          += Environment.NewLine + "Stack: " + ex.StackTrace;
                td.ExpandedContent = expanded;
                td.Show();
                //TaskDialog.Show("Unexpected Error", ex.GetType().Name + ": " + ex.Message);
                if ((trans != null) && (trans.HasStarted()))
                {
                    trans.RollBack();
                }
                return(Result.Failed);
            }

            //try

            // {

            //}
            //catch (System.Exception ex)
            //{
            //    return Result.Failed;
            //}

            //doc.Regenerate();

            return(Result.Succeeded);
        }
コード例 #2
0
ファイル: Command.cs プロジェクト: DOCQR/revit
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _uiApp = commandData.Application;
            Document doc = _uiApp.ActiveUIDocument.Document;
            UIDocument uidoc = _uiApp.ActiveUIDocument;

            // take care of AppDomain load issues
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            Transaction trans = null;
            try
            {

                if (uidoc.ActiveGraphicalView.ViewType != ViewType.ThreeD) throw new ApplicationException("Please run this command from a 3D View!");

                string WebURL = "http://128.8.215.91";
                //DOCQRclient client = new DOCQRclient(WebURL);

                LogInFrm loginForm = new LogInFrm(WebURL, false);

                if (loginForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    DOCQRclient client = loginForm.DClient;

                    WebURL = client.Server;
                    ProjectSelectFrm ProjectSelectFrm = new ProjectSelectFrm(client);
                    if (ProjectSelectFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        List<SheetInfo> sheets = GetSheetViewInfo(doc);
                        List<ElementId> ViewsToDelete = new List<ElementId>();
                        ViewNames names = new ViewNames();
                        client.GetModelID(ProjectSelectFrm.SelectedProject.id);

                        ProgressForm progress = new ProgressForm(_viewCount * 3);
                        progress.Show();

                        trans = new Transaction(doc, "QR");
                        trans.Start();

                        // go through all the sheets and then views
                        // make a 3d view
                        // save each 3d view json file
                        foreach (SheetInfo sheet in sheets)
                        {
                            foreach (ViewPortInfo vpInfo in sheet.ViewPorts)
                            {
                                Spectacles.RevitExporter.Command cmd = new Spectacles.RevitExporter.Command();
                                string tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), doc.Title + vpInfo.view.Id + ".json");

                                if (progress.IsCancelled) throw new ApplicationException("DOCQR Cancelled...");
                                progress.SetStatus("Exporting View: " + vpInfo.view.Name + " to Spectacles...");
                                System.Diagnostics.Debug.WriteLine("Exporting View " + vpInfo.view.Name + " to Spectacles...");
                                View3D temp3dView = vpInfo.view.GetMatching3DView(doc);
                                cmd.ExportEntireModel(temp3dView, tempFile);
                                ViewsToDelete.Add(temp3dView.Id);

                                if (progress.IsCancelled) throw new ApplicationException("DOCQR Cancelled...");
                                progress.Step();
                                progress.SetStatus("Sending View: " + vpInfo.view.Name + " to DOCQR...");
                                vpInfo.docQRid = client.SendModelInfo(ProjectSelectFrm.SelectedProject, tempFile);            // send the model and view info to the web server
                                names.Views.Add(new ViewName() { Name = vpInfo.view.Name, ID = vpInfo.docQRid });
                                progress.Step();
                            }
                        }

                        //client.SendViewInfo(names);

                        progress.SetStatus("Adding QR Codes...");
                        foreach (SheetInfo sheet in sheets)
                        {
                            if (progress.IsCancelled) throw new ApplicationException("DOCQR Cancelled...");
                            progress.Step();
                            RevitQR QR = new RevitQR(doc, sheet, true, WebURL);                                                   // create QR codes
                        }

                        progress.Close();

                        doc.Delete(ViewsToDelete);

                        trans.Commit();
                        trans.Dispose();

                        TaskDialog.Show("DOCQR", "QR Codes added to " + _viewCount + " viewports!");
                    }
                }
            }
            catch (ApplicationException aex)
            {
                TaskDialog.Show("DOCQR", aex.Message);
                if ((trans != null) && (trans.HasStarted())) trans.RollBack();
                return Result.Cancelled;
            }
            catch (Exception ex)
            {
                TaskDialog td = new TaskDialog("Unexpected Issue");
                td.MainInstruction = ex.GetType().Name + ": " + ex.Message;
                string expanded = "";
                if (ex.InnerException != null)
                {
                    expanded += Environment.NewLine + "Inner: " + ex.InnerException.GetType().Name + ": " + ex.InnerException.Message;
                }
                expanded += Environment.NewLine + "Stack: " + ex.StackTrace;
                td.ExpandedContent = expanded;
                td.Show();
                //TaskDialog.Show("Unexpected Error", ex.GetType().Name + ": " + ex.Message);
                if ((trans != null) && (trans.HasStarted())) trans.RollBack();
                return Result.Failed;
            }

            //try

            // {

            //}
            //catch (System.Exception ex)
            //{
            //    return Result.Failed;
            //}

            //doc.Regenerate();

            return Result.Succeeded;
        }