I have very busy this last week answering cases and preparing training material. Lots of interesting issues are cropping up that I would love to blog about, but I can hardly find the time to do so. Here is one little item of interest raised by Henrik Bengtsson of Lindab on renaming a group:
Question: Is there a way to change the name of a group that is created via the API? If you use the Document.Create.CreateNewGroup method and provide an ElementSet argument, it returns a Group object. If you then call Group.Name = "Test", it will raise an error saying that this operation is not valid due to the current state of the object. Is there perhaps some other method of changing the name of the group?
This group issue is of great importance since I am working on creating walls with studs and beams, so called structural framing. I want all these profiles to be connected in some way and this is one method. They both graphically and parametrically belong to each other, since you can use the Group.Members property to find all the different members in the group. Good when you are specifying products.
Answer: We already discussed the creation of a group. Changing the name of a group is not achieved by using the Name property on the group itself, but on the group type, like this:
Group g = <wherever you got the group from> Symbol groupType = g.ObjectType; groupType.Name = "New group name";
There is no real difference between these two properties, even though one can be changed and the other cannot. They return the same value and are probably pointing to the same data field somewhere.
The split into Group and GroupType classes was probably made to reuse the typical Revit family structure, similar to the relationship between Wall and WallType or family instance and family symbol. In the case of a group, the distinction between Group and GroupType may seem a bit contrived, but it certainly has valid internal reasons.