Revit API 2022 PostableCommand CopyMonitorSelectLink

Revit API 2022 PostableCommand CopyMonitorSelectLink

TomB.ADV
Advocate Advocate
309 Views
2 Replies
Message 1 of 3

Revit API 2022 PostableCommand CopyMonitorSelectLink

TomB.ADV
Advocate
Advocate

Hi,

 

I noticed there is a Copy Monitor related command in the 2022 API version which I'm not sure how to use.
I want to automate the Copy-Monitor process for levels and grids which we are doing manually for each new
Revit project file. I have the below code where I get the RevitCommandId but I can't figure out how to proceed...

I don't have much experience with postable commands, any help would be very appreciated !

 

namespace AdvTools.Commands
{
    [Transaction(TransactionMode.Manual)]
    public class CopyMonitor : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            ExternalCommandData CommandData = commandData;
            UIApplication Uiapp = CommandData.Application;
            Application App = Uiapp.Application;
            UIDocument Uidoc = CommandData.Application.ActiveUIDocument;
            Document document = Uidoc.Document;

            RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.CopyMonitorSelectLink);
            return Result.Succeeded;
        }
    }
}

 

0 Likes
310 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni

Okey-doke. Well, one place to check for samples and documentation on getting started with that is The Building Coder topic group on PostCommand:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 3

TomB.ADV
Advocate
Advocate

Hi @jeremy_tammik ,

 

so just to be sure I'm in the right direction, I added some more code to select the Levels after I posting the command but it seems like Revit stops the CopyMonitor function at that point.

 

Is there any other approach to make the task done except programmatically providing input which otherwise the

user would have to do manually as you mentioned on your website here:

 

https://thebuildingcoder.typepad.com/blog/2017/12/magic-number-magic-automation-and-magic-season.htm...

 

 Uiapp.PostCommand(RevitCommandId.LookupPostableCommandId(PostableCommand.CopyMonitorSelectLink));

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            IList<Element> elems = collector
            .OfCategory(BuiltInCategory.OST_RvtLinks)
            .OfClass(typeof(Level))
            .ToElements();

            List<ElementId> icollection = new List<ElementId>();
            foreach (Element e in elems)
            {
                icollection.Add(e.Id);
            }

            Uidoc.Selection.SetElementIds(icollection);

 

0 Likes