<?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 ChangeTypeId of AssemblyInstance during the DMU in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8209982#M48157</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;---I am not good at English.---&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to change the assembly type of all other instances to match the changed one, then restore the assembly type name to its original name. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, the following error appears. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"An elements was modified in a way that yields a new cross reference with another element. Such changes are not allowed in the context the document is currently in."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is part of the code.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am a beginner of RevitAPI.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What is wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    public class AssEdit : IUpdater
    {
        public static bool _updateActive = true;
        static AddInId _appId;
        static UpdaterId _updaterId;

        static string rawAss = null;
        static string createdAss = null;
        static List&amp;lt;Element&amp;gt; toChangeAss = new List&amp;lt;Element&amp;gt;();
        static ElementId sourceAss = null;

        public AssEdit(AddInId id)
        {
            _appId = id;
            _updaterId = new UpdaterId(_appId, new Guid(
              "76DD8055-80CA-4400-847C-E77325936DDD"));
        }

        public void Execute(UpdaterData data)
        {
            if (_updateActive)
            {
                Document doc = data.GetDocument();
                Application app = doc.Application;

                rawAss = "AssemblyName0"; //RAW AssemblyName

                foreach (ElementId id in
                  data.GetAddedElementIds())
                {
                    Element elem = doc.GetElement(id);
                    string cat = elem.Category.Name;
                    if (cat == "Assemblies")
                    {
                        createdAss = elem.Name; //NEW AssemblyName

                        toChangeAss = new FilteredElementCollector(doc)
                            .OfCategory(BuiltInCategory.OST_Assemblies)
                            .WherePasses(new ElementClassFilter(typeof(AssemblyInstance)))
                            .Cast&amp;lt;Element&amp;gt;()
                            .Where(x =&amp;gt; x.Name == rawAss)
                            .ToList();

                        createdAssId = new FilteredElementCollector(doc)
                            .OfCategory(BuiltInCategory.OST_Assemblies)
                            .Where(x =&amp;gt; x.Name == createdAss)
                            .Select(x =&amp;gt; x.GetTypeId())
                            .First();

                        if (toChangeAss.Count() &amp;gt; 0)
                        {

                            foreach (Element ass in toChangeAss)
                            {
                                try
                                {
                                    ass.ChangeTypeId(createdAssId);
                                }
                                catch(Exception e)
                                {
                                    TaskDialog.Show("Why?", e.Message);
                                }
                            }

                            return;

                        }
                    }
                }
            }
            else
            {
                return;
            }
            
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 20 Aug 2018 01:22:23 GMT</pubDate>
    <dc:creator>SUGKJ</dc:creator>
    <dc:date>2018-08-20T01:22:23Z</dc:date>
    <item>
      <title>ChangeTypeId of AssemblyInstance during the DMU</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8209982#M48157</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;---I am not good at English.---&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to change the assembly type of all other instances to match the changed one, then restore the assembly type name to its original name. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, the following error appears. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;"An elements was modified in a way that yields a new cross reference with another element. Such changes are not allowed in the context the document is currently in."&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is part of the code.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am a beginner of RevitAPI.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;What is wrong?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    public class AssEdit : IUpdater
    {
        public static bool _updateActive = true;
        static AddInId _appId;
        static UpdaterId _updaterId;

        static string rawAss = null;
        static string createdAss = null;
        static List&amp;lt;Element&amp;gt; toChangeAss = new List&amp;lt;Element&amp;gt;();
        static ElementId sourceAss = null;

        public AssEdit(AddInId id)
        {
            _appId = id;
            _updaterId = new UpdaterId(_appId, new Guid(
              "76DD8055-80CA-4400-847C-E77325936DDD"));
        }

        public void Execute(UpdaterData data)
        {
            if (_updateActive)
            {
                Document doc = data.GetDocument();
                Application app = doc.Application;

                rawAss = "AssemblyName0"; //RAW AssemblyName

                foreach (ElementId id in
                  data.GetAddedElementIds())
                {
                    Element elem = doc.GetElement(id);
                    string cat = elem.Category.Name;
                    if (cat == "Assemblies")
                    {
                        createdAss = elem.Name; //NEW AssemblyName

                        toChangeAss = new FilteredElementCollector(doc)
                            .OfCategory(BuiltInCategory.OST_Assemblies)
                            .WherePasses(new ElementClassFilter(typeof(AssemblyInstance)))
                            .Cast&amp;lt;Element&amp;gt;()
                            .Where(x =&amp;gt; x.Name == rawAss)
                            .ToList();

                        createdAssId = new FilteredElementCollector(doc)
                            .OfCategory(BuiltInCategory.OST_Assemblies)
                            .Where(x =&amp;gt; x.Name == createdAss)
                            .Select(x =&amp;gt; x.GetTypeId())
                            .First();

                        if (toChangeAss.Count() &amp;gt; 0)
                        {

                            foreach (Element ass in toChangeAss)
                            {
                                try
                                {
                                    ass.ChangeTypeId(createdAssId);
                                }
                                catch(Exception e)
                                {
                                    TaskDialog.Show("Why?", e.Message);
                                }
                            }

                            return;

                        }
                    }
                }
            }
            else
            {
                return;
            }
            
        }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 01:22:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8209982#M48157</guid>
      <dc:creator>SUGKJ</dc:creator>
      <dc:date>2018-08-20T01:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: ChangeTypeId of AssemblyInstance during the DMU</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8210158#M48158</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Dear Sugkj,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thank you for your query.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Your English is just fine, no worries!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In this case, I would first explore exactly how you can achieve the desired operation manually through the user interface.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does that produce the same error?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Does that operation require a special situation, some special context?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;In general, if a feature is not available in the Revit product manually through the user interface, then the Revit API will not provide it either.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;You should therefore research the optimal workflow and best practices to address your task at hand manually through the user interface first.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;To do so, please discuss and analyse it with an application engineer, product usage expert, or product support.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Once you have got that part sorted out, it is time to step up into the programming environment.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I hope this helps.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeremy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Aug 2018 06:00:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8210158#M48158</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-08-20T06:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: ChangeTypeId of AssemblyInstance during the DMU</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8215413#M48159</link>
      <description>&lt;P&gt;Following the advice from you, I reconsidered the idea. And I rewrote the code and got the add-in I wanted. Thank you for your good advice.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 00:16:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/8215413#M48159</guid>
      <dc:creator>SUGKJ</dc:creator>
      <dc:date>2018-08-22T00:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: ChangeTypeId of AssemblyInstance during the DMU</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/13270999#M48160</link>
      <description>&lt;P&gt;Hi, I am trying to achieve exact same thing and I am running into same Exception message.&lt;BR /&gt;Can you please post how you menaged to solve this?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2025 07:54:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/changetypeid-of-assemblyinstance-during-the-dmu/m-p/13270999#M48160</guid>
      <dc:creator>michal_prusF4JJ2</dc:creator>
      <dc:date>2025-01-20T07:54:05Z</dc:date>
    </item>
  </channel>
</rss>

