pyRevit CLI SaveToCloud rvt2021

Hi,
Could you help me with some code? It should work, but unfortunately not :smiley:
I run command:

pyrevit run "C:\Users\tomasz.puchala\OneDrive - Arup\pyRevitCLI\myscript.py" 
"C:\Users\tomasz.puchala\OneDrive - Arup\pyRevitCLI\WA050-ARP-ZZ-ZZ-M3-A-ZZZZ-9001_test.rvt"

script is straight forward - revit 2021+

from pyrevit import HOST_APP
from Autodesk.Revit.DB import SaveAsOptions
import System
from System import Guid

# __models__ is set to a list of model file paths

for model in __models__:
    uidoc = HOST_APP.uiapp.OpenAndActivateDocument(model)
    doc = uidoc.Document

    filepath = doc.PathName
    name = System.IO.Path.GetFileName( filepath )
    
    opt = SaveAsOptions(OverwriteExistingFile = True)
    doc.SaveAs(filepath, opt)

    accountId = Guid('16254c15-5884-4102-9b1a-XXXX')
    projectId = Guid('0ef11c59-0592-475b-b928-XXXX')
    folderId = 'urn:adsk.wipprod:fs.folder:co.Y3EPE_zBTFmDu8tLK1XXXX'
    

    doc.SaveAsCloudModel(accountId, projectId, folderId, name)

Error:

IronPython Traceback:
Traceback (most recent call last):
  File "C:\Users\tomasz.puchala\OneDrive - Arup\pyRevitCLI\myscript.py", line 38, in <module>
Exception: The given Id is not a valid GUID value.
Parameter name: accountId or projectId


Script Executor Traceback:
Autodesk.Revit.Exceptions.ArgumentException: The given Id is not a valid GUID value.
Parameter name: accountId or projectId
   at Autodesk.Revit.DB.Document.SaveAsCloudModel(Guid accountId, Guid projectId, String folderId, String modelName)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`5.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`7.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
   at PyRevitLoader.ScriptExecutor.ExecuteScript(String sourcePath, IEnumerable`1 sysPaths, String logFilePath, IDictionary`2 variables)

I’ve already tested this code in Dynamo (using Rhythm package to get document) and it works as expected (GUIDs are valid).
Am I missing something? :smiley:

from pyrevit import HOST_APP, revit
from Autodesk.Revit.DB import SaveAsOptions
import System
from System import Guid

doc = revit.doc

filepath = doc.PathName
name = System.IO.Path.GetFileName( filepath )

opt = SaveAsOptions(OverwriteExistingFile = True)
doc.SaveAs(filepath, opt)

folderId = "urn:adsk.wipprod:fs.folder:co.xxxxxxxxxxxxxxxxxxxxx"
doc.SaveAsCloudModel(folderId, "test.rvt")

tested in revit 2020, directly through a pushbutton in my toolbar:
I had to remove the account and project id (because 2020)
removed the loop
and used the revit.doc instead of the HOSTAPP… as the model was open

it worked

used your code in the pyrevit runner:
just removed account id and project id because of 2020

got the same error as you but for the folderId.

tried many different ways. I am guessing it has to do with the fact that the command SaveAsCloudModel does not have the time to process entirely before the runner closes revit.
what do you think @eirannejad ?