Message 1 of 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
Really sorry, but I can't get this to work. I am sure it's really basic. I'm just starting to learn C#
Following on from here...
I have an embedded resource .png which I cannot get to link into my project correctly.
This is obviously wrong...
PNGtoImageSource("HTA_Ribbon.totalLength.png");Any assistance greatfully received.
Apologies again for such a basic question.
Thanks,
Mark
Code below
using System;
using System.Reflection;
using System.IO;
using Autodesk.Revit.UI;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace HTA_Ribbon
{
class App : IExternalApplication
{
private ImageSource PNGtoImageSource(string embeddedPath)
{
Stream myStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedPath);
PngBitmapDecoder decoder = new PngBitmapDecoder(myStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
return decoder.Frames[0];
}
// define a method that will create our tab and button
static void AddRibbonPanel(UIControlledApplication application)
{
// Create a custom ribbon tab
String tabName = "HTA";
application.CreateRibbonTab(tabName);
// Add a new ribbon panel
RibbonPanel ribbonPanel = application.CreateRibbonPanel(tabName, "Tools");
// Get dll assembly path
string thisAssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
// create push button for CurveTotalLength
PushButtonData b1Data = new PushButtonData(
"cmdCurveTotalLength",
"Total" + System.Environment.NewLine + " Length ",
thisAssemblyPath,
"Curve_Total_Length.CurveTotalLength");
//add push button to ribbon
PushButton pb1 = ribbonPanel.AddItem(b1Data) as PushButton;
pb1.ToolTip = "Select Multiple Lines to Obtain Total Length";
// create embedded Large Image
BitmapImage pbImage = PNGtoImageSource("HTA_Ribbon.totalLength.png");
pb1.LargeImage = pbImage;
}
public Result OnShutdown(UIControlledApplication application)
{
// do nothing
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
// call our method that will load up our toolbar
AddRibbonPanel(application);
return Result.Succeeded;
}
}
}
Solved! Go to Solution.