
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having problems exporting a group of 3d views to DWG based on their name containing a specified string. Below is the code that I'm using in my addin, and it seems to have a problem with the export method.
When I run the entire code, it get an error that says non empy list of views must be provided.
If I comment out the export method, the code runs through and I can see in the success dialog box that I'm getting the views I need filtered from the collection and their ID's, so I'm not sure why the export method is not reading the collection.
If I comment out the if statement, all the views in the project get exported and I get an error saying some were not printable.
Can someone help me understand why the export method is not working?
{
Document doc = commandData.Application.ActiveUIDocument.Document;
string docName = commandData.Application.ActiveUIDocument.Document.Title.ToString();
string title = docName.Replace(".rvt", "");
string folderName = Environment.GetFolderPath(Environment.SpecialFolder.Personal).ToString() + "\\" + title + " Coordination Exports" + DateTime.Now.ToString(" yyMMdd") + "\\";
FilteredElementCollector collection = new FilteredElementCollector(doc).
OfClass(typeof(View3D));
DWGExportOptions opt = new DWGExportOptions();
string viewNames = "";
if (Directory.Exists(folderName))
{
Array.ForEach(Directory.GetFiles(folderName), File.Delete);
}
else
{
Directory.CreateDirectory(folderName);
}
foreach (View3D vt in collection)
{
string viewName = vt.Name;
ViewSet viewsToExport = new ViewSet();
if (viewName.Contains("xxxxxxxx"))
{
viewsToExport.Insert(vt);
}
ICollection<ElementId> exportViews = new List<ElementId>();
foreach (View view in viewsToExport)
{
viewNames += vt.Name + "" + view.Id.ToString() + Environment.NewLine;
exportViews.Add(view.Id);
}
doc.Export(folderName, viewName, exportViews, opt);
}
TaskDialog td = new TaskDialog("Coordination Exports");
td.MainContent = "All of the Coordination Exports in Project:" + Environment.NewLine +
docName + Environment.NewLine + viewNames + Environment.NewLine +
"Have been exported to: " + Environment.NewLine +
folderName + Environment.NewLine;
td.MainInstruction = "Coordination Views have been exported.";
td.Show();
return Result.Succeeded;
}
}
}
Solved! Go to Solution.