How to rotate a model using c# api?

How to rotate a model using c# api?

ggXWU4P
Explorer Explorer
1,546 Views
2 Replies
Message 1 of 3

How to rotate a model using c# api?

ggXWU4P
Explorer
Explorer

Hi,

 

I am quite new in developping through revit and I am a bit lost on how REVIT manages 3D view. My goal is to rotate the whole 3D model.

So far I have managed to create a Isometric 3D view and I would like now to rotate all 3D elements, how to do this?

 

regards, 

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

jeremytammik
Autodesk
Autodesk

If you really want to rotate all the elements, you can presumably do so using the ElementTransformUtils RotateElements method:

 

https://www.revitapidocs.com/2020/5d62fb23-60c1-b740-b02c-d0b6fd1d8ed0.htm

 

If you want to rotate the view, leaving the elements in place, you can do so by manipulating the view parameters.

 

In both cases, you should analyse the required steps manually via the Revit user interface first to determine exactly what you need. Then, analyse what effect the manipulation has on the Revit database, e.g., by using RevitLookup and other tools. Finally, when all that is clear, you can start addressing the programming task via the Revit API. Here is the standard approach to research to find a Revit API solution:

 

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 



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

Message 3 of 3

Anonymous
Not applicable

I come from the industrial CAD domain and I have difficulties to understand the way REVIT represent 3D.

 

I need to export model to DWG, but first I need to select a PartFamily, draw the view3D and I expect to select all model geometry to perform a rotation à the whole 3D instance model.

 

Is it the right way to do it?

 

...           
 var viewFamilyType
                = new FilteredElementCollector(doc)
                    .OfClass(typeof(ViewFamilyType))
                    .OfType<ViewFamilyType>()
                    .FirstOrDefault(x =>
                        x.ViewFamily == ViewFamily.ThreeDimensional);
            
            using (var t = new Transaction(doc))
            {
                t.Start("Create 3D View");

                if (viewFamilyType != null)
                {
                    var threeDView = View3D.CreateIsometric(
                        doc, viewFamilyType.Id);
                    
                    var o = new XYZ(0, 0, 0);
                    var x = new XYZ(1, 0, 0);


                    // Find all Wall instances in the document by using category filter

                    RotateModel(doc, threeDView, o, x, Math.PI / 2);

                    // Export to SAT

                    var viewSet = new List<ElementId>()
                    {
                        threeDView.Id
                    };
                    var exportOptions = new SATExportOptions();
                    doc.Export(outputFolder, file, viewSet, exportOptions);
                }

                t.RollBack();
            }
...

        /// <summary>
        /// Rotate model
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="type"></param>
        /// <param name="axis"></param>
        /// <param name="angle"></param>
        /// <param name="origin"></param>
        private static void RotateModel(Document doc, View3D view, XYZ origin, XYZ axis, double angle)
        {
            view.Pinned = false;

            // Use ElementClassFilter to find all loads in the document
            // Using typeof(Element) will yield all AreaLoad, LineLoad and PointLoad
            var filter = new ElementClassFilter(typeof(Extrusion));


            // Use ElementClassFilter to find all loads in the document
            // Using typeof(LoadBase) will yield all AreaLoad, LineLoad and PointLoad
            var ox = Line.CreateBound(origin, axis);

            var collector = new FilteredElementCollector(doc, view.Id);
            if (!collector.IsValidObject)
                throw new Exception("Not valid Object");

            // Apply the filter to the elements in the active document
            var elements = collector
                .WhereElementIsNotElementType();
                //.WherePasses(filter).ToList();

           //var elements = collector.ToList();

            foreach (var element1 in elements)
            {
                var element = (Extrusion) element1;
                if (element.IsSolid && element.IsValidObject && !element.IsHidden(view))
                    ElementTransformUtils.RotateElement(doc, element.Id, ox, angle);
            }


            view.Pinned = true;

        }

 Is it the right way to do it?

0 Likes