<?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: VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings? in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10455318#M26614</link>
    <description>&lt;P&gt;Have you tried iterating the BindingMap and changing the category set for the matching definition i.e. change ElementBinding.Categories in place? I'm not sure this is possible but seems odd to ReInsert when the definition hasn't changed only the category set has.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are warnings about set_Item on BindingMap however. Not sure if that extends to the members of the item or if the item of the iterator is detached from original so changes to it are pointless without reinserting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most categories exist without an element of such needing to, what was the issue binding to all? Document.Settings.Categories you can iterate it and check Categoeries.AllowsBoundParameters.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jul 2021 10:58:25 GMT</pubDate>
    <dc:creator>RPTHOMAS108</dc:creator>
    <dc:date>2021-07-09T10:58:25Z</dc:date>
    <item>
      <title>VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10237400#M26611</link>
      <description>&lt;P&gt;Our plugin maintains some instance parameter values across many elements, including those in groups.&lt;/P&gt;&lt;P&gt;Occasionally the end users will introduce data that activates an unused Category,&lt;/P&gt;&lt;P&gt;so we have to update the document parameter bindings, to include those categories.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, when we call&lt;/P&gt;&lt;P&gt;doc.ParameterBindings.ReInsert()&lt;/P&gt;&lt;P&gt;our existing parameter values inside groups are lost, because our VariesAcrossGroups flag is toggled back to false?&lt;/P&gt;&lt;P&gt;How did Revit intend this to work - are we supposed to use this in a different way, to not trigger this problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ReInsert() expects a base Definition argument, and would usualy get an ExternalDefinition supplied.&lt;/P&gt;&lt;P&gt;To learn, I instead tried to scan through the definition-keys of existing bindings and match those.&lt;/P&gt;&lt;P&gt;This way, I got the document's InternalDefinition, and tried calling Reinsert with that instead&lt;/P&gt;&lt;P&gt;(my hope was, that since its existing InternalDefinition DID include VariesAcrossGroups=true, this would help.)&lt;/P&gt;&lt;P&gt;Alas, Reinsert&amp;nbsp; doesn't seem to care.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem, as you might guess, is that after VariesAcrossGroups=False, a lot of my instance parameters have collapsed into each other, so they all hold identical values. Given that they are IDs, this is less than ideal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current (intended) solution is to instead grab a backup of all existing parameter values BEFORE I update the bindings, then after the binding-update and variesAcrossGroups back to true,&lt;/P&gt;&lt;P&gt;then inspect all values and re-assign all parameter-values that have been broken.&lt;/P&gt;&lt;P&gt;But as you may surmise, this is less than ideal - it will be horribly slow for the users to use our plugin,&lt;/P&gt;&lt;P&gt;and frankly it seems like something the revitAPI should take care of, not the plugin developer.&lt;/P&gt;&lt;P&gt;Are we using this the wrong way?&lt;/P&gt;&lt;P&gt;One approach I have considered, is to bind every possibly category I can think of, up front and once only.&lt;/P&gt;&lt;P&gt;&amp;nbsp; But I'm not sure that is possible. Categories in themselves are also difficult to work with, as you can only create them indirectly, by using your Project-Document as a factory (i.e. you cannot create a category yourself, you can only indirectly ask the Document to - maybe! - create a category for you, that you request). Because of this, I don't think you can bind for all categories up front - some categories only become available&amp;nbsp; in the document, AFTER you have included a given family/type in your project.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To sum it up:&lt;/P&gt;&lt;P&gt;First, I&lt;/P&gt;&lt;P&gt;doc.ParameterBindings.ReInsert() my binding, with the updated categories.&lt;/P&gt;&lt;P&gt;Then, I call InternalDefinition.SetAllowVaryBetweenGroups()&lt;/P&gt;&lt;P&gt;(after having determined IDEF.VariesAcrossGroups has reverted back to false.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am interested to hear the best way to do this, without destroying the client's existing data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 12:02:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10237400#M26611</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-14T12:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10452983#M26612</link>
      <description>&lt;P&gt;JG, we are currently experiencing the exact behavior and am wondering if youd found a solution.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jul 2021 14:30:10 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10452983#M26612</guid>
      <dc:creator>ChrisHildebranAtWork</dc:creator>
      <dc:date>2021-07-08T14:30:10Z</dc:date>
    </item>
    <item>
      <title>Re: VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10455035#M26613</link>
      <description>No, unfortunately. I still handle it in the manual cumbersome way I described, ie I back up the critical data before updating, then write it back in places where it has changed. However, given it only affects data in groups, it is possible to narrow down the affected data somewhat (e.g. group members will have data in Element.GroupId.)&lt;BR /&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:33:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10455035#M26613</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-07-09T08:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10455318#M26614</link>
      <description>&lt;P&gt;Have you tried iterating the BindingMap and changing the category set for the matching definition i.e. change ElementBinding.Categories in place? I'm not sure this is possible but seems odd to ReInsert when the definition hasn't changed only the category set has.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are warnings about set_Item on BindingMap however. Not sure if that extends to the members of the item or if the item of the iterator is detached from original so changes to it are pointless without reinserting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Most categories exist without an element of such needing to, what was the issue binding to all? Document.Settings.Categories you can iterate it and check Categoeries.AllowsBoundParameters.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 10:58:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10455318#M26614</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-07-09T10:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10462293#M26615</link>
      <description>Thanks for the insight JG!</description>
      <pubDate>Mon, 12 Jul 2021 15:25:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/10462293#M26615</guid>
      <dc:creator>ChrisHildebranAtWork</dc:creator>
      <dc:date>2021-07-12T15:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: VariesAcrossGroups lost when ReInsert_ing doc.ParameterBindings?</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/11823541#M26616</link>
      <description>&lt;P&gt;Hi jg,&amp;nbsp; to avoid this problem you need to set SetAllowVaryBetweenGroups =false BEFORE calling ReInsert method and then bring back SetAllowVaryBetweenGroups = true if it's necessary.&amp;nbsp;If you do this inside a transaction you don't lose data.&lt;/P&gt;&lt;P&gt;This happens always when exixts at least one GroupType into the model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here the code snippet:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;using (Transaction t = new Transaction(doc, "Reinsert"))
{
    t.start();

    InternalDefinition intDef = def as InternalDefinition

    bool canVary = intDef.VariesAcrossGroups;
    intDef.SetAllowVaryBetweenGroups(doc, false);

    if (!doc.ParameterBindings.ReInsert(extDef, ib, pGroup))
    {
        doc.ParameterBindings.Remove(defFound);
        doc.ParameterBindings.Insert(extDef, ib, pGroup);
    }

    // If 'canVary' was true bring it back to true  
    if (canVary)
        intDef.SetAllowVaryBetweenGroups(doc, true);

    t.commit();
}
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if it works for you.&lt;/P&gt;&lt;P&gt;Bye.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Federico Cucchi&lt;/P&gt;</description>
      <pubDate>Wed, 15 Mar 2023 16:42:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/variesacrossgroups-lost-when-reinsert-ing-doc-parameterbindings/m-p/11823541#M26616</guid>
      <dc:creator>f_cucchi_FocchiSpa</dc:creator>
      <dc:date>2023-03-15T16:42:18Z</dc:date>
    </item>
  </channel>
</rss>

