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?