ElementTransformUtils.MirrorElements error when upgrading Revit API 2024

ElementTransformUtils.MirrorElements error when upgrading Revit API 2024

ptranU2KHX
Advocate Advocate
3,465 Views
34 Replies
Message 1 of 35

ElementTransformUtils.MirrorElements error when upgrading Revit API 2024

ptranU2KHX
Advocate
Advocate

Hi everyone,

I have a very simple project and I'd like to mirror them. Link to project if you'd like to download mirror 

ptranU2KHX_0-1683771354293.png

My code works fine with Revit API 2023 but not Revit API 2024.

ptranU2KHX_1-1683771455046.png

ptranU2KHX_2-1683771588085.png

Looking at the Revit API 2024 change, I see a section related to mirror thing.

ptranU2KHX_3-1683771615212.png

I try to use the check mirror posibility before executing but it always returns me true value.

ptranU2KHX_4-1683771669290.png

 

Please help. Thank you.

0 Likes
3,466 Views
34 Replies
Replies (34)
Message 2 of 35

jeremy_tammik
Alumni
Alumni

As far as I understand the documentation that you quote, the error is caused because the elements differ too much, e.g., have different sketch planes or something, so they cannot be mirrored together.

  

The CanMirrorElement, however, reports whether an element can be mirrored individually.

  

So, the solution might be to mirror the differing elements individually, reusing the same mirroring plane.

  

Please correct me if I misunderstand something, and let us know whether mirroring the elements one by one works better.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 35

ptranU2KHX
Advocate
Advocate

Hi @jeremy_tammik 

Thank you for your reply.

I tried to loop through each elementid in my list and mirror, but there are warnings in Revit after each transaction.

ptranU2KHX_0-1683783545203.png

 

The CanMirrorElements and CanMirrorElement are both always true.

0 Likes
Message 4 of 35

jeremy_tammik
Alumni
Alumni

Aha. Well, maybe CanMirrorElements is reporting incorrectly. I can submit the issue to the development team for you. Is the code that you are using embedded in a macro in the sample model that you provided? If not, please provide a complete minimal reproducible case with detailed succinct step-by-step instructions for them in which they can verify and analyse the problem and test possible enhancements: 

  

  

Thank you!

  

Please note that one possible outcome might be that they agree that CanMirrorElements should return false, not true, and just fix that.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 5 of 35

ptranU2KHX
Advocate
Advocate

Hi @jeremy_tammik 

 

Please use this project

 

Here is the simple code:

Public Sub MirrorProject(doc As Document)

        Try

            Dim DocElemFilter As FilteredElementCollector = New FilteredElementCollector(doc)
            DocElemFilter.WhereElementIsNotElementType()

            Dim MirElems As ICollection(Of ElementId) = New List(Of ElementId)
            Dim mirElemsBelongView3DViewPlanViewSection As ICollection(Of ElementId) = New List(Of ElementId)

            For Each elem As Element In DocElemFilter

                If elem.Pinned = True Then Continue For

                If elem.Category Is Nothing OrElse
                    (elem.Category.Id.Value <> BuiltInCategory.OST_Constraints AndAlso
                    elem.Category.Id.Value <> BuiltInCategory.OST_CLines AndAlso
                    elem.Category.Id.Value <> BuiltInCategory.OST_Elev AndAlso
                    elem.Category.Id.Value <> BuiltInCategory.OST_Viewers) Then

                    If TypeOf (elem) IsNot SketchPlane AndAlso TypeOf (elem) IsNot Area AndAlso TypeOf (elem) IsNot Sketch Then

                        If elem.Geometry(New Options) Is Nothing And elem.OwnerViewId.Value = ElementId.InvalidElementId.Value Then Continue For
                    End If

                End If

                If elem.OwnerViewId.Value = ElementId.InvalidElementId.Value Then

                    MirElems.Add(elem.Id)

                Else

                    Dim ov As View = doc.GetElement(elem.OwnerViewId)

                    If TypeOf (ov) Is View3D OrElse TypeOf (ov) Is ViewPlan OrElse TypeOf (ov) Is ViewSection Then

                        MirElems.Add(elem.Id)

                    End If

                End If

            Next

            Dim MirPlane As Plane = Plane.CreateByNormalAndOrigin(New XYZ(1, 0, 0), New XYZ(0, 0, 0))

            Using tr As New Transaction(doc, "mirror all")

                tr.Start()

                If ElementTransformUtils.CanMirrorElements(doc, MirElems) = True Then
                    ElementTransformUtils.MirrorElements(doc, MirElems, MirPlane, False)

                End If

                tr.Commit()

            End Using


        Catch ex As Exception

        End Try

    End Sub
