Revit Run in Automation Mode

Revit Run in Automation Mode

manuel_f_perezii
Participant Participant
225 Views
3 Replies
Message 1 of 4

Revit Run in Automation Mode

manuel_f_perezii
Participant
Participant

Hello Everyone and thank you.

 

I have a powershell script that will load a revit application and most likely will call a revit plugin. Below is my powershell script, addin and the class of my plugin.

# Path to Revit EXE
$revitExe = "C:\Program Files\Autodesk\Revit 2024\Revit.exe"

# Path to your generated journal
$journalPath = "C:\Users\xxxx\AppData\Local\Temp\revit_auto_6e7001a415554ea7af4fb16612599dd9\auto_journal.txt"

# Start Revit with /automation
$tempDir = "C:\Users\xxxx\AppData\Local\Temp\revit_auto_6e7001a415554ea7af4fb16612599dd9"
Start-Process -FilePath $revitExe -ArgumentList "/automation `"$journalPath`"" -WorkingDirectory $tempDir -Wait

addin file

<?xml version="1.0" encoding="utf-8"?>
<RevitAddIns>
  <AddIn Type="Command">
    <Name>BatchKeynoteUpdater</Name>
    <Assembly>C:\Users\xxxx\source\repos\version app.dll</Assembly>
     <AddInId>xxxx</AddInId>  <FullClassName>app.UpdaterCommand</FullClassName>
    <VendorId>x</VendorId>
    <Publisher>x</Publisher>
    <VendorDescription>x</VendorDescription>
    <CommandType>Automation</CommandType>
  </AddIn>
</RevitAddIns>

 

namespace app
{
    [Transaction(TransactionMode.Manual)]
    public class UpdaterCommand : IExternalCommand
    {
   
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
          log("this is called");
        }      
     }
}

My problem here is that the updatercommand execute was never called at all by using the powershell script.  Doing this manually or clicking the revit plugin works.

 

I am kinda stuck on this scenario. Before I posted here I tried to look for answers via AI and I exhausted all the recommendation.

 

If anyone has idea feel free to commend and thank you in advance.

 

0 Likes
226 Views
3 Replies
Replies (3)
Message 2 of 4

charlesyip913
Observer
Observer

Hi, can you share what’s in your journal file? Did you include a Jrn.RibbonEvent call to trigger the command? Also, I’m not sure if your snippet was trimmed, but it looks like you’re missing the return Result.Succeeded; statement. If the code doesn’t compile cleanly due to syntax errors, Revit won’t run the command.

0 Likes
Message 3 of 4

manuel_f_perezii
Participant
Participant

Yes I have trimmed some code, and yes it returns Result.Succeeded; I just forgot to paste it on the code.

 

This is the autojournal text

Dim Jrn
Set Jrn = CrsJournalScript

' open RVT file
Jrn.Command "Ribbon", "Open an existing project , ID_FILE_OPEN"
Jrn.Data "File Name" , "ModelPath" , "C:\Users\xxx\Desktop\revit docs\Link Testing\Link Testing2\MainModel.0011.rvt"

Jrn.Wait "20"

' run your external command
Jrn.RibbonEvent "Execute external command:xxx:app.UpdaterCommand"

' exit Revit
Jrn.Command "Ribbon", "Exit Revit , ID_APP_EXIT"

 

 

0 Likes
Message 4 of 4

jsantana49YZQ
Observer
Observer

Hello @manuel_f_perezii, I try also to test execution of a command with automation mode but it doesn't work for me either.

 

So I have a question, where did you find documentation on this?

 

Thanks in advance

0 Likes