namespace ChangeTo3dView
{
[Transaction(TransactionMode.Manual)]
public class DeleteImportElement : IExternalCommand
{
Autodesk.Revit.ApplicationServices.Application app;
Document doc;
View3D threeDView;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
app = commandData.Application.Application;
doc = commandData.Application.ActiveUIDocument.Document;
string directory = @"D:\Desktop\View\";
string s = "";
foreach (string filename in Directory.GetFiles(directory))
{
s += "Family Name,Family Type,";
Document doc = app.OpenDocumentFile(filename);
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
var viewId = createView(uidoc, doc);
var options = new SaveOptions()
{
PreviewViewId = viewId
};
doc.Save(options);
doc.Close(false);
}
return Result.Succeeded;
}
public ElementId createView(UIDocument uidoc, Document doc)
{
var viewFamilyType
= new FilteredElementCollector(doc)
.OfClass(typeof(ViewFamilyType))
.OfType<ViewFamilyType>()
.FirstOrDefault(x =>
x.ViewFamily == ViewFamily.ThreeDimensional);
using (var t = new Transaction(doc, "Create 3D View"))
{
t.Start();
threeDView = View3D.CreateIsometric(
doc, viewFamilyType.Id);
threeDView.get_Parameter(BuiltInParameter
.VIEW_DETAIL_LEVEL).Set(1);
threeDView.get_Parameter(BuiltInParameter
.MODEL_GRAPHICS_STYLE).Set(3);
t.Commit();
}
return threeDView.Id;
}