Here is how to create an assembly and assembly views from a group
public void assemblyFromGroup()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uidoc = this.ActiveUIDocument;
// prompt the user to select a group
Group group = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as Group;
View v3d = null;
View partlist = null;
View section = null;
using (Transaction t = new Transaction(doc,"Create Assembly From Group"))
{
t.Start();
// ungroup the group, getting the list of elements in the group
List<ElementId> ids = group.UngroupMembers().ToList();
// get the category of the first element in the group
// a category needs to be specified when creating the assembly
Category cat = doc.GetElement(ids.First()).Category;
// create the assembly
AssemblyInstance ai = AssemblyInstance.Create(doc, ids, cat.Id);
// create the assembly views
v3d = AssemblyViewUtils.Create3DOrthographic(doc, ai.Id);
partlist = AssemblyViewUtils.CreatePartList(doc, ai.Id);
section = AssemblyViewUtils.CreateDetailSection(doc, ai.Id, AssemblyDetailViewOrientation.DetailSectionA);
t.Commit();
}
// activate the new views so they are visible when the command ends
// The active view can only be changed when there is no open transaction
uidoc.ActiveView = v3d;
uidoc.ActiveView = partlist;
uidoc.ActiveView = section;
}
Harry!!!! You are the man!!!!!!!!! Thank you so much for an awesome lab at RTC and providing exceptional help to new people trying to learn the Revit API! It was a pleasure!
[…] #RTCNA Wish 6 granted! Create assemblies from groups […]
[…] #RTCNA Wish 6 granted! Create assemblies from groups […]
I’m new to the API and was wonding how would you go about adding the other possible assembly views, ie plan, section, elevation
Hi,
Have you looked at AssemblyViewUtils..::..CreateDetailSection Method and the options for the AssemblyDetailViewOrientation Enumeration?