コード例 #1
0
        public static void ActivateInstance(Document InDocument)
        {
            // Disable existing instance, if there's active one.
            ActiveInstance?.MakeActive(false);
            ActiveInstance = null;

            // Find out if we already have instance for this document and
            // activate it if we do. Otherwise, create new one.

            FDirectLink InstanceToActivate = null;

            foreach (FDirectLink DL in Instances)
            {
                if (DL.RootCache.SourceDocument.Equals(InDocument))
                {
                    InstanceToActivate = DL;
                    break;
                }
            }

            if (InstanceToActivate == null)
            {
                InstanceToActivate = new FDirectLink(InDocument);
                Instances.Add(InstanceToActivate);
            }

            InstanceToActivate.MakeActive(true);
            ActiveInstance = InstanceToActivate;
        }
コード例 #2
0
 public static void DestroyInstance(FDirectLink Instance, Application InApp)
 {
     if (ActiveInstance == Instance)
     {
         ActiveInstance = null;
     }
     Instances.Remove(Instance);
     Instance?.Destroy(InApp);
 }
コード例 #3
0
        static void OnViewActivated(object sender, ViewActivatedEventArgs e)
        {
            View Previous = e.PreviousActiveView;
            View Current  = e.CurrentActiveView;

            if (Previous == null || !Previous.Document.Equals(Current.Document))
            {
                FDirectLink.ActivateInstance(Current.Document);
            }
        }
コード例 #4
0
        public FDatasmithRevitExportContext(
            Application InApplication,                                        // running Revit application
            Document InDocument,                                              // active Revit document
            Dictionary <ElementId, string> InDatasmithFilePaths,              // Datasmith output file path
            DatasmithRevitExportOptions InExportOptions,                      // Unreal Datasmith export options
            FDirectLink InDirectLink                                          // DirectLink manager
            )
        {
            ProductVersion     = InApplication.VersionNumber;
            DatasmithFilePaths = InDatasmithFilePaths;
            RevitDocument      = InDocument;
            DirectLink         = InDirectLink;

            // Get the Unreal Datasmith export options.
            DebugLog            = InExportOptions.GetWriteLogFile() ? new FDatasmithFacadeLog() : null;
            LevelOfTessellation = InExportOptions.GetLevelOfTessellation();
        }
コード例 #5
0
        public static void OnDocumentChanged(
            object InSender,
            DocumentChangedEventArgs InArgs)
        {
            FDirectLink DirectLink = FDirectLink.Get();

            Debug.Assert(DirectLink != null);

            // Handle modified elements
            foreach (ElementId ElemId in InArgs.GetModifiedElementIds())
            {
                Element ModifiedElement = DirectLink.RootCache.SourceDocument.GetElement(ElemId);

                if (ModifiedElement.GetType() == typeof(RevitLinkInstance))
                {
                    DirectLink.ModifiedLinkedDocuments.Add((ModifiedElement as RevitLinkInstance).GetLinkDocument());
                }

                DirectLink.RootCache.ModifiedElements.Add(ElemId);
            }
        }
コード例 #6
0
 static void OnDocumentClosing(object sender, DocumentClosingEventArgs e)
 {
     FDirectLink.DestroyInstance(FDirectLink.FindInstance(e.Document), e.Document.Application);
 }
コード例 #7
0
        public override Result OnExecute(ExternalCommandData InCommandData, ref string OutCommandMessage, ElementSet OutElements)
        {
            UIDocument UIDoc      = InCommandData.Application.ActiveUIDocument;
            Document   Doc        = UIDoc.Document;
            View3D     ActiveView = Doc.ActiveView as View3D;

            if (ActiveView == null)
            {
                string Message = "You must be in a 3D view to export.";
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            if (ActiveView.IsTemplate || !ActiveView.CanBePrinted)
            {
                string Message = "The active 3D view cannot be exported.";
                MessageBox.Show(Message, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(Result.Cancelled);
            }

            Debug.Assert(FDirectLink.Get() != null);

            // Holding ctrl will force full sync.
            if (FDirectLink.Get().SyncCount > 0 && (System.Windows.Forms.Control.ModifierKeys & Keys.Control) == Keys.Control)
            {
                FDirectLink.DestroyInstance(FDirectLink.Get(), InCommandData.Application.Application);
                FDirectLink.ActivateInstance(Doc);
            }

            FDatasmithRevitExportContext ExportContext = new FDatasmithRevitExportContext(
                InCommandData.Application.Application,
                Doc,
                null,
                new DatasmithRevitExportOptions(Doc),
                FDirectLink.Get());

            // Export the active 3D View to the given Unreal Datasmith file.
            using (CustomExporter Exporter = new CustomExporter(Doc, ExportContext))
            {
                try
                {
                    // The export process will exclude output of geometric objects such as faces and curves,
                    // but the context needs to receive the calls related to Faces or Curves to gather data.
                    // The context always receive their tessellated geometry in form of polymeshes or lines.
                    Exporter.IncludeGeometricObjects = true;

                    // The export process should stop in case an error occurs during any of the exporting methods.
                    Exporter.ShouldStopOnError = true;

#if REVIT_API_2020
                    Exporter.Export(ActiveView as Autodesk.Revit.DB.View);
#else
                    Exporter.Export(ActiveView);
#endif
                }
                catch (System.Exception exception)
                {
                    OutCommandMessage = string.Format("Cannot export the 3D view:\n\n{0}\n\n{1}", exception.Message, exception.StackTrace);
                    MessageBox.Show(OutCommandMessage, DIALOG_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(Result.Failed);
                }
                finally
                {
                    if (ExportContext.GetMessages().Count > 0)
                    {
                        string Messages = string.Join($"{System.Environment.NewLine}", ExportContext.GetMessages());
                        DatasmithRevitApplication.SetExportMessages(Messages);
                    }
                }
            }

            return(Result.Succeeded);
        }