title: Revit API Change Groups in Python
body: <p>I am trying to write a script that changes groups from one type to another. Essentially, I want to accomplish the UI equivalent of right-clicking on a group type, selecting all instances and changing the type. </p>
  
  <p>I am able to use something like the code below, but it takes a lot longer than the UI method when there are a lot of groups (e.g. 270 or so). What takes less than 5 minutes in the UI, takes about 20 minutes or more programatically.</p>
  
  <p>Is there a better way to do this so that it doesn't take so much longer than the UI method?</p>
  
  <p>Here is the code I am using to test in Revit Python Shell:</p>
  
  <pre><code>import clr
  clr.AddReference('RevitAPI')
  from Autodesk.Revit.DB import *
  
  uidoc = __revit__.ActiveUIDocument
  doc = uidoc.Document
  sel = uidoc.Selection.GetElementIds()
  
  t = Transaction(doc, "Test")
  t.Start()
  
  g1 = doc.GetElement(sel[0])
  g2 = doc.GetElement(sel[1])
  
  for group in g2.Groups:
      group.GroupType = g1
  
  t.Commit()
  </code></pre>