<?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: Elements disappear after closing the form in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6504559#M63519</link>
    <description>&lt;P&gt;Peterjegan my man. That was exactly my problem. I knew it was something silly. Thank you so much.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Aug 2016 05:42:31 GMT</pubDate>
    <dc:creator>nayer.girgis</dc:creator>
    <dc:date>2016-08-17T05:42:31Z</dc:date>
    <item>
      <title>Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6498008#M63513</link>
      <description>&lt;P&gt;Hello Revit gurus,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to&amp;nbsp;C# programming&amp;nbsp;and for the past 2 days I couldn't find the solution for my problem. I have created an External addin that add tags to family instances based on its BuiltinCategory. The addin works as it should without any problems. However when I decided to create a form to&amp;nbsp;expand the functionality of the addin that is when the headaches started.&lt;/P&gt;&lt;P&gt;I cut down my program into 3 parts. The first implements the ExternalCommandData method to show the form.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;

namespace Pipes_Annotations1
{
    
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    [Autodesk.Revit.Attributes.Journaling(Autodesk.Revit.Attributes.JournalingMode.NoCommandData)]

    public class pipesannotation1 : IExternalCommand
    {        
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //tagging tagginng1 = new tagging(commandData);
            try
            {
                tagging m_tagging = new tagging();
                // show UI
                using (Form1 displayForm = new Form1(m_tagging,commandData))
                {
                    DialogResult result = displayForm.ShowDialog();
                    if (DialogResult.OK != result)
                    {
                        return Autodesk.Revit.UI.Result.Cancelled;
                    }
                }

                return Autodesk.Revit.UI.Result.Succeeded;
            }
            catch (Exception e)
            {
                message = e.Message;
                return Autodesk.Revit.UI.Result.Failed;
            }
        }
        

    }   
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Second Part creates the tags:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;namespace Pipes_Annotations1
{
    public class tagging
    {        
        public FamilySymbol elemtag1 = null;
        public FamilySymbol elemtag2 = null;        
        public void tagging1(ExternalCommandData commandData)
        {
            MessageBox.Show("Started the program");
            try
            {                
                // Get the active document and view
                UIDocument revitDoc = commandData.Application.ActiveUIDocument;
                Autodesk.Revit.DB.View view = revitDoc.Document.ActiveView;
                StringBuilder message2 = new StringBuilder();
                FilteredElementCollector viewCollector = new FilteredElementCollector(revitDoc.Document, revitDoc.ActiveView.Id);
                viewCollector.OfCategory(BuiltInCategory.OST_PipeCurves);
                message2.AppendLine("Pipes category elements within active View: "
                   + viewCollector.ToElementIds().Count);

                FilteredElementCollector docCollector = new FilteredElementCollector(revitDoc.Document);
                docCollector.OfCategory(BuiltInCategory.OST_PipeCurves);
                message2.AppendLine("Pipes category elements within document: "
                   + docCollector.ToElementIds().Count);

                FilteredElementCollector Familytagcollector = new FilteredElementCollector(revitDoc.Document);
                Familytagcollector.OfCategory(BuiltInCategory.OST_PipeTags);
                Familytagcollector.OfClass(typeof(FamilySymbol));
                message2.AppendLine("Pipes tags category elements within document: "
                   + Familytagcollector.ToElementIds().Count);

                TaskDialog.Show("Revit", message2.ToString());                

                foreach (ElementId tagID in Familytagcollector.ToElementIds())
                {
                    FamilySymbol elemtag = revitDoc.Document.GetElement(tagID) as FamilySymbol;
                    Parameter elemtagfam = elemtag.get_Parameter(BuiltInParameter.ELEM_FAMILY_PARAM);                    
                    if (elemtag.Family.Name == "Pipe Size Tag")
                    {
                        elemtag1 = elemtag;
                        MessageBox.Show(elemtag.Family.Name);                        
                    }
                    else if (elemtag.Family.Name == "BOP")
                    {
                        elemtag2 = elemtag;                        
                        MessageBox.Show(elemtag.Family.Name);
                        
                    }
                }

                string message = "";
                if (viewCollector.ToElementIds().Count == 0)
                {
                    message = "No pipe selected!";
                    MessageBox.Show(message);                    
                }
                else
                {
                    foreach (ElementId elemId in viewCollector.ToElementIds())
                    {
                        message = " " + elemId;                        
                        Element elem = revitDoc.Document.GetElement(elemId);
                        if (elem.GetType() == typeof(Autodesk.Revit.DB.Plumbing.Pipe))
                        {                                                                                
                            Autodesk.Revit.DB.Plumbing.Pipe pipe = (Autodesk.Revit.DB.Plumbing.Pipe)elem;
                            LocationCurve pipelloc = pipe.Location as LocationCurve;
                            XYZ pipeStart = pipelloc.Curve.GetEndPoint(0);
                            XYZ pipeEnd = pipelloc.Curve.GetEndPoint(1);
                            XYZ pipeMid = pipelloc.Curve.Evaluate(0.5, true);                         

                            using (Transaction t = new Transaction(revitDoc.Document))
                            {
                                t.Start("Create new tag");                                
                                IndependentTag tag = revitDoc.Document.Create.NewTag(view, pipe, false,
                                    Autodesk.Revit.DB.TagMode.TM_ADDBY_CATEGORY,
                                    Autodesk.Revit.DB.TagOrientation.Horizontal, pipeMid );
                                tag.ChangeTypeId(elemtag1.Id);
                                                           
                                t.Commit();
                            }
                        }
                    }
                }
                
            }
            catch (Exception err)
            {
                string message = err.Message;
                //return Autodesk.Revit.UI.Result.Failed;
            }
        }
     }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The 3rd part is the form. In the form Structure under the button1_Click method, I added the tagging method only without ending&amp;nbsp;this.Close();. The program works as it should and the tags are added. However, when I close the form manually, all my tags disappear. If I add &lt;SPAN&gt;this.Close(); after the tagging method, the program runs but none of the tags appear. So I am assuming that closing the form does not commit the transaction and whenever I close it all the tags disappear. I am not sure How to solve this issue and any help will be appreciated. the form code:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI.Selection;
namespace Pipes_Annotations1
{

    //[TransactionAttribute(TransactionMode.Manual)]
    //[RegenerationAttribute(RegenerationOption.Manual)]

    public partial class Form1 : System.Windows.Forms.Form
    {
        private tagging m_tagging1;        
        ExternalCommandData commandData;
        public Form1(tagging m_tagging, ExternalCommandData commandData1)
        {
            m_tagging1 = m_tagging;
            commandData =  commandData1;                      
            InitializeComponent();
            
        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            m_tagging1.tagging1(commandData);&lt;BR /&gt;        }

        
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {            
            //System.Windows.Forms.Application.Exit();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
    }
}&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Thank you so much&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Nayer Girgis&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Aug 2016 05:30:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6498008#M63513</guid>
      <dc:creator>nayer.girgis</dc:creator>
      <dc:date>2016-08-13T05:30:11Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6499703#M63514</link>
      <description>HI again guys,&lt;BR /&gt;&lt;BR /&gt;I am still stuck in this and I can't figure out what I am doing wrong. I am pretty sure it is something silly I am missing and I really need your help to figure it out.&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;Nayer</description>
      <pubDate>Mon, 15 Aug 2016 03:10:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6499703#M63514</guid>
      <dc:creator>nayer.girgis</dc:creator>
      <dc:date>2016-08-15T03:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6499766#M63515</link>
      <description>&lt;P&gt;Please provide sample RVT file and the VS solution so I may help.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 04:59:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6499766#M63515</guid>
      <dc:creator>Mustafa.Salaheldin</dc:creator>
      <dc:date>2016-08-15T04:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6499790#M63516</link>
      <description>&lt;P&gt;Thank you so much Mustafa. I have attached the rvt test file and a .rar file that contains VS solution. Can't wait for your feedback.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 05:31:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6499790#M63516</guid>
      <dc:creator>nayer.girgis</dc:creator>
      <dc:date>2016-08-15T05:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6502252#M63517</link>
      <description>&lt;P&gt;I still don't understand what I am missing.&amp;nbsp;The tags are added without any problems if I ran the externalcommand directly without a form. For some reason when I add a form to my program, all my tags disappear when&amp;nbsp;I close it. There is something I am missing in the form that should keep the added tags after closing the it. I really ran out of ideas and I would really&amp;nbsp;appreciate if someone could put me on the right track.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 06:39:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6502252#M63517</guid>
      <dc:creator>nayer.girgis</dc:creator>
      <dc:date>2016-08-16T06:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6504003#M63518</link>
      <description>&lt;P&gt;I would recommend changing the DialogResult of your button2 to "OK". Right now, it is set to "None".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When your code reaches "if (DialogResult.OK != result)," it finds a match (OK != None) and executes "return Autodesk.Revit.UI.Result.Cancelled;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2016 20:34:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6504003#M63518</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-08-16T20:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6504559#M63519</link>
      <description>&lt;P&gt;Peterjegan my man. That was exactly my problem. I knew it was something silly. Thank you so much.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2016 05:42:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/6504559#M63519</guid>
      <dc:creator>nayer.girgis</dc:creator>
      <dc:date>2016-08-17T05:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: Elements disappear after closing the form</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/13106904#M63520</link>
      <description>thanks for the post</description>
      <pubDate>Thu, 24 Oct 2024 23:16:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/elements-disappear-after-closing-the-form/m-p/13106904#M63520</guid>
      <dc:creator>errolhq</dc:creator>
      <dc:date>2024-10-24T23:16:14Z</dc:date>
    </item>
  </channel>
</rss>

