Postable Command - ID_FILE_SAVE

I hope I am using the correct name for the topic.

Here is a quick overview of what I am trying to accomplish:

  1. Open detached central model
  2. clean it out
  3. standardize according to internal guidelines

This is done through a series of small scripts which will be run consecutively through the dynamo player. Some scripts execute in less than two minutes. Some are a bit chunkier and require close to ten minutes. In any case, I would like to prompt the user to save the file after the better part of scripting has been executed.

I can do this with a postable command, but I would like to point to the directory, and pre-set the file name.

Is it possible to point to the directory and specify the file name in the save-as dialogue:

Here is the script I’ve hijacked:

import clr
clr.AddReference(‘RevitAPI’)
clr.AddReference(‘RevitAPIUI’)
import Autodesk
from Autodesk.Revit.UI import RevitCommandId
from Autodesk.Revit.UI import UIApplication
from Autodesk.Revit.UI import ExternalCommandData
clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication

RunIt = IN[0]

if RunIt == True:
CmndID = RevitCommandId.LookupCommandId(‘ID_FILE_SAVE’)
CmId = CmndID.Id
uiapp.PostCommand(CmndID)
errorReport = ‘Success’
else:
errorReport = ‘Set IN[0] to true’

#Assign your output to the OUT variable
OUT = errorReport

1 Like

I believe you should be using the SaveAs method of your doc variable. Doing so, you are able to specify the new filepath, which would include the filename. This would not bring up a dialog box, but it would save the file automatically.

Hi cgartland,

Thank you for the response.

I actually have very little scripting experience with python / scripting in general.

I need a bit of help to automate the file path and file name and to integrate them in the code.
[0] Input = File Path (String)
[1] Input = File Name (String)

I need code, or at least help with the arguements(?).

Cheers,
Matt

I guess the “Syntax” should look something like?

[0] = filePath (String)
[1] = fileName (String)

CmndID = RevitCommandId.LookupCommandId(ID_FILE_SAVEAS, filePath, fileName)

I have no idea how to code this…

The best advice is to NOT use postable commands where possible. They tend to be a last resort. The save as command can be called in a better way as @cgartland suggests by doing the following…

doc.SaveAs("your new file path")

Here is the API method for this…

https://www.revitapidocs.com/2020/25c44d4a-b220-5898-b28c-a2cf6a8a8673.htm

3 Likes

Best advice I have read today. :slight_smile:

2 Likes