- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi to all, steeping into Revit API for the first time and I'm having issues with the first attempt to create addin. Keep in mind that I do not have any previous experience with programming and API-s, so i would appreciate if someone could walk me through the process.
I created ExternalCommand for making sheets and it works from AddIns tab > External Commands.
I'm trying to make it executable trough its Button on the ribbon tab, but I'm facing the problem.
This is a screenshot of notification window appeared when I try to execute the command by clicking Ribbon panel button:
I'm guessing that the problem is somewhere in my addin manifest file or somewhere with the lines for External command executing, but I can't solve it myself... unfortunately... Any help?
This is my code:
namespace SheetAddin { class App : IExternalApplication { public Result OnStartup(UIControlledApplication a) { a.CreateRibbonTab("Toolbar"); RibbonPanel P01 = a.CreateRibbonPanel("Toolbar", "Toolbar"); string path = Assembly.GetExecutingAssembly().Location; PushButtonData buttonShow = new PushButtonData("CreateSheets", "CreateSheets", path, "SheetAddin.Toolbars"); buttonShow.LargeImage = GetImage(Resources.SheetIcon.GetHbitmap()); //Add the buttons to the panel RibbonItem ri1 = P01.AddItem(buttonShow); return Result.Succeeded; } //Buttons image size loading on startup private System.Windows.Media.Imaging.BitmapSource GetImage(IntPtr bm) { System.Windows.Media.Imaging.BitmapSource bmSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( bm, IntPtr.Zero, System.Windows.Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); return bmSource; } public Result OnShutdown(UIControlledApplication a) { return Result.Succeeded; } public class Toolbars : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { #region CREATE SHEETS UIApplication uiApp = commandData.Application; Document doc = uiApp.ActiveUIDocument.Document; UIDocument uidoc = uiApp.ActiveUIDocument; //define starting sheet number int sheetNum = 101; FilteredElementCollector viewColl = new FilteredElementCollector(doc); viewColl.OfClass(typeof(ViewPlan)); FilteredElementCollector tblockColl = new FilteredElementCollector(doc); tblockColl.OfCategory(BuiltInCategory.OST_TitleBlocks); Transaction curTrans = new Transaction(doc, "Create Sheets"); curTrans.Start(); foreach (ViewPlan curView in viewColl.OrderBy(zz => zz.Name)) { if (curView.ViewType == ViewType.FloorPlan) { if (curView.IsTemplate == false) { ViewSheet newSheet; newSheet = ViewSheet.Create(doc, tblockColl.FirstElementId()); newSheet.Name = curView.Name; newSheet.SheetNumber = "A" + sheetNum.ToString(); sheetNum++; } } } //comit changes and close transaction curTrans.Commit(); curTrans.Dispose(); #endregion return Result.Succeeded; } } } }
and this is the addin manifest:
<?xml version="1.0" encoding="utf-8"?> <RevitAddIns> </AddIn>--> <AddIn Type="Application"> <Name>Application SheetAddin</Name> <Assembly>SheetAddin.dll</Assembly> <FullClassName>SheetAddin.App</FullClassName> <ClientId>9fb2e77f-2f3f-41ef-9e56-77c7debafc19</ClientId> <VendorId>testingrevitapi</VendorId> <VendorDescription>MiletaP</VendorDescription> </AddIn> </RevitAddIns>
Solved! Go to Solution.