Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Mirror Family Instance

3 REPLIES 3
Reply
Message 1 of 4
chiefbraincloud
1196 Views, 3 Replies

Mirror Family Instance

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
3 REPLIES 3
Message 2 of 4
joelkarr
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?
Message 3 of 4

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
Message 4 of 4

Ok, I figured out this bit:
{code}
Dim docelems As ElementIterator = ActDoc.Elements()
Dim elem As Autodesk.Revit.Element
While docelems.MoveNext
elem = docelems.Current
End While
{code}
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.........

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community