Problem when mirroring newly modified family instance

Problem when mirroring newly modified family instance

Anonymous
Not applicable
1,050 Views
3 Replies
Message 1 of 4

Problem when mirroring newly modified family instance

Anonymous
Not applicable

My situation is this:

  • A new family instance is placed
  • some instance parameters in the new family instance is modified
  • the family instance is mirrored
  • the mirrored instance don't inherit the newly modified parameters

Here's my code:

FamilyInstance instance = doc.Create.NewFamilyInstance(somePoint, someSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

ElementTransformUtils.RotateElement(doc, instance.Id, someLine, someRotation);

instance.LookupParameter("Width").Set(someWidth);
instance.LookupParameter("Height").Set(someHeight);
instance.LookupParameter("Depth").Set(someDepth);

ElementTransformUtils.MirrorElement(doc, instance.Id, somePlane);

The weird thing is that if I run the MirrorElement() function twice, it will work the second time! I thought because of this that the first mirror function ran before the parameters were successfully modified, but I've tried different delay tricks, but with no luck.

0 Likes
1,051 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @Anonymous,

 

Does rotating the element in a transaction and mirroring the rotated element in

a second transaction(as below code snippet) solve your issue ?

1.Start the transaction

Transaction Rotate_element = new Transaction(doc);
 Rotate_element.Start("Rotating Element");

2.Rotate the element

FamilyInstance instance = doc.Create.NewFamilyInstance(somePoint, someSymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

ElementTransformUtils.RotateElement(doc, instance.Id, someLine, someRotation);

3.Get the  of rotated element.

FilteredElementCollector Element_collector = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).WhereElementIsNotElementType();
                IList<Element> elementss = Element_collector.ToElements() as IList<Element>;    
                FamilyInstance Fam_inst = null; ;
                int i = Element_collector.Max<Element>(y => y.Id.IntegerValue);
                ElementId MAX_ID = new ElementId(i);
                
                foreach(Element e in elementss)
                {
                    if(e.Id==MAX_ID)
                    {
                        Fam_inst = doc.GetElement(e.Id) as FamilyInstance;                       
                        break;
                    }
                }
                

4.Commit the transaction 

Rotate_element.Commit();

5.Open  a New transaction

Transaction Mirror_transaction = new Transaction(doc);
 Mirror_transaction.Start("Mirror");

6.Mirror the element

 Element rotated_element = Fam_inst as Element;
ElementId rotated_element_id = rotated_element as ElementId;
ElementTransformUtils.MirrorElement(doc,rotated_element_id, plane); 

7.commit the second transaction

Mirror_transaction.Commit();

 

 

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 4

frankholidayjunior
Advocate
Advocate

Hi,

Does anyone know of way to get a mirrored instances mirrored plane, so that I can replicate this when creating a familyInstance that is identical?

0 Likes
Message 4 of 4

frankholidayjunior
Advocate
Advocate

I would probably do something like this...

get the flip plane

ElementTransformUtils.

FlipElement(some plane etc in the method overload)

0 Likes