I have created an add-in for revit, inside which I transform the Revit geometry.DB to Autodesk geometry.Design Script.Geometry, so that Dynamo methods can be applied.
Here is an example of the code
using System.Windows.Media.TextFormatting;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.DesignScript.Geometry;
using Autodesk.Revit.UI;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.UI.Selection;
using Dynamo;
using RevitServices.Persistence;
using RevitServices.Transactions;
using Autodesk.Revit.Attributes;
namespace Интеграция_Динами
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
class Helper : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
Document doc = uidoc.Document;
#region Core Logic
IList<Reference> refElementsA;
try
{
refElementsA = uidoc.Selection.PickObjects(ObjectType.Face, "Please pick elements (set A)");
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
return Result.Cancelled;
}
//TransactionManager.SetupManager();
// this is must-do assignmet so that we can use wrapper functions
DocumentManager.Instance.CurrentUIDocument = uidoc;
List<Revit.Elements.Element> elementSetA = Helper.GetWrappedElements(refElementsA, doc);
Revit.Elements.Element F = elementSetA[0];
Autodesk.DesignScript.Geometry.Surface[] SF = F.Faces;
#endregion
//this is must do call as wrapper function opens an transaction but doesn't close it.
//if not called an error will be shown to the user after excuting the command.
TransactionManager.Instance.ForceCloseTransaction();
return Result.Succeeded;
}
/// <summary>
/// this is our helper method DocumentManager. Instance. CurrentUIDocument = uidoc must be setted before calling this function.
/// </summary>
/// <param name="refElements"></param>
/// <param name="mainDoc"></param>
/// <returns></returns>
public static List<Revit.Elements.Element> GetWrappedElements(IList<Reference> refElements, Document mainDoc)
{
List<Revit.Elements.Element> result = new List<Revit.Elements.Element>();
foreach (var refElement in refElements)
{
var rvtElement = mainDoc.GetElement(refElement);
result.Add(Revit.Elements.ElementWrapper.Wrap(rvtElement, false));
}
return result;
}
}
}
On the 52nd line of the code, it constantly gives an error, I don’t understand it.
Help me figure it out.