0 Likes
Message 6 of 35

jeremy_tammik
Alumni
Alumni

Dear Phat Tran,

 

Thank you for your report, clear description and sample material.

 

Sorry to hear about this.

 

I logged the issue REVIT-207038 [MirrorElements fails although CanMirrorElements returns true] with our development team for this on your behalf as it requires further exploration and possibly a modification to our software. Please make a note of this number for future reference.

 

You are welcome to request an update on the status of this issue or to provide additional information on it at any time quoting this change request number.

 

This issue is important to me. What can I do to help?

 

This issue needs to be assessed by our engineering team and prioritised against all other outstanding change requests. Any information that you can provide to influence this assessment will help. Please provide the following where possible:

 

  • Impact on your application and/or your development.
  • The number of users affected.
  • The potential revenue impact to you.
  • The potential revenue impact to Autodesk.
  • Realistic timescale over which a fix would help you.
  • In the case of a request for a new feature or a feature enhancement, please also provide detailed Use cases for the workflows that this change would address.

 

This information is crucial. Our engineering team has limited resources and must focus their efforts on the highest impact items. We do understand that this will cause you delays and affect your development planning, and we appreciate your cooperation and patience.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 7 of 35

jeremy_tammik
Alumni
Alumni

The ticket processing by the development team will take some time and not provide any immediate relief, unless they happen to discover some error in your code.

 

Since this issue is urgent for you, I suggest we also analyse it ourselves and try to find a solution or workaround regardless.

  

(A) You say that mirroring elements one by one works, but produces warnings. What warnings are those?

  

(B) Also, the original error message reports that the elements being mirrored differ too much, e.g., have different sketch planes or something.

  

The proper way to fix this would be to eliminate those differences in (B). Can you do that?

  

If not, we can take a closer look at (A).

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 35

ptranU2KHX
Advocate
Advocate

Hi @jeremy_tammik 

Many thanks to your response. 

 

(A) Here is the warnings. I believe this comes when there are relationships between elements and annotations.

Please note in Revit 2023, I won't get this issue.

ptranU2KHX_0-1684147074877.png

(B) I tried to group them into 4 group: elements which are not belonged to any views, elements which are in View3D, , ViewPlan, and ViewSection. It worked for now but some annotations like tags, keynotes... will not be mirrored properly.

0 Likes
Message 9 of 35

jeremy_tammik
Alumni
Alumni

If you do not care about these relationships, you may be able to use the failure handling API to delete the offending instances and handle the error automatically. Better still, delete the relationships before copying, and you will have no errors at all. That would enable you to fix the problem ourself right away rather than waiting for the response from the development team. As I mentioned above, I suspect that their response will not help you much, since the stricter checks before mirroring presumably are being applied intentionally.

  

The fact that this mirroring approach worked in previous versions des not mean that it was a good thing. Just that less checking was applied. Probably, mirroring these relationships is actually violating some fundamental BIM principles and will lead to more problems in the long run. Better clean up asap.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 10 of 35

ptranU2KHX
Advocate
Advocate

Thank @jeremy_tammik .

 

The thing is I'd like to mirror a building with all annotations in each floor plan. 

 

I bet I have to take a deep into look at filtering elements. Do you have any information about what elements should be mirrored together and what should be not?

0 Likes
Message 11 of 35

jeremy_tammik
Alumni
Alumni

Dear Phat Tran,

 

Thank you for your explanation.

 

Maybe we need to expose the 'mirror project' command to API.

 

The existing API is not likely to work for this in most cases. Mirroring one element at a time will work even less. For instance, you can't mirror a wall and a window in it separately, and you also can't delete this relationship between the two elements before mirroring.

 

Mirroring is done by creating a mirrored copy and deleting the original; that's why the customer gets copy-related errors when they mirror one element at a time.

 

I believe we added a check to prevent mirroring elements from different views (unless the views themselves are mirrored too), so it should be reflected in the documentation. OTOH the customer script seems to not mirror view-specific elements directly, so something deeper must be happening here.

 

We'll see what we can do.

 

Would it work for you to use PostCommand to launch the 'mirror project' command?

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 12 of 35

ptranU2KHX
Advocate
Advocate

Thanks @jeremy_tammik 

 

Would you mind explaining using PostCommand to launch the 'mirror project' command? Please forgive me since this approach is new to me.

 

Please note currently, my 'mirror project' command is launched after a process of many works. And after 'mirror project' command, I also have some commands executed. 

0 Likes
Message 13 of 35

jeremy_tammik
Alumni
Alumni

Everything I know is discussed by The Building Coder here:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.3

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 14 of 35

jeremy_tammik
Alumni
Alumni

Dear Phat Tran,

 

Thank you for your patience.

 

The development team has made some progress and shared some interesting observations on the current implementation:

 

The script collects all elements in the document. It filters out a few kinds of elements, like element types, and elements without geometry. However, it still grabs way too much. In the selection that will be mirrored fall specialised elements like ExtentElem and LegendComponent. In general, I think such an approach of collecting all elements in the document and trying to do something with them is dangerous and can cause unexpected issues. There is no good way to filter out specialised elements that I can see. So, we need to continue internal discussion and decide what to expose, how to know what elements to skip and how to perform the mirror.

 

A couple more observations:

 

CanMirrorElements is not enough to tell whether the elements will successfully be mirrored. A number of other internal checks are performed, and even if those checks succeed, the whole operation can still fail in the end. There is no way to tell whether mirroring will succeed without doing the actual mirroring. We could, however, improve the accuracy of this method by including more of the validations in it. This requires more internal discussion and research.

 

The validation which causes the issue, in this case, is a check areElementsNonViewSpecificOrFromOneView. The reason is, we try to mirror view-specific elements like SketchPlanes and others along with model elements. If this validation is skipped, the operation succeeds. I would still not recommend doing a mirror project this way, and I am concerned that this validation will prevent other much more reasonable workflows. For example, mirroring a wall and its attached tags/dimensions. This will also require more internal discussion and research.

 

Best regards,

 

Jeremy

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 15 of 35

ptranU2KHX
Advocate
Advocate

Thank you @jeremy_tammik . I do appreciate that.

Message 16 of 35

dbrainard
Advocate
Advocate

Hello Jeremy and thank you for your responsiveness and follow-up details shared so far. I wanted to provide some additional notes per a request you made in a previous response if it will help.

 

One of many key features in the product mentioned above is designed to help automate the creation of opposite handed plans and documentation for production home builders. We have been able to do this reliably for years in prior versions of Revit without the unresolvable errors that are now occurring with various annotation elements. We believe that without this key capability, virtually all of our current target market will not be able to commit to the 2024 platform version. Because we have other Revit products that compliment and integrate with this product, the effectiveness of those 2024 versions won’t be realized either.

 

With respect to urgency, we historically do not receive pressure from our customers or prospects to upgrade until the dot one Revit release is available, however we have customers that have already upgraded and are experiencing this issue. We will have to revise our release plans for the year to continue developing in the 2023 version for an extended period of time but without any timeline on your end we have to delay future projects intended for 2024 and beyond. If it will be helpful, we can arrange for a discussion offline for any other details you may require from our end on the subject, just let me know.

 

We appreciate your teams efforts and fully respect the challenge of evaluating and effectively prioritizing all incoming requests and issues.

 

Best Regards,

Dave

Message 17 of 35

ptranU2KHX
Advocate
Advocate

Hi @jeremy_tammik 

'MirrorProject' command should work for me if I can select the axis by revit api. You can refer to @dbrainard 's comment.

As far as I research, I saw a post you said selecting axis by api could not be done.

0 Likes
Message 18 of 35

jeremy_tammik
Alumni
Alumni

Dear Dave and Phat Tran,

 

Thank you for your appreciation.

 

The development team reached a stage in their analysis of the issue REVIT-207038 [MirrorElements fails although CanMirrorElements returns true] in which they cannot continue without further information from your side and say:

 

Apologies for the delay in moving forward with this. I've tried a couple of things and what seems to work best is indeed adding the view to the mirror set. I must have been testing it differently before, but it does work if, besides adding the view-specific elements, you also add the view of that view specific element like this:

 

  If TypeOf (ov) Is View3D OrElse TypeOf (ov) Is ViewPlan OrElse TypeOf (ov) Is ViewSection Then
    MirElems.Add(elem.Id)
    MirElems.Add(ov.Id);
  End If 

 

Can the customer check if this works for them?

 

We still need a separate mirror project API, but that will be filed as a separate improvement.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 19 of 35

ptranU2KHX
Advocate
Advocate

Hi @jeremy_tammik 

 

Really thank you for your time and effort. Your solution works with the attached project.

Unfortunately, the customer seems to have much more complicated projects than that project and the tag room still experiences the issue when mirroring.

 

ptranU2KHX_0-1686124342386.png

 

Message 20 of 35

jeremy_tammik
Alumni
Alumni

Thank you for confirming that it helps in a simple case. I have asked the development team for further advice.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open