I can't seem to find a way to get the UIApplication in a Sharp Macro.
Is the UIApplication not available in a Macro?
And if so, does that mean PostCommand cannot be run from a Macro?
I'm still pretty much a beginner, so it may be missing something simple. Here is what I've tired:
public void PcmdMacro()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = this.ActiveUIDocument.Document;
UIApplication uiapp = ??;
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.ViewRange);
uiapp.PostCommand( id );
}
Solved! Go to Solution.
Solved by so-chong. Go to Solution.
Hi,
You were almost there i think.
Is this what you're looking for?
Document doc = this.ActiveUIDocument.Document; Application app = doc.Application; UIApplication uiapp = new UIApplication(app);
I got an error saying Application was a type but used like a variable (or something like that).
The Help files says the Application is obtained by the Application keyword in a macro, so I made one slight change, and it seems to work.
Unfortunately, ViewRange doesn't seem to be a postable command like I had hoped.
public void PcmdMacro()
{
Document doc = this.ActiveUIDocument.Document;
//Application app = doc.Application;
//UIApplication uiapp = new UIApplication(app);
UIApplication uiapp = new UIApplication(Application);
try
{
//RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.ViewRange);
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent);
if (id != null)
{
TaskDialog.Show("Test", "Found ID");
uiapp.PostCommand(id);
}
}
catch
{
TaskDialog.Show("Test", "error");
}
}
Hi there Mr. So-Chong,
what is the keyword "this" linking to? I'm curious about that, perhaps it is referring to the instance class "uiApp?
'This' is ApplicationEntryPoint which inherits UIApplication and Implements IEntryPoint.
However you see most things related to creating RibbonItems overridden at ApplicationEntryPoint, such as CreateRibbonTab.
PostCommand not overridden.
Can't find what you're looking for? Ask the community or share your knowledge.