- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I create a user control which call class. The class contain code for joining wall and column. While running the show error that Starting a transaction from an external application running outside of API context is not allowed.
After solving this error it show the error Object reference not set to an instance of an object. How can I solved this error and run my code?
This is my code:
USER CONTROL CLASS:
namespace AdvanceQuickJoin
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
/// <summary>
/// Interaction logic for UserControl1.xaml
/// </summary>
public partial class UserControl1 : UserControl
{
ExternalCommandData commandData;
UIApplication app;
public UserControl1(ExternalCommandData commandDatax)
{
commandData = commandDatax;
InitializeComponent();
// Set a fixed height and width for the control.
}
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Hello friends! I am from the WPF world!");
}
private void button_Click(object sender, RoutedEventArgs e)
{
// MessageBox.Show("");
WallStcolumnJoin wc = new WallStcolumnJoin();
wc.Execute(app);
}
}
}
This is my class which has code for joining:
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
namespace AdvanceQuickJoin
{
[Transaction(TransactionMode.Manual)]
class WallStcolumnJoin :IExternalEventHandler
{
public void Execute(UIApplication app)
{
UIDocument uidoc = app.ActiveUIDocument;
Document doc = uidoc.Document;
using (Transaction t = new Transaction(doc, "Join All Walls/Column"))
{
t.Start();
FilteredElementCollector column = new FilteredElementCollector(doc, doc.ActiveView.Id);
column.OfClass(typeof(FamilyInstance));
column.OfCategory(BuiltInCategory.OST_StructuralColumns);
foreach (FamilyInstance c in column)
{
FilteredElementCollector Walls = new FilteredElementCollector(doc, doc.ActiveView.Id);
Walls.OfClass(typeof(Wall));
Walls.WherePasses(new ElementIntersectsElementFilter(c));
foreach (Wall w in Walls)
{
JoinGeometryUtils.JoinGeometry(doc, w, c);
}
}
t.Commit();
}
}
}
}
Solved! Go to Solution.