Changing Elements Inside Group Problem

Changing Elements Inside Group Problem

Anonymous
Not applicable
1,350 Views
2 Replies
Message 1 of 3

Changing Elements Inside Group Problem

Anonymous
Not applicable

I have been working on some code that will change walls in a group to a different type. Apparently, it is not possible to change elements inside of a group via code. I have followed the suggested path of ungrouping, making the change, regrouping, and changing all other group instances to the new group. This changes the walls as desired, but rotates some of the group instances (not a minor rotation, but one that is greater than 90 degrees, placing elements outside of the building). 

I have tried to fix this by taking a vector from the group's centroid to the first element's location before and after the change. I then try to adjust by reversing the rotation. This doesn't work for all groups. Perhaps the order of elements in the group is changing.

 

I am hoping someone has some solutions that may help me For instance:

 - Is there a way to change an element in a group without ungrouping? (this should be possible!)

 - Is there an orientation property for a group element, so that I can track the dynamics?

 

Has anyone dealt with this problem?

0 Likes
1,351 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor

Probably the issue is that the group has been rotated manually after placement so when you ungroup and regroup the rotation of those groups is lost.

 

The group class itself has no transform to indicate it's orientation within the model. However any instance objects within the group will have such a transform object. If you have no instance objects e.g. Walls only then you can use a Wall location curve as a direction vector and the curve start point as an origin.

 

Therefore if you get equivalent instances between such groups via Group.GetMemberIds (which states that it returns an ordered list to match members across instances). Then you can use the transforms or differences in location curve to work out the overall translation and rotation required for each group. You have to extract this information before the ungrouping. I've not done it this way personally but knowing the limitations of groups this is how I would do it.

 

What you are really looking to do is probably either of the following:

 

  1. If you are changing the existing group type with instance remaining in-place then you need to know the difference between old group and new group for each instance in terms of the common origin and direction that remains constant between them.
  2. If you are deleting the group instances and replacing them with copies transformed from the location of the group you are editing then you need the differece between that group and all of the new locations of it.

In either of the above you need one aspsect in the group with a location to remain unchanged between the changeover.

 

 

0 Likes
Message 3 of 3

dolan.klockLTCTY
Explorer
Explorer

I have managed to change text note types inside of a group without having to ungroup it. Here is the code below.


CODE BELOW:

 

from rpw import db

with forms.WarningBar(title='Select Rooms To Create Filled Region From'):
    # selecting a group for testing
    groups = uidoc.Selection.PickObjects(Autodesk.Revit.UI.Selection.ObjectType.Element, "Select group")

# getting group object
for g in groups:
    group = doc.GetElement(g.ElementId)

# getting all groups member ids
member_ids = group.GetMemberIds()

# iterating through member ids list, getting the element from that id and appending elements to a new list
elements = []
for id in member_ids:
    elements.append(doc.GetElement(id))

# checking if element inside of elements list is of TextNote type and if so changing the type to a new one
for e in elements:
    if type(e) == DB.TextNote:
        with db.Transaction("change text type in group"):
            e.ChangeTypeId(DB.ElementId(2799))
0 Likes