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: 

PostCommand() takes exactly 2 arguments (1 given)

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
davidvadkerti
1699 Views, 4 Replies

PostCommand() takes exactly 2 arguments (1 given)

Hi,

I was trying to run Purge Unused command by following code:

 

Command_ID=RevitCommandId.LookupPostableCommandId(PostableCommand.PurgeUnused)
UIApplication.PostCommand(Command_ID)

It gets me this error: 

PostCommand() takes exactly 2 arguments (1 given)
As I understand explanation at revitapidocs it should take just one argument. Can you tell me what I got wrong please?
Thanks a lot.

 

4 REPLIES 4
Message 2 of 5

UIApplication is a class. You need an instance. I assume the instance is regarded as the first argument. Look at other PostCommand samples:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.3

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5

Thanks a lot Jeremy!

I am not familiar with C# in any sense, but your hint helped me a lot. I am using Python in Revit Python Shell and Pyrevit. My solution was like this:

#calling command Purge Unused
from Autodesk.Revit.UI import UIApplication, RevitCommandId, PostableCommand
doc = __revit__.ActiveUIDocument.Document

Command_ID=RevitCommandId.LookupPostableCommandId(PostableCommand.PurgeUnused)
#alternative way of getting command ID
#Command_ID=RevitCommandId.LookupCommandId("ID_PURGE_UNUSED") uiapp = UIApplication(doc.Application) UIApplication.PostCommand(uiapp,Command_ID)

I supose there isn't any other way to run command and submit it (like clicking on OK button). At least I haven't found any direct way in Revit API.

 

Message 4 of 5

You are still using a method on the class:

 

  UIApplication.PostCommand(uiapp,Command_ID)

 

The normal thing to do is to call a method on the class instance instead.

 

That is shorter and more readable:

 

  uiapp.PostCommand(Command_ID)

 

And, as you see, only one argument is provided.

 

The instance implicitly becomes an argument as well, the first argument, often called `this`.

 

Read a bit on Python object oriented programming basics before proceeding any further.

  

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 5

Thanks for advice.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report