Revit API

*Expert Elite*
Posts: 753
Registered: ‎02-13-2008
Message 1 of 4 (339 Views)

Mirror Family Instance

339 Views, 3 Replies
10-08-2009 12:11 PM
I have a need to be able to insert a family instance, then Mirror it about it's own X axis, Y axis, or both.
I found Autodesk.Revit.Document.Mirror with five overloads, and chose this one:
Autodesk.Revit.Document.Mirror(Autodesk.Revit.ElementSet, Autodesk.Revit.Geometry.Line) As Boolean
because it is the only one that uses a Line as the definition of the mirror base.

Notice the function only returns a boolean indicating success or failure.
first of all, I'm getting pretty wierd behavior where when I run a test of my code using a real example, I end up with one family instance in the correct position, at the wrong orientation, but when I set up a special test focusing on the problem, each time I mirror I end up creating a new instance, which I have no reference to. What I need is to have a reference to the newly created mirror, and delete the original, but I can't figure how to do that. I thought maybe the new instance would be added to the ElementSet passed to the method but it does not.

I have attached the function. Note that prior to calling this function I have already verified that the familyname passed to it is loaded in the project.

Anybody have any suggestions?

Edited by: chiefbraincloud on Oct 8, 2009 2:28 PM

OK, I figured out the wierd behavior, but I still have the same problem of needing to have a reference to the new mirrored object so I can manipulate it further.
Dave O.                                                                  Sig-Logos32.png
Active Contributor
Posts: 30
Registered: ‎11-25-2008
Message 2 of 4 (339 Views)

Re: Mirror Family Instance

10-08-2009 03:01 PM in reply to: chiefbraincloud
Since you are creating the new instance. Could you find the newest created instance in the document and that would be the newly mirrored instance?
*Expert Elite*
Posts: 753
Registered: ‎02-13-2008
Message 3 of 4 (339 Views)

Re: Mirror Family Instance

10-08-2009 03:37 PM in reply to: chiefbraincloud
I thought about doing that, but I searched through the object browser and I don't see anything like autocad's LASTENT property, so I'm not sure how to go about getting the newest created instance. (one might assume a similiar behavior to autocad, where looping the database is a last-in-first-out operation, but who knows)

Another thought is that I'm not even sure the instance becomes database resident until after my command completes (and therefore the top level transaction which revit automatically creates commits). If that is true, then I would be looking for a temporary entity associated with the transaction instead of a database entity.

just thinking out loud now. Any thoughts appreciated.
Dave O.                                                                  Sig-Logos32.png
*Expert Elite*
Posts: 753
Registered: ‎02-13-2008
Message 4 of 4 (339 Views)

Re: Mirror Family Instance

10-08-2009 06:12 PM in reply to: chiefbraincloud
Ok, I figured out this bit:
Dim docelems As ElementIterator = ActDoc.Elements()
Dim elem As Autodesk.Revit.Element
While docelems.MoveNext
elem = docelems.Current
End While
Which gives me the last element placed. That works (to my surprise). It is unfortunately in first-in-first-out order so you have to iterate to the end instead of just grabbing the first one.

Now I create Instance1, then if needed I mirror it, dispose of Instance1, then use the code snip above to grab the last element, set it to the variable used for Instance1 and continue. When the code finishes I have two issues.
1. I have both instances showing in the model. Not just the mirrored instance
2. This whole mirror thing seems to mess with the Document.Selection.Elements collection so after running a massive custom import (could be 1000 objects) the selection only contains those items placed since the last mirror operation occurred.

of course I would happily ignore the selection set problem if I could figure out how to make Instance1 go away.

Edited by chiefbraincloud.........

Still have the selection set problem, but disposing the Instance1 is insufficient, Document.Delete(instance) works.
Dave O.                                                                  Sig-Logos32.png
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.