How can I flip a section using the Revit 2017 API

How can I flip a section using the Revit 2017 API

Anonymous
Not applicable
2,568 Views
6 Replies
Message 1 of 7

How can I flip a section using the Revit 2017 API

Anonymous
Not applicable

I have a section that I want to flip using the Revit API just like doing it with the UI as seen below.  I've tried using the ElementTransformUtils.MirrorElement but that only creates a copy with a duplicate view.

 

iylm9.pngy1njz.png

Here is a copy of my question on StackOverflow:

 

http://stackoverflow.com/questions/42164282/how-can-i-flip-a-live-section-with-the-revit-api

0 Likes
Accepted solutions (1)
2,569 Views
6 Replies
Replies (6)
Message 2 of 7

FAIR59
Advisor
Advisor
Accepted solution

you can use another method from the ElementTransformUtils  (Revit 2017).

 

ElementTransformUtils.MirrorElements(document, sel , _plane, false);

 

with the 2nd argument a list of ElementId's

with the 4th argument set to false, meaning  no copies should be created and the elements should be mirrored directly.

0 Likes
Message 3 of 7

Anonymous
Not applicable

mirroring only works if you set the flag to true - it only creates new elements and does nothing if boolean is set to false. Ideas? 

0 Likes
Message 4 of 7

FAIR59
Advisor
Advisor

In my test, i selected the section  in a plan view and mirrored that section. That works fine.

 

So you will have to find the section  (Element of BuiltinCategory.OST_Viewers) of your view .

0 Likes
Message 5 of 7

FAIR59
Advisor
Advisor

Here is my testcode

 

            Document document = revit.Application.ActiveUIDocument.Document;
            Autodesk.Revit.DB.View _view2mirror = document.ActiveView;
            List<Element> _sections = new FilteredElementCollector(document)
            .OfCategory(BuiltInCategory.OST_Viewers)
            .ToList();
            Element _section = null;
            foreach (Element _e in _sections)
            {
                if (_e.Name == _view2mirror.Name && _e.GetTypeId() == _view2mirror.GetTypeId()) _section = _e;
            }
            try
            {

                if( _section !=null)
            {
                using (Transaction t = new Transaction(document, "MirrorSection"))
                {
                    t.Start();
                    Plane _plane = Plane.CreateByNormalAndOrigin(_view2mirror.ViewDirection, _view2mirror.Origin);
                    ElementTransformUtils.MirrorElements(document, new List<ElementId> { _section.Id }, _plane, false);
                    t.Commit();
                }
            }
            return Result.Succeeded;
            }
            catch (Exception ex)
            {
                return Result.Failed;
            }
0 Likes
Message 6 of 7

Anonymous
Not applicable

Thanks FAIR59.  This worked for me in Revit 2017.  I didn't even think about trying the plural MirrorElements because I was just wanting to mirror one at a time and I assumed that it had the same function signature (other than single element vs. collection of elements) as the singular MirrorElement.  It seems odd to me that they excluded the mirrorCopies parameter from the singular version of the function.

0 Likes
Message 7 of 7

Anonymous
Not applicable

ksobon, are you using Revit 2017 or an older version?

0 Likes