how to put outlet in the wall?
I'm trying to create code to add an outlet to the wall. (Same as done in Revit's Systems tab)
when I run the code I get the following error
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IExternalCommand1
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIDocument uIDocument = commandData.Application.ActiveUIDocument;
Document document = uIDocument.Document;
#region
FilteredElementCollector outlet = new FilteredElementCollector(document);
outlet.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_ElectricalFixtures);
FamilySymbol familySymbol = outlet.FirstElement() as FamilySymbol;
ElementId elementId = new ElementId(308696);
Wall wall = document.GetElement(elementId) as Wall;
var reference = HostObjectUtils.GetSideFaces(wall, ShellLayerType.Interior).First();
using (Transaction transaction = new Transaction(document))
{
transaction.Start("add");
if (wall != null)
{
var instance = document.Create.NewFamilyInstance(reference,
new XYZ(13.3997604933275, -1.35161192601243, 9.0571329707487),
new XYZ(0, 0, 0),
familySymbol);
if (instance == null)
TaskDialog.Show("ERROR", "Instance is null!");
}
transaction.Commit();
}
#endregion
return Result.Succeeded;
}
}
}