How to rotate elements in view3D in REVIT using API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Here what I want to do : I want to create a view3D and rotate elements on the view before exporting the view
I have the following code :
```
...
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();
}
...
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;
}
```
I get a "c'ant rotate element." I not sure I have the right methodology. Can someone help me?
Regards,