Currently, we do not have Revit API samples for Assembly/Parts in Revit SDK.
So I searched for and I would like to share with you what I found.
Our Revit 2012 API webcast demonstrated the assembly creation. You can download the code sample posted with the webcast recording at Webcast Recording Archive web page. I migrated the code sample tp Revit 2013 (it was an easy task) and attached sample in this blog post for your convenience. It implements two external commands. “CreateAssemblies” command let you pick elements and creates an assembly instance and a part list in a schedule view as following. “Compare Assemblies” command asks you to select two assembly instances and finds differences such as the number or types of elements. For example, you can create walls, windows, and columns as shown below to demonstrate the sample.
public class CreateAssemblies : IExternalCommand
#region IExternalCommand Members
public Result Execute(
ref string message,
// Get the application and document from command data
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
ICollection<ElementId> elemIds =
ElementId categoryId = null;
ElementId keyElemId = null;
if (elemIds.Count > 0)
foreach (ElementId elemId in elemIds)
// Use category of one of the assembly elements
keyElemId = elemId;
categoryId = doc.GetElement(elemId).Category.Id;
Transaction transaction = new Transaction(doc);
// Check if the Category name is valid
doc, categoryId, elemIds
transaction.Start("Create Assembly Instance");
AssemblyInstance assemblyInstance =
AssemblyInstance.Create(doc, elemIds, categoryId);
// Commit the transaction that creates the
// assembly instance before modifying the
// instance's name
// Create another transaction for assigning name to the
// assembly instance
transaction.Start("Set Assembly Name");
"My Assembly Name " + keyElemId.ToString();
// Create assembly views for this assembly instance
// Create Orthographic view
View3D view3d = AssemblyViewUtils.Create3DOrthographic(
// Create Part list
View partList = AssemblyViewUtils.CreatePartList(
Also a blog post by Jeremy shows how to split walls into parts. I recommend to take a look at PartUtils class in the API reference document for what you can do with parts.
Here is a Jeremy’s post in case if you want to create certain AssemblyInstance elements in the model programmatically and would like to prevent the user from being able to modify those elements.