Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Yes/No Parameter values on doors in groups

9 REPLIES 9
Reply
Message 1 of 10
Anonymous
1579 Views, 9 Replies

Change Yes/No Parameter values on doors in groups

Hi,

I tried to change the boolean value by  familyinstance.lookup("door-yes-no-shared-param") and by setting the parameter value, however revit shows it's you must ungroup the groups warning. Is there a safe way of doing this without breaking the database? Is there a dirty way of doing this? I tried once before to use a building coder blog which worked however my recreated group would be flipped or move on it's origin point. Does anyone know what I might be doing wrong here?

cheers

stuck in groups.

9 REPLIES 9
Message 2 of 10
naveen.kumar.t
in reply to: Anonymous

Hi @Anonymous ,

Have you tried using this link?

editing-elements-inside-groups


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 10
Anonymous
in reply to: naveen.kumar.t

Hi,

Thanx for the hyperlink where is the how to change elements inside groups demonstration that is about hiding dialogs, the next onerous step in jumping through hoops and I hope this one isn't lined with fire. 

Message 4 of 10
Anonymous
in reply to: naveen.kumar.t

Hi Naveen, et al.

 

So I found this building coder blog which was quite good, albeit dated. I had to change fro using elementset to elementids.

I tested this and i managed to get it to create new group with updated parameters. It didn't however swap the oldgrouptype, i think it is failing on this command...

grpNew.GroupType = grpTypes.First<GroupType>();

any insight would be welcome and I thank the building coder for creating a blog on such an important and practical issue when automating tasks with the revit api.

 

 

 

[Transaction(TransactionMode.Manual)]
public class Groups_Main : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;

 

// Prompt user to select existing group
Group grpExisting = doc.GetElement(
uidoc.Selection.PickObject(ObjectType.Element,
"Select an existing group")) as Group;

string nameExGrp = grpExisting.Name;

// Ungroup the group
Transaction tx = new Transaction(doc);
tx.Start("Ungroup and delete");

var grpElements = grpExisting.UngroupMembers();

// Create element set for new group
ICollection<ElementId> newgrpIds = uidoc.Selection.GetElementIds();


int counter = 0;

foreach (ElementId eid in grpElements)
{
if (0 == counter)
{
// Delete the first group element
doc.Delete(eid);
}
else
{
if (doc.GetElement(eid).Category.Name == _Category.DOORS)
{
FamilyInstance fi = doc.GetElement(eid) as FamilyInstance;
Parameter param = fi.LookupParameter("Hide Door Swings");

if (param != null)
{
param.Set(0);
}
}

newgrpIds.Add(eid);
}
++counter;
}

tx.Commit();

 


// Create new group
tx.Start("Group");

Group grpNew = doc.Create.NewGroup(newgrpIds);

 

// Access the name of the previous group type
// and change the new group type to previous
// group type to retain the previous group
// configuration
FilteredElementCollector coll
= new FilteredElementCollector(doc)
.OfClass(typeof(GroupType));

IEnumerable<GroupType> grpTypes
= from GroupType g in coll
where g.Name == nameExGrp
select g;

 

grpNew.GroupType = grpTypes.First<GroupType>();

tx.Commit();

Message 5 of 10
naveen.kumar.t
in reply to: Anonymous

Hi @Anonymous 

  • Does the user interface allow you to create a Group with such a name?

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 6 of 10
naveen.kumar.t
in reply to: Anonymous

Hi @Anonymous ,

are you looking for this one ?

 

 Group G ;
 GroupType Old_GT = G.GroupType;
/*
Your code
*/ //Create New Group Group NewGroup = doc.Create.NewGroup(newGroupIds); NewGroup.GroupType = Old_GT;

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 7 of 10
Anonymous
in reply to: naveen.kumar.t

Hi,

I am already performing these functions. What it does is to create a new group type, that is available in the project browser, if I don't do the swap operation for Grouptype it actually works, however it has create a new groupType already "Group 1, Group 2, Group 1+n" in the project browser and not swapped all the old grouptypes to the new groupTypes.  

I am guessing that maybe it is something fundamental that I don't understand todo with deleting the original groupType first before making the new Group. I will investigate the early parts of the code and let you know if I can get it to actually swap all the old-grouptypes to the new grouptype.

cheers,

Breldan 

Message 8 of 10
Anonymous
in reply to: naveen.kumar.t

1. It works up to the point were a new group is created with changed properties.

 

2. If I remove part 3 (swap groupTypes), the group swapping operation below I am left with an updated set of elements in the model space and no group created obviously.

 

3. If I remove the swap groupType i get a new Group 1 created in the project browser and the existing group becomes Group 1 with the updated values.

 

4. So the swap group types is failing and it's not much use to me if i have to ask users to do that part manually lol.

 

 

 

 

//NEW GROUP
Group NewGroup = null;
//SWAP
try
{

// Create new group
using (Transaction trans = new Transaction(doc, "3.Swap Group"))
{
trans.Start();

 

FilteredElementCollector coll
= new FilteredElementCollector(doc)
.OfClass(typeof(GroupType));

IEnumerable<GroupType> grpTypes
= from GroupType g in coll
where g.Name == nameExGrp
select g;


NewGroup = doc.Create.NewGroup(NewElementIds);

//swap New Group
NewGroup.GroupType = grpTypes.First<GroupType>();
trans.Commit();
}

}
catch (Exception ex)
{
TaskDialog.Show("msg", ex.Message);
}

Message 9 of 10
Anonymous
in reply to: Anonymous

This works!

However

I am uncertain if this approach so different from the building coder blog is database safe. Also I am concerned that mirrored, origin adjusted or rotated groups might not work. Stay tuned as I break things with my dodgy code. 

 

 

 

//NEW GROUP
Group NewGroup = null;
//SWAP
try
{

// Create new group
using (Transaction trans = new Transaction(doc, "3.Swap Group"))
{
trans.Start();

//create new group
NewGroup = doc.Create.NewGroup(NewElementIds);

GroupType OldGrpType = new FilteredElementCollector(doc)
.OfClass(typeof(GroupType)).OfType<GroupType>()
.Where(g => g.Name == nameExGrp).FirstOrDefault();


foreach (Group group in OldGrpType.Groups)
{
//swap New Group
group.GroupType = NewGroup.GroupType;
}

 

//Delete old group type
doc.Delete(oldGrpType.Id);

NewGroup.GroupType.Name = nameExGrp;


trans.Commit();
}

}
catch (Exception ex)
{
TaskDialog.Show("msg", NewGroup.Name + "," + ex.Message);
}

Message 10 of 10
Anonymous
in reply to: naveen.kumar.t

Hit another snag,

It seems that I can swap groups, the first group doesn't move however the other groups are jumping about. consistent in each event until you modify one of the groups then they jump the other way a different distance. If no modification has occured to the initial group i.e. you create and copy and paste no jumping occurs.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community