Group Origin Point is moved when using Revit API.

Group Origin Point is moved when using Revit API.

휴엔
Participant Participant
584 Views
0 Replies
Message 1 of 1

Group Origin Point is moved when using Revit API.

휴엔
Participant
Participant

Dear Everyone, 

I have a question about loading group into another Revit project/file.

MicrosoftTeams-image (27).png

I have created a group file like the image above.

 

MicrosoftTeams-image (28).png

The image above is loaded group in other Revit file.

On the left I used Revit API to load the group, On the right is Manual Copy & Paste.

As the image shows the group origin point is loaded in different position.

 

I want to know when the group is loaded by Revit API, how we can preserve the group origin point like manual Copy & Paste.

 

Below is the used code to load the group.

public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument uiDoc = uiApp.ActiveUIDocument;
            Document doc = uiDoc.Document;

            var trans = new Transaction(doc);
            trans.Start("Creating Group");

            Document otherdocument = doc.Application.OpenDocumentFile(GROUP_FILE_PATH);

            View3D view = new FilteredElementCollector(otherdocument)
                .OfClass(typeof(View3D))
                .WhereElementIsNotElementType()
                .FirstElement() as View3D;

            var collector = new FilteredElementCollector(otherdocument)
                .WhereElementIsNotElementType()
                .WhereElementIsViewIndependent()
                .ToList();

            var ids = new List<ElementId>();
            foreach (Element elem in collector)
            {
                ids.Add(elem.Id);
            }

            var copiedElements = ElementTransformUtils.CopyElements(otherdocument, ids, doc, null, new CopyPasteOptions());

            Group g = doc.Create.NewGroup(copiedElements);
            if (g != null)
            {
                XYZ point = uiDoc.Selection.PickPoint();
                doc.Create.PlaceGroup(point, g.GroupType);
                doc.Delete(g.Id);
            }
            trans.Commit();
            return Result.Succeeded;
        }

 

0 Likes
585 Views
0 Replies
Replies (0)