Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Revit Macros, UIApp, and PostCommand

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
stever66
1396 Views, 5 Replies

Revit Macros, UIApp, and PostCommand

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 );
            
            
        }

5 REPLIES 5
Message 2 of 6
so-chong
in reply to: stever66

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);
Message 3 of 6
stever66
in reply to: so-chong

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");
            } 
         }

Message 4 of 6
stever66
in reply to: stever66

Oh, and Thanks!!

Message 5 of 6
MiguelGT17
in reply to: so-chong

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? 

Message 6 of 6
RPTHOMAS108
in reply to: MiguelGT17

'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.

Post to forums  

Autodesk Design & Make Report