Can't Rotate Element into this position..again

Can't Rotate Element into this position..again

jmyr
Enthusiast Enthusiast
2,426 Views
7 Replies
Message 1 of 8

Can't Rotate Element into this position..again

jmyr
Enthusiast
Enthusiast

Hi all,

 

Im placing batch family instances by reading cadlink/import instance data into revit, placing instances is working properly, however if i add/try to rotate instances after creation im getting an error saying "cant rotate element into this position", I know there's lot of discussion already about this issue but those solution doesn't seem to solve my problem. Any thoughts? Cheers!

X.PNG

 

foreach (ImportInstance instance in instances)
                    {
                        Transform transform = instance.GetTotalTransform();

                        XYZ origin = transform.Origin;

   
                        XYZ vectorTran = transform.OfVector(transform.BasisX.Normalize());
                        double rotation = transform.BasisX.AngleOnPlaneTo(vectorTran, transform.BasisZ.Normalize());
                        rotation = rotation * (180 / Math.PI);


                        if (!selectedSymbol[0].IsActive)
                        {
                            selectedSymbol[0].Activate();
                        }

                        FamilyInstance newInstance = doc.Create.NewFamilyInstance(origin, selectedSymbol[0], Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

                        Line axis = Line.CreateBound(origin, XYZ.BasisZ);
                        ElementTransformUtils.RotateElement(doc, newInstance.Id, axis, rotation);
                    }
0 Likes
Accepted solutions (1)
2,427 Views
7 Replies
Replies (7)
Message 2 of 8

jeremytammik
Autodesk
Autodesk

Dear Myrwen,

 

Thank you for your query.

 

Your code is performing two operations:

 

  • Placing a new family instance
  • Rotating the newly placed instance

 

Quite possibly, the latter cannot be accomplished before the former has been fully completed.

 

To do so, it may be necessary to regenerate the model in between these two steps, or even perform the two operations in completely separate transactions, committing the first transaction before starting the second one.

 

For more on this and related topics, please refer to The Building Coder topic group on the need to regenerate:

 

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

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 8

RmsMali
Contributor
Contributor

Did you try to place the family manually in Revit Project and try to rotate it? If you are not able to do it manually, then it can't be done using API as well (AFAIK).

 

It usually has to do with the way the family has been modeled.

  1. Try to place some other family (A family containing a simple rectangular extruded feature) and rotate it via your code. If you could achieve it using the API, then the issue is with the way you have modeled it.
0 Likes
Message 4 of 8

jmyr
Enthusiast
Enthusiast

Thank you @jeremytammik  i tried your suggestions unfortunately that doesn’t solve the issue. 

0 Likes
Message 5 of 8

jmyr
Enthusiast
Enthusiast

hi, yes i can rotate them manually in revit.

 

i tried it as well in other families and i get the same error.

0 Likes
Message 6 of 8

jeremytammik
Autodesk
Autodesk

Dear Myrwen,

 

Good for you that you are able to achieve the desired rotation manually.

 

In that case, you should be able to analyse exactly what database modifications are performed by the manual interaction.

 

RevitLookup and other database exploration tools enable you to see exactly how these modifications look through the API.

 

Here are some sample instructions in more detail:

 

 

I hope this helps.

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 8

FAIR59
Advisor
Advisor
Accepted solution

If you desire to rotate with a vertical axis ( as I suspect), you need te redefine the axis Line:

			Line axis = Line.CreateBound(origin, origin.Add(XYZ.BasisZ));
0 Likes
Message 8 of 8

jmyr
Enthusiast
Enthusiast

Perfect! Thank you very much.

0 Likes