Check if Assembly Views Exist

Check if Assembly Views Exist

a.j_
Explorer Explorer
362 Views
1 Reply
Message 1 of 2

Check if Assembly Views Exist

a.j_
Explorer
Explorer

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;
}

0 Likes
363 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

Welcome to the Revit API!

 

This sounds doable. First of all, you might want to explore what the Revit database looks like through the API via RevitLookup:

 

https://github.com/jeremytammik/RevitLookup

 

Next, read about how to research to find a Revit API solution:

 

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 

For instance, you can create a list of all Revit database elements before and after creating such an assembly view. 

 

By observing those changes you can determine how to address your task.

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes