<?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 Closing active Family document in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11470176#M16377</link>
    <description>&lt;P&gt;I'm trying to open a family document do something inside it, switch to project document using UIDocument.ShowElements and close the family document, but i keep getting that there is an open transaction even though the transaction was already committed, also the snippet code attached results in having the same effect, even though there is no transaction at all.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I would appreciate any hints of how to solve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class OpenAndClose : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
             var uiApp = commandData.Application;
            var uiDoc = uiApp.ActiveUIDocument;
            var doc = uiDoc.Document;
            try
            {
                ICollection&amp;lt;ElementId&amp;gt; eLiD = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ElectricalFixtures).
                WhereElementIsNotElementType().ToElementIds();
                var firstId = eLiD.First();
                FilteredElementCollector symbols = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ElectricalFixtures)
                .WhereElementIsElementType();
                var families = new HashSet&amp;lt;Family&amp;gt;();
                var Ids = new HashSet&amp;lt;ElementId&amp;gt;();
                foreach (FamilySymbol symbol in symbols)
                {
                    Family fam = symbol.Family;
                    var id = fam.Id;
                    Ids.Add(id);
                }
                var uniquFam = new HashSet&amp;lt;Family&amp;gt;();
                foreach (ElementId id1 in Ids)
                {
                    var fam2 = doc.GetElement(id1) as Family;
                    uniquFam.Add(fam2);
                }

                foreach (Family family in uniquFam)
                {
                    var editFamDoc = doc.EditFamily(family);
                    var famUIDoc = uiApp.OpenAndActivateDocument(editFamDoc.PathName);
                    var famDoc = famUIDoc.Document;

                    uiDoc.ShowElements(eLiD);
                    famDoc.Close(false);
                }

                return Result.Succeeded;
            }

            
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AhmadAbuZnait_0-1665237816053.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1125026i51AAB1A9B3BFB409/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AhmadAbuZnait_0-1665237816053.png" alt="AhmadAbuZnait_0-1665237816053.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Oct 2022 14:12:42 GMT</pubDate>
    <dc:creator>Ahmad.AbuZnait</dc:creator>
    <dc:date>2022-10-08T14:12:42Z</dc:date>
    <item>
      <title>Closing active Family document</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11470176#M16377</link>
      <description>&lt;P&gt;I'm trying to open a family document do something inside it, switch to project document using UIDocument.ShowElements and close the family document, but i keep getting that there is an open transaction even though the transaction was already committed, also the snippet code attached results in having the same effect, even though there is no transaction at all.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I would appreciate any hints of how to solve it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public class OpenAndClose : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
             var uiApp = commandData.Application;
            var uiDoc = uiApp.ActiveUIDocument;
            var doc = uiDoc.Document;
            try
            {
                ICollection&amp;lt;ElementId&amp;gt; eLiD = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ElectricalFixtures).
                WhereElementIsNotElementType().ToElementIds();
                var firstId = eLiD.First();
                FilteredElementCollector symbols = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ElectricalFixtures)
                .WhereElementIsElementType();
                var families = new HashSet&amp;lt;Family&amp;gt;();
                var Ids = new HashSet&amp;lt;ElementId&amp;gt;();
                foreach (FamilySymbol symbol in symbols)
                {
                    Family fam = symbol.Family;
                    var id = fam.Id;
                    Ids.Add(id);
                }
                var uniquFam = new HashSet&amp;lt;Family&amp;gt;();
                foreach (ElementId id1 in Ids)
                {
                    var fam2 = doc.GetElement(id1) as Family;
                    uniquFam.Add(fam2);
                }

                foreach (Family family in uniquFam)
                {
                    var editFamDoc = doc.EditFamily(family);
                    var famUIDoc = uiApp.OpenAndActivateDocument(editFamDoc.PathName);
                    var famDoc = famUIDoc.Document;

                    uiDoc.ShowElements(eLiD);
                    famDoc.Close(false);
                }

                return Result.Succeeded;
            }

            
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AhmadAbuZnait_0-1665237816053.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1125026i51AAB1A9B3BFB409/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AhmadAbuZnait_0-1665237816053.png" alt="AhmadAbuZnait_0-1665237816053.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2022 14:12:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11470176#M16377</guid>
      <dc:creator>Ahmad.AbuZnait</dc:creator>
      <dc:date>2022-10-08T14:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Closing active Family document</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11471099#M16378</link>
      <description>&lt;P&gt;Try to use OpenAndActivateDocument instead of ShowElements to change the active document before you close the active family document&lt;/P&gt;&lt;LI-CODE lang="general"&gt;uiApp.OpenAndActivateDocument(doc.PathName);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 09 Oct 2022 10:23:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11471099#M16378</guid>
      <dc:creator>mohamedelimam</dc:creator>
      <dc:date>2022-10-09T10:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Closing active Family document</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11483581#M16379</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5903329"&gt;@mohamedelimam&lt;/a&gt;, that solved it&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 17:59:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/11483581#M16379</guid>
      <dc:creator>Ahmad.AbuZnait</dc:creator>
      <dc:date>2022-10-14T17:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: Closing active Family document</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/13020120#M16380</link>
      <description>&lt;P&gt;Do you have any explanation why this happens? I face the same issue, but I can't use OpenAndActivateDocument if it has not yet been saved.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Sep 2024 21:18:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/closing-active-family-document/m-p/13020120#M16380</guid>
      <dc:creator>tamas.deri</dc:creator>
      <dc:date>2024-09-13T21:18:06Z</dc:date>
    </item>
  </channel>
</rss>

