
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I creating an application for revit addin in which when we click on addin it open the windows form .
Form contain combobox and button, if we select an item from combobox the clicked button it run the class which we have call on that click button.
Addin Ribbon code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.UI;
using System.Reflection;
namespace FormDemo
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Class1 : IExternalApplication
{
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
public Result OnStartup(UIControlledApplication application)
{
RibbonPanel ribbonPanel = application.CreateRibbonPanel("Form");
string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
//string assembly = @"D:\Software\FormDemo\FormDemo\bin\Debug\FormDemo.dll";
PushButtonData bOne = new PushButtonData("ButtonNameA", "FormDemo1",
thisAssemblyPath, "FormDemo.Class2");
PushButton pushButton = ribbonPanel.AddItem(bOne) as PushButton;
return Result.Succeeded;
}
}
}
Class2 Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
namespace FormDemo
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
class Class2 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Form1 fm = new Form1();
fm.Show();
return Result.Succeeded;
}
}
}
Form code:-
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
namespace FormDemo
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public partial class Form1 : System.Windows.Forms.Form
{
ExternalCommandData commandData;
// ElementSet elements;
// string message=null;
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Wall And Column");
}
public void button1_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedItem == "Wall And Column")
{
try
{
//In this block ,How I call WCjoin class and it execute the code of that class
}
catch(Exception g)
{
TaskDialog.Show("revit", "error is occured"+g);
}
TaskDialog.Show("revit", "Joined Wall And Column");
}
}
}
}
WCjoin class Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace FormDemo
{
[Transaction(TransactionMode.Manual)]
class WCjoin
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;
//-----------get walls on the active view-----------
FilteredElementCollector collWalls = new FilteredElementCollector(doc, doc.ActiveView.Id);
collWalls.OfClass(typeof(Wall));
foreach (Wall w in collWalls)
{
FilteredElementCollector collColumnsOnThisWall = new FilteredElementCollector(doc, doc.ActiveView.Id);
collColumnsOnThisWall.OfClass(typeof(FamilyInstance));
collColumnsOnThisWall.OfCategory(BuiltInCategory.OST_StructuralColumns);
foreach (FamilyInstance column in collColumnsOnThisWall)
{
using (Transaction t = new Transaction(doc, "Join All Walls/Column"))
{
t.Start();
JoinGeometryUtils.JoinGeometry(doc, w, column);
t.Commit();
}
}
}
TaskDialog.Show("revit", "in class");
return Result.Succeeded;
}
}
}
//If i write the code in the form.cs class in try block like this
try
{
WCjoin wcj = new WCjoin();
wcj.Execute(commandData, ref message1, elements);
}
//it give me error..I attach image which show error.
I had added some screen shot..plz tell me what i should do!
Solved! Go to Solution.