1

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.

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.

Is there a better way to do this so that it doesn't take so much longer than the UI method?

Here is the code I am using to test in Revit Python Shell:

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()
2
  • 1
    Revit API is basically a dot net wrapper around the core Revit functionality. I'm not speaking from knowledge here but It's imaginable that Revit has a more low-level access to its model database that allows it to batch modify data faster than the user facing API. Commented May 20, 2018 at 2:35
  • 1
    That makes total sense. A bit of a bummer, but I suppose it is what it is. Thanks for your help! Commented May 21, 2018 at 18:25

1 Answer 1

0

I could be wrong, but I think that's your only option. There are utilities to move a bunch of objects at once, but I'm not aware of any ways to change the type of multiple objects at the same time. The Revit API isn't complete so there are things you can't do in python/c# that Revit can do itself.

There is a tool to copy multiple elements at once (ElementTranformUtils.CopyElements); although, that would require you to delete all the existing families before you copy them. It's probably not worth it, and I'm not sure if that would be any faster either.

Because of how large groups are, they are just slow to work with in general, which doesn't help. I was working on a script that would edit groups to check elements within the group. This entailed ungrouping the group, editing the elements, regrouping it, and then changing all the existing groups to his new type. It took several hours to run on a project with a decent number of groups.

Sign up to request clarification or add additional context in comments.

1 Comment

That sounds like an ambitious project Dennis, its awesome hearing how creatively Revits features get used. My next toolbox item will be a 'Workset Enforcer' for groups...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.