- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I'm in my first attempt to create some custom Add-ins for Revit written in C# and the first tool I'm struggling to get working is one that takes some *.rvt files from a folder and links them in the active project.
In order to get started I simplified the functionalities of the script and right now I'm just trying to link a file that is hard coded in the script but it is still not working and I'm not too sure on the reason. I suspect it might have to do with the transaction needing to be started and/or closed.
This is where I got so far with my code:
#region Namespaces using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Text; using System.Collections; using System.Linq; using Autodesk.Revit.ApplicationServices; using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Selection; using Autodesk.Revit.Creation; #endregion namespace LinkRVT_test { [Transaction(TransactionMode.Manual)] public class Command : IExternalCommand { public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { // Get application and document objects UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; Autodesk.Revit.DB.Document doc = uidoc.Document; try { using (Transaction transaction = new Transaction(doc)) { transaction.Start("Link files"); string testFile = @"C: \Users\atassera\AT\C#\Revit\LinkRVT_test\Utilities\AR-GAM-3DM-FACADE-RVT.rvt"; ModelPath linkpath = ModelPathUtils.ConvertUserVisiblePathToModelPath(testFile); RevitLinkOptions options = new RevitLinkOptions(false); RevitLinkLoadResult result = RevitLinkType.Create(doc, linkpath, options); RevitLinkInstance.Create(doc, result.ElementId); RevitLinkInstance instance2 = RevitLinkInstance.Create(doc, result.ElementId); Location location = instance2.Location; return Result.Succeeded; } }
When I start debugging, Revit opens and I go in the Add-Ins panel, External Tools and click the tool I'm creating but nothing happens.
Any help is greatly appreciated!
Thank you
Andrea
Solved! Go to Solution.