Can't place a group

Can't place a group

a.sabatier
Contributor Contributor
905 Views
2 Replies
Message 1 of 3

Can't place a group

a.sabatier
Contributor
Contributor

Hi

I don't know where is my mistake but when I try to create an instance of a group nothing happens..

 

            // On crée la liste de tous les groupes présents dans le fichier
            List<GroupType> collectiongrouptype = new FilteredElementCollector(doc).
                OfClass(typeof(GroupType)).OfType<GroupType>().ToList();

                
                using (ConfigurateurBVForm f = new ConfigurateurBVForm())
                {
                    #region  Bouton Appliquer
                    
                    f.applyButton.Click += (sender, e) =>
                    {
                        using (Transaction tr = new Transaction(doc))
                        {
                            tr.Start("Insert group");

                            //On regarde le nom qui est à inserer
                            foreach (GroupType grouptype in collectiongrouptype)
                            {
                                TaskDialog.Show("e", grouptype.Name);
                                if (grouptype.Name == "montype")
                                {
                                    TaskDialog.Show("ee", "if condition");

                                    //On crée l'instance.
                                    try
                                    {
                                        XYZ zero = new XYZ(0, 0, 0);
                                        doc.Create.PlaceGroup(zero, grouptype);
                                        break;
                                    }
                                    catch { }

                                    tr.Commit();
                                }
                            }
                        }
                    };
                    f.ShowDialog();
                }
                #endregion
            return Result.Succeeded;

Thanks for your help

 

Alexandre

0 Likes
Accepted solutions (1)
906 Views
2 Replies
Replies (2)
Message 2 of 3

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @a.sabatier ,

Filter Group instead of Grouptype and from the filtered group try to get the GroupType.

IList<Element> groups = new FilteredElementCollector(doc).OfClass(typeof(Group)).WhereElementIsNotElementType().ToElements() as IList<Element>;
                 
                 foreach (Element group in groups)
                 {
                     Group g = group as Group;
GroupType GT = g.GroupType;
doc.Create.PlaceGroup(new XYZ(0, 0, 0), GT); }

If this helped solve your problem  mark it as solutionSmiley Happy


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

JimJia
Alumni
Alumni
Accepted solution

hi, 

 

Some wrong in your code: after break with foreach loop, the code after break will not be executed; I guess the tr.Commit() is not called, so the placement will not occur; you should move the tr.Commit() outside foreach.

 

Please try following fixed code, I verified it works:

foreach (GroupType grouptype in collectiongrouptype)
{
    // your other code
}
//
// commit transaction after group placing
tr.Commit();

 

 


Jim Jia
Autodesk Forge Evangelist
https://forge.autodesk.com
Developer Technical Services
Autodesk Developer Network
Email: Jim.Jia@autodesk.com
0 Likes