The following code creates exceptions in 2018, 2019, and 2020
foreach (var command in (PostableCommand[])Enum.GetValues(typeof(PostableCommand))) { var commandId = RevitCommandId.LookupPostableCommandId(command); }
These are the PostableCommands that fail
2018:
PostableCommand.ViewRange
2019:
PostableCommand.PublishDGNToAutodeskBuzzsaw
PostableCommand.PublishDWFToAutodeskBuzzsaw
PostableCommand.PublishDWGToAutodeskBuzzsaw
PostableCommand.PublishDXFToAutodeskBuzzsaw
PostableCommand.PublishSATToAutodeskBuzzsaw
PostableCommand.ViewRange
2020:
PostableCommand.DrawOnFace
PostableCommand.DrawOnWorkPlane
PostableCommand.PublishDGNToAutodeskBuzzsaw
PostableCommand.PublishDWFToAutodeskBuzzsaw
PostableCommand.PublishDWGToAutodeskBuzzsaw
PostableCommand.PublishDXFToAutodeskBuzzsaw
PostableCommand.PublishSATToAutodeskBuzzsaw
PostableCommand.ViewRange
Also, the static method RevitCommandId.LookupCommandId returns null for every command
foreach (var command in Enum.GetNames(typeof(PostableCommand))) { var commandId = RevitCommandId.LookupCommandId(command); if (commandId != null) Debugger.Break(); //This line is never reached }
I can replicate the exceptions you are getting from the first portion of code that you posted.
Regarding the second portion of your post, I believe the null values you are getting are the expected and correct outcome of the code you posted. The RevitCommandId.LookupCommandId() method does not take in the names of PostableCommands, but rather the string values of the names of the internal commands that Revit uses, i.e. the output of the LookupPostableCommandId method, the names of which look like this:
ID_CREATE_GUIDE_GRID ID_CREATE_ASSEMBLY ID_STAIRS_TRISER_NUMBER ID_MANAGE_CONNECTION_TO_A_REVIT_SERVER_ACCELERATOR ID_PHOTO_RENDER_IN_CLOUD ID_PHOTO_RENDER_GALLERY ID_ENABLE_ENERGY_ANALYSIS ID_DISPLACEMENT_CREATE ID_SETTINGS_ASSEMBLY_CODE ID_TOGGLE_FABPART_BROWSER ID_PLAYLIST_DYNAMO
Per the RevitAPI documentation, you can get these string values from Revit Journal files, or, if they pertain to a PostableCommand, you can output them with an augmentation to your own code:
foreach (var command in (PostableCommand[])Enum.GetValues(typeof(PostableCommand))) { var commandId = RevitCommandId.LookupPostableCommandId(command); Debug.Log(commandId.Name) //or whichever way you prefer to collect and display these names }
Hope this helps!
Can't find what you're looking for? Ask the community or share your knowledge.