<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Exporting to DWG after Dynamo script being executed in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488016#M16244</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just found out that the&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ICollection&amp;lt;ElementId&amp;gt; selectedIds = uidoc.Selection.GetElementIds();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;is not getting any Ids.&lt;BR /&gt;If anyone sees what is causing this, please let me know&lt;/P&gt;</description>
    <pubDate>Mon, 17 Oct 2022 14:41:34 GMT</pubDate>
    <dc:creator>joaofmoco</dc:creator>
    <dc:date>2022-10-17T14:41:34Z</dc:date>
    <item>
      <title>Exporting to DWG after Dynamo script being executed</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11487750#M16243</link>
      <description>&lt;P&gt;Hello everyone,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I am developing an add-in for Revit that automatically opens a file, executes a Dynamo script and exports the views to a DWG file. However, I'm having issues implementing the last step. From what I understood, the code where I define the DWG export settings is not being executed. My only questions are: What's causing this? And what can I do to fix this?&lt;/P&gt;&lt;P&gt;The Command and App classes in C# are exposed, in order, bellow:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Dynamo.Applications;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

#endregion

namespace DynamoAddin
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Command : IExternalCommand
    {
        string Journal_Dynamo_Path = @"C:\Users\JoãoMoço\Documents\Dynamo\structure.dyn";

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application and document objects and start transaction
            UIApplication uiapp = commandData.Application;
            Document doc = uiapp.ActiveUIDocument.Document;
            Application app = uiapp.Application;
            UIDocument uidoc = new UIDocument(doc);

            DynamoRevit dynamoRevit = new DynamoRevit();
            DynamoRevitCommandData dynamoRevitCommandData = new DynamoRevitCommandData();
            dynamoRevitCommandData.Application = commandData.Application;
            IDictionary&amp;lt;string, string&amp;gt; journalData = new Dictionary&amp;lt;string, string&amp;gt;
            {
                { Dynamo.Applications.JournalKeys.ShowUiKey, false.ToString() }, // don't show DynamoUI at runtime
                { Dynamo.Applications.JournalKeys.AutomationModeKey, true.ToString() }, //run journal automatically
                { Dynamo.Applications.JournalKeys.DynPathKey, Journal_Dynamo_Path }, //run node at this file path
                { Dynamo.Applications.JournalKeys.DynPathExecuteKey, true.ToString() }, // The journal file can specify if the Dynamo workspace opened from DynPathKey will be executed or not. If we are in automation mode the workspace will be executed regardless of this key.
                { Dynamo.Applications.JournalKeys.ForceManualRunKey, false.ToString() }, // don't run in manual mode
                { Dynamo.Applications.JournalKeys.ModelShutDownKey, true.ToString() },
                { Dynamo.Applications.JournalKeys.ModelNodesInfo, false.ToString() }

            };

            dynamoRevitCommandData.JournalData = journalData;
            Result externalCommandResult = dynamoRevit.ExecuteCommand(dynamoRevitCommandData);
            //return externalCommandResult;

            try
            {
                using (Transaction tx = new Transaction(doc))
                {
                    string dwgPath = "C:\\Users\\JoãoMoço\\Documents\\Dynamo";
                    tx.Start("ExportDWG");

                    doc.Regenerate();

                    ICollection&amp;lt;ElementId&amp;gt; selectedIds = uidoc.Selection.GetElementIds();
                    foreach (ElementId e in selectedIds)
                    {
                        // Setting DWG Export Options
                        DWGExportOptions options = new DWGExportOptions();
                        ExportDWGSettings dwgSettings = ExportDWGSettings.Create(doc, "IBAS Export");
                        options = dwgSettings.GetDWGExportOptions();

                        options.Colors = ExportColorMode.TrueColorPerView;
                        options.FileVersion = ACADVersion.R2018;
                        options.MergedViews = true;
                        Element f = doc.GetElement(e);
                        ElementType ftype = doc.GetElement(f.GetTypeId()) as ElementType;
                        List&amp;lt;ElementId&amp;gt; collection = new List&amp;lt;ElementId&amp;gt;();
                        collection.Add(e);

                        // Export file as DWG
                        doc.Export(dwgPath, ftype.FamilyName + " " + f.Name, collection, options);
                        ElementId dwgSettingId = dwgSettings.Id;

                        doc.Delete(dwgSettingId);
                    }


                    tx.Commit();
                }

                return Result.Succeeded;
            }
            catch
            {
                return Result.Failed;
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#region Namespaces
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
using Dynamo.Applications;
using System;
using System.Collections.Generic;

#endregion

namespace DynamoAddin
{
    class App : IExternalApplication
    {
        string revitFilePath = @"C:\Users\JoãoMoço\Documents\Dynamo\Template.rvt";
        string commandId = "0a2ba4ad-c3a9-450d-aed1-4cfe6413228e";

        public Result OnStartup(UIControlledApplication a)
        {
            a.ControlledApplication.ApplicationInitialized += OnApplicationInitialized;

            return Result.Succeeded;
        }

        void OnApplicationInitialized(object sender, ApplicationInitializedEventArgs e)
        {
            Application app = sender as Application;
            UIApplication uiapp = new UIApplication(app);

            uiapp.OpenAndActivateDocument(revitFilePath);

            RevitCommandId idAddinCommand = RevitCommandId.LookupCommandId(commandId);
            uiapp.PostCommand(idAddinCommand);
        }

        public Result OnShutdown(UIControlledApplication a)
        {
            a.ControlledApplication.ApplicationInitialized -= OnApplicationInitialized;

            return Result.Succeeded;
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The .sln file and the .dyn script are attached to this post.&lt;BR /&gt;Any feedback is helpful&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 12:39:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11487750#M16243</guid>
      <dc:creator>joaofmoco</dc:creator>
      <dc:date>2022-10-17T12:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to DWG after Dynamo script being executed</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488016#M16244</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Update:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just found out that the&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;ICollection&amp;lt;ElementId&amp;gt; selectedIds = uidoc.Selection.GetElementIds();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;is not getting any Ids.&lt;BR /&gt;If anyone sees what is causing this, please let me know&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 14:41:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488016#M16244</guid>
      <dc:creator>joaofmoco</dc:creator>
      <dc:date>2022-10-17T14:41:34Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to DWG after Dynamo script being executed</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488029#M16245</link>
      <description>&lt;P&gt;Does the commandId constant refer to your Dynamo external command? I assume it does, so the PostCommand call actually launches your external command that in turn launches your Dynamo code via&amp;nbsp;dynamoRevit.ExecuteCommand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can imagine the&amp;nbsp;call to dynamoRevit.ExecuteCommand puts Revit into a state from which it will not return to execute the rest of the code following that statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can imagine various ways to resolve this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My preference would be to rewrite the external Dynamo code and place the appropriate pure native Revit API code replacing it into the external command instead of calling dynamoRevit.ExecuteCommand. That would simplify the whole structure significantly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is difficult or impossible, you might want to place the DWG export code into its own external command that is launched subsequently, after the Dynamo stuff. One approach to achieve that is being discussed right now as we speak in this parallel thread on how to chain Idling events:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;A href="https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11484370" target="_blank"&gt;https://forums.autodesk.com/t5/revit-api-forum/can-you-chain-idling-events/m-p/11484370&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 14:47:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488029#M16245</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-17T14:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to DWG after Dynamo script being executed</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488090#M16246</link>
      <description>&lt;P&gt;Hello Jeremy and thank you for replying,&lt;BR /&gt;&lt;BR /&gt;Yes,&amp;nbsp;&lt;SPAN&gt;the commandId constant refers to your Dynamo external command.&lt;BR /&gt;The objective here was to chain a series of events together.&lt;BR /&gt;Originally, this was supposed to be all contained in C#,&amp;nbsp;but a Dynamo script was developed in parallel&amp;nbsp;since Dynamo as a built-in Excel import feature.&amp;nbsp;&lt;BR /&gt;When you speak of placing the DWG export code inside another External Command, do you mean inside of the same .sln file (Being another IExternalCommand class)?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 15:13:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488090#M16246</guid>
      <dc:creator>joaofmoco</dc:creator>
      <dc:date>2022-10-17T15:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to DWG after Dynamo script being executed</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488308#M16247</link>
      <description>&lt;DIV id="bodyDisplay_2" class="lia-message-body lia-component-message-view-widget-body lia-component-body-signature-highlight-escalation lia-component-message-view-widget-body-signature-highlight-escalation"&gt;
&lt;DIV class="lia-message-body-content"&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;gt; do you mean inside of the same .sln file?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes. Same VS SLN, and also same .NET assembly DLL.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; &amp;gt; Being another IExternalCommand class?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="custom-add-tag"&gt;
&lt;DIV class="lia-panel lia-panel-standard MessageTagsTaplet Chrome lia-component-message-view-widget-tags"&gt;
&lt;DIV class="lia-decoration-border"&gt;
&lt;DIV class="lia-decoration-border-top"&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV class="lia-decoration-border-content"&gt;
&lt;DIV&gt;
&lt;DIV class="lia-panel-heading-bar-wrapper"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 17 Oct 2022 16:26:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11488308#M16247</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2022-10-17T16:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Exporting to DWG after Dynamo script being executed</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11490610#M16248</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Update on the situation:&lt;/STRONG&gt;&lt;BR /&gt;I managed to circumvent the situation by adding the DWG Export functionality on the Dynamo script.&lt;BR /&gt;&lt;BR /&gt;Thank you to everyone &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Oct 2022 13:38:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/exporting-to-dwg-after-dynamo-script-being-executed/m-p/11490610#M16248</guid>
      <dc:creator>joaofmoco</dc:creator>
      <dc:date>2022-10-18T13:38:38Z</dc:date>
    </item>
  </channel>
</rss>

