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:
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
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
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.
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
Can't find what you're looking for? Ask the community or share your knowledge.