For the form code:
using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RevitAddinCS5
{
public partial class Form1 : System.Windows.Forms.Form
{
Document _CachedDoc;
public Form1(Document CachedDoc)
{
InitializeComponent();
_CachedDoc = CachedDoc;
}
private void Form1_Load(object sender, EventArgs e)
{
List<string> list = new List<string>();
List<ViewSheetSet> vsheetsets = new FilteredElementCollector(_CachedDoc)
.OfClass(typeof(ViewSheetSet)).Cast<ViewSheetSet>().ToList();
BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataSource = vsheetsets;
cb.DataSource = bindingSource1.DataSource;
cb.DisplayMember = "Name";
cb.ValueMember = "Views";
}
private void Print_Click(object sender, EventArgs e)
{
try
{
PrintManager printManager = _CachedDoc.PrintManager;
printManager.PrintRange = PrintRange.Select;
ViewSheetSetting viewSheetSetting = printManager.ViewSheetSetting;
viewSheetSetting.CurrentViewSheetSet.Views = cb.SelectedValue as ViewSet;
printManager.SubmitPrint();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
For the External Command:
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
//using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
#endregion
namespace RevitAddinCS5
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class ExtCmd : IExternalCommand
{
#region Cached Variables
private static ExternalCommandData _cachedCmdData;
public static UIApplication CachedUiApp
{
get
{
return _cachedCmdData.Application;
}
}
public static RvtApplication CachedApp
{
get
{
return CachedUiApp.Application;
}
}
public static RvtDocument CachedDoc
{
get
{
return CachedUiApp.ActiveUIDocument.Document;
}
}
#endregion
#region IExternalCommand Members
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
{
_cachedCmdData = cmdData;
try
{
Form1 frm = new Form1(CachedDoc);
frm.Show();
return Result.Succeeded;
}
catch (Exception ex)
{
msg = ex.ToString();
return Result.Failed;
}
}
#endregion
}
}
If this works fine with you don't forget to mark the reply as an answer.
¯\_(ツ)_/¯
Let it work like a charm.
Mustafa Salaheldin


Digital Integration Manager, DuPod
Facebook |
Twitter |
LinkedIn