Hello All,
I'm getting stuck when build an application UI, everything works perfect when I build the code, but when Revit opened and when run the plugin there is an error window titled Command Failure for External Command came up saying "Revit could not complete the external command. Contact the provider for assistance. Information they provided to Revit about their identity:."
Is there anoyone here knows where is the mistake or knows the solution for this?
Many Thanks
Looking forward your response.
Here is my C# code:
Code:
using System;using System.Collections.Generic;
using System.Linq;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using System.Text;
using System.Windows.Forms;
using JungHwanUI;
[TransactionAttribute(TransactionMode.Manual)]
[RegenerationAttribute(RegenerationOption.Manual)]
public class JHUI : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
//Get application and document objects
UIApplication uiApp = commandData.Application;
Document doc = commandData.Application.ActiveUIDocument.Document;
//Define a Reference object to accept the pick result.
Reference pickedRef = null;
//Pick a group
Selection sel = uiApp.ActiveUIDocument.Selection;
pickedRef = sel.PickObject(ObjectType.Element, "Please select a wall");
Element elem = doc.GetElement(pickedRef);
Wall wall = elem as Wall;
double wallArea = wall.get_Parameter("Area").AsDouble();
JHUIData data = new JHUIData();
data.WallArea = wallArea;
StringBuilder sb = new StringBuilder();
sb.AppendFormat("Selected {0}\n", wall.Name);
foreach (Material mat in wall.Materials)
{
double area = wall.GetMaterialArea(mat);
double volume = wall.GetMaterialVolume(mat);
double height = volume / area;
double length = wall.get_Parameter("Length").AsDouble();
double width = area / length;
sb.AppendFormat("Material: {0}\nArea={1} ft^2\nVolume={2} ft^3\n" +
"Length={3} ft\nWidth={4} ft\nHeight={5} ft\nclass={6}", mat.Name,
area, volume, length, width, height, mat.MaterialClass);
data.ElementName = wall.Name;
JHUIData.CostLabMaterialInfo matInfo = new JHUIData.CostLabMaterialInfo();
matInfo.MaterialName = mat.Name;
matInfo.Area = area;
matInfo.Volume = volume;
matInfo.Length = length;
matInfo.Width = width;
matInfo.Height = height;
data.AddMaterialInfo(matInfo);
}
string prompt = sb.ToString();
TaskDialog taskDialog = new TaskDialog("JungHwangUI");
// Nice to set stuffs
taskDialog.Id = "ID_TaskDialog_JungHwanUI";
taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconNone;
taskDialog.Title = "JHUI";
taskDialog.TitleAutoPrefix = true;
taskDialog.AllowCancellation = true;
taskDialog.MainInstruction = "JHUI";
taskDialog.MainContent = prompt;
// Common button stuffs
taskDialog.CommonButtons = TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Close;
//TaskDialogResult result = taskDialog.Show();
FormJHUI form = new FormJHUI(data);
form.ShowDialog();
//GetElementParameterInformation(doc, elem);
//Pick a point
//XYZ point = sel.PickPoint("Please pick a point to place group");
//Place the group
//Transaction trans = new Transaction(doc);
//trans.Start("Lab");
//doc.Create.PlaceGroup(point, group.GroupType);
//trans.Commit();
return Result.Succeeded;
}
}