Revit 2024 - Constantly getting managed exception with OpenAndActivateDocument

Revit 2024 - Constantly getting managed exception with OpenAndActivateDocument

hzamani
Advocate Advocate
145 Views
4 Replies
Message 1 of 5

Revit 2024 - Constantly getting managed exception with OpenAndActivateDocument

hzamani
Advocate
Advocate

Hi there,

 

I am getting  Autodesk.Revit.Exceptions.InternalException: A managed exception was thrown by Revit or by one of its external applications, how ever I call the OpenAndActivateDocument. 

I have tried multiple models, stand-alone or workshared. I also have tried different overloads eg passing model path as string with OpenAndActivateDocument(path) or OpenAndActivateDocument(modelPath, options, bool) - none of these work. This is just in Revit 2024. Any version before that is working fine.

 

Does anyone have any suggestions what could be the issue here? 

 

Regards

 

 

0 Likes
146 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @hzamani ,

 

Could you please confirm if you are able to open the same models manually in Revit 2024 via the Revit UI without any issues?
Is this issue specific to the API?

Additionally, could you share the non-confidential sample code you used?
It would also be helpful if you could provide the journal file via the Private Forum chat so that I can analyze the issue further.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

hzamani
Advocate
Advocate

Hi @naveen.kumar.t ,

 

This is only happening through the API. I can open the file through the UI just fine. 

The original code is in C#:

 

OpenOptions openOptions = new OpenOptions();
// I have tested commenting out the two lines below for modifying the openOptions, still getting the same error
openOptions.DetachFromCentralOption = DetachFromCentralOption.ClearTransmittedSaveAsNewCentral;
openOptions.SetOpenWorksetsConfiguration(new WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets));

Directory.CreateDirectory(@"C:\Revit_Projects");
string newLocalPathAndName = Path.Combine(@"C:\Revit_Projects", modelNames[0]
                        + "_" + uiApp.Application.Username + "_"
                        + DateTime.Now.ToString("ddMMMMyy_HHmm") + ".rvt");
ModelPath localModelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(newLocalPathAndName);
var createdDoc = uiApp.OpenAndActivateDocument(localModelPath, openOptions, false);

 

I have also tested this in python with Revit Python Shell:

 

path = r'C:\Users\hzamani\Desktop\Project1.rvt'
#mpath = ModelPathUtils.ConvertUserVisiblePathToModelPath(path)
#options = OpenOptions()
#options.DetachFromCentralOption = DetachFromCentralOption.ClearTransmittedSaveAsNewCentral
#options.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach
#options.SetOpenWorksetsConfiguration(WorksetConfiguration(WorksetConfigurationOption.OpenAllWorksets))

uiapp = __revit__

#uiapp.OpenAndActivateDocument(mpath, options, False)
uiapp.OpenAndActivateDocument(path)

 

No matter what I do I still get the same error. This is happening in Revit 2024. Running the same code in Revit 2025 crashed Revit! In older version it's working fine.

 

Thanks

0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @hzamani ,

 

A suggestion from Engineering team: Could you try using "Save As" instead of "Close and Save" to clear the transmittal status and mark the model as a new central?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

hzamani
Advocate
Advocate

Thanks @naveen.kumar.t will give this a try.

0 Likes