简体   繁体   中英

Revit API Change Groups in Python

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 (eg 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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM