- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am creating a medium sized add-in (Using C#). The add-in will launch the WindowWizard Add-in from a project file Ribbon by openning the RFT file, and then launching the WindowWiazard form programmatically.
The windowWizard typically will save the family, then finishes with a completed window family. This all works well. I would like the RFT file to close once this save is complete but I can't seem to get the
doc.Close(); method to work. Can anyone please point me in the correct direction?
Please refer to the following code:
using System;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
namespace DuraRibbon
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
class CmdLogo3 : IExternalCommand
{
private static ExternalCommandData _cachedCmdData;
public static UIApplication CachedUiApp
{
get
{
return _cachedCmdData.Application;
}
}
public static RvtApplication CachedApp
{
get
{
return CachedUiApp.Application;
}
}
public static RvtDocument CachedDoc
{
get
{
return CachedUiApp.ActiveUIDocument.Document;
}
}
private const string Path = @"C:\ProgramData\Autodesk\RVT 2021\Family Templates\English-Imperial\Window.RFT";
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
{
_cachedCmdData = cmdData;
Document doc = CachedApp.OpenDocumentFile(Path);
cmdData.Application.OpenAndActivateDocument(Path);
using (TransactionGroup transGroup = new TransactionGroup(doc))
{
using (Transaction trans = new Transaction(doc))
{
try
{
transGroup.Start("Action");
trans.Start("First Transaction");
// do some stuff
// do your modifications
UIApplication uiapp = cmdData.Application;
RevitCommandId id_built_in = RevitCommandId.LookupPostableCommandId(PostableCommand.SheetIssuesOrRevisions);
string name = "a3777760-d59c-426e-bcdc-01c805aa37b9";
RevitCommandId id_addin = RevitCommandId.LookupCommandId(name);
uiapp.PostCommand(id_addin);
if (trans.Commit() != TransactionStatus.Committed)
{
return Result.Failed;
}
trans.Start("Second Transaction");
// do some more stuff
doc.Close();
trans.Commit();
if (trans.Commit() != TransactionStatus.Committed)
{
return Result.Failed;
}
transGroup.Assimilate();
}
catch (Exception ex)
{
msg = ex.ToString();
return Result.Failed;
}
}
Solved! Go to Solution.