Check if Assembly Views Exist
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am new to plugin development. I am trying to create a tool to create new assembly views. I can create the views just fine.
What I am struggling with is to check if an assembly view already exists in the project and has views/sheets created already. If so, I'd like to then skip them and create views for the assemblies that need them.
I tried checking if any of the views had an AssociatedAssemblyInstanceId on it but its not working.
I would appreciate any help on this. Thanks
FilteredElementCollector assemblyInstanceCollector = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Assemblies);
List<Element> assemblyInstanceList = assemblyInstanceCollector.OfClass(typeof(AssemblyInstance))
.ToElements().ToList();
FilteredElementCollector viewCollector = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Views);
List<Element> viewList = viewCollector.ToElements().ToList();
foreach (View v in viewList)
{
foreach (Element e1 in assemblyInstanceList)
{
if (e1.Id != v.AssociatedAssemblyInstanceId)
{
var viewSheet = AssemblyViewUtils.CreateSheet(doc, e1.Id, (ElementId)assemblyTileBlock);
var detailSectionH = AssemblyViewUtils.CreateDetailSection(doc, e1.Id, AssemblyDetailViewOrientation.HorizontalDetail);
var elevationTop = AssemblyViewUtils.CreateDetailSection(doc, e1.Id, AssemblyDetailViewOrientation.ElevationTop);
var elevationFront = AssemblyViewUtils.CreateDetailSection(doc, e1.Id, AssemblyDetailViewOrientation.ElevationFront);
var detailSectionB = AssemblyViewUtils.CreateDetailSection(doc, e1.Id, AssemblyDetailViewOrientation.DetailSectionB);
Viewport.Create(doc, viewSheet.Id, elevationTop.Id, new XYZ(.9, 2.2, 0));
Viewport.Create(doc, viewSheet.Id, detailSectionH.Id, new XYZ(.9, 1.5, 0));
Viewport.Create(doc, viewSheet.Id, elevationFront.Id, new XYZ(.9, .9, 0));
Viewport.Create(doc, viewSheet.Id, detailSectionB.Id, new XYZ(2.4, .9, 0));
elevationTop.ViewTemplateId = (ElementId)assemblyViewTemplate;
detailSectionH.ViewTemplateId = (ElementId)assemblyViewTemplate;
elevationFront.ViewTemplateId = (ElementId)assemblyViewTemplate;
detailSectionB.ViewTemplateId = (ElementId)assemblyViewTemplate;
}
}
break;
}