Crash in OpenAndActivateDocument

Crash in OpenAndActivateDocument

ebarMLN7G
Enthusiast Enthusiast
1,037 Views
7 Replies
Message 1 of 8

Crash in OpenAndActivateDocument

ebarMLN7G
Enthusiast
Enthusiast

We use UIApplication.OpenAndActivateDocument(String fileName) to open and activate documents. It has been working fine for us without any issues. But on a couple models we are getting:

 

 

Opening was canceled., Stack:    at Autodesk.Revit.UI.UIApplication.OpenAndActivateDocument(String fileName)

 

 

Looking at the errors I found:

 

 

Object reference not set to an instance of an object.

Source Autodesk.WorksharingMonitor.Application StackTrace at WorkSharingLib.ExternalApplication.DocumentClosing(Object obj, DocumentClosingEventArgs eArgs)

 

 

Also:

 

'309.808524=== 2:<<FormOrAbandon::openFromModelPath [C:\Users\ebar\AppData\Local\Launcher\Revit\UNO1A-PIM.rvt]
' 2:< ::1295:: Delta VM: Avail -17 -> 134208931 MB, Used +1 -> 5459 MB; RAM: Avail +18 -> 218156 MB, Used +0 -> 5557 MB
' 2:< GUI Resource Usage GDI: Avail 9825, Used 175, User: Used 161
' 2:< API_ERROR {  System.NullReferenceException exception(Object reference not set to an instance of an object.) was thrown from a handler of Autodesk.Revit.Proxy.DB.Events.DocumentOpenedEventArgsProxy event. The API event handler was registered by application Export To Revit (df5b7489-f0e6-4f83-8010-3d852316d225). Changes made by this handler are going to be discarded. }
' 0:< ModelPath Created: Is server path = True, Region = "GLOBAL", Central server = "", Path = "CLD:\\GLOBAL\{00000000-0000-0000-0000-000000000000}Project-UNO1-A\{00000000-0000-0000-0000-000000000000}UNO1A-PIM.rvt"
' 2:< ::1295:: Delta VM: Avail +15 -> 134208946 MB, Used 5459 MB; RAM: Avail -14 -> 218143 MB, Used 5557 MB
' 2:< GUI Resource Usage GDI: Avail 9825, Used 175, User: Used 161
' 2:< API_ERROR {  System.ArgumentNullException exception(Value cannot be null.
'Parameter name: key) was thrown from a handler of Autodesk.Revit.Proxy.DB.Events.DocumentOpenedEventArgsProxy event. The API event handler was registered by application FormIt Conversion (eccb03c4-b3c3-4c39-868e-5d65d9ce20bd). Changes made by this handler are going to be discarded. }
  ' 1:< ::1295:: Delta VM: Avail -18 -> 134208928 MB, Used 5459 MB; RAM: Avail 218143 MB, Used 5557 MB
  ' 1:< GUI Resource Usage GDI: Avail 9825, Used 175, User: Used 161
  'E 27-Jul-2022 11:31:23.551;   1:<

 

 

So it seems like they are caused by FormIt and WorkSharingLib. How can I get around this issue?

 

 

1,038 Views
7 Replies
Replies (7)
Message 2 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @ebarMLN7G ,

 

You say this problem only occurs in a couple of models.

One possible reason is that the model you are trying to open is corrupted.

Is it possible to open these models without any problem in Revit UI(Without using API)?

Are you facing this issue only when trying to open models using the API?

Can you share some more information about the model you are trying to open?

If possible please share the journal file with us.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 8

ebarMLN7G
Enthusiast
Enthusiast

Hi Naveen, yes the models are fine and I can open them using Revit UI.

0 Likes
Message 4 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @ebarMLN7G ,

 

I have no clue what is causing this issue.
Here is the list of OpenAndActivateDocument Method's Overload List

https://www.revitapidocs.com/2023/5018fbdb-e7c3-6e32-7ca3-ee5c20dbc56f.htm 

Please try using the other 2 methods.

If nothing helps, Please send us the non-confidential sample Revit file and journal file to analyze this issue at our end.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 8

ebarMLN7G
Enthusiast
Enthusiast

Hi, 

 

I tried to change the use one of the overloads and it didn't make a difference. Still getting:

 

```

'865.449708=== 2:<<FormOrAbandon::openFromModelPath [C:\Users\bstastny\AppData\Local\Launcher\Revit\SLN4A-PIM.rvt]
' 0:< ModelPath Created: Is server path = True, Region = "GLOBAL", Central server = "", Path = "CLD:\\GLOBAL\{00000000-0000-0000-0000-000000000000}Project-SLN4-A\{00000000-0000-0000-0000-000000000000}SLN4A-PIM.rvt"
' 2:< ::3027:: Delta VM: Avail -35 -> 134201863 MB, Used 10179 MB; RAM: Avail +6 -> 221919 MB, Used -8 -> 10190 MB
' 2:< GUI Resource Usage GDI: Avail 9827, Used 173, User: Used 163
' 2:< API_ERROR { System.ArgumentNullException exception(Value cannot be null.
'Parameter name: key) was thrown from a handler of Autodesk.Revit.Proxy.DB.Events.DocumentOpenedEventArgsProxy event. The API event handler was registered by application FormIt Conversion (eccb03c4-b3c3-4c39-868e-5d65d9ce20bd). Changes made by this handler are going to be discarded. }
' 1:< ::3027:: Delta VM: Avail +15 -> 134201879 MB, Used 10179 MB; RAM: Avail 221919 MB, Used 10190 MB
' 1:< GUI Resource Usage GDI: Avail 9827, Used 173, User: Used 163
'E 06-Nov-2022 17:56:11.826; 1:<

```

 

I changed the API call to:

 

```

 

OpenOptions options = new OpenOptions();

// Using reflection to set IgnoreExtensibleStorageSchemaConflict because it doesn't exist in
// Revit 2021 APIs.
PropertyInfo propertyInfo = options.GetType().GetProperty("IgnoreExtensibleStorageSchemaConflict");
if (propertyInfo != null) {
propertyInfo.SetValue(options, true);
}

options.OpenForeignOption = OpenForeignOption.Open;
options.DetachFromCentralOption = DetachFromCentralOption.DoNotDetach;
options.Audit = false;
options.AllowOpeningLocalByWrongUser = true;

ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(job.fileLocation);

var uidoc = uiapp.OpenAndActivateDocument(modelPath, options, false);

```

 

Maybe someone from FormIt team can shed some light on this issue?

 

Also, we are running into this issue only for a handful of models. Overall it works fine.

 

Is there a way to remove FormIt dependencies from Revit?  

0 Likes
Message 6 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @ebarMLN7G ,

 

I have raised your issue to the Revit Engineering team and asked for their suggestions.

 

I will come back to you as soon as I receive a response from them

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @ebarMLN7G ,

 

I received the below response from the Engineering team.


For developers needing to update or query the document and activate it too, I'd recommend using OpenDocumentFile(). This will open and fully initialize the document. You can now query/update the document and then call OpenAndActivateDocument(). Since the document is already opened, this call will merely activate the document. For example, the following code should work.

Dim doc = Me.Application.Application. OpenDocumentFile("C:\Path\To\Project1.rvt")
Dim sample As New SearchForWalls(doc)
sample.Run()
Me.Application.OpenAndActivateDocument("C:\Path\To\Project1.rvt")


Could you please try this suggestion and let me know?


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 8 of 8

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @ebarMLN7G ,

The Engineering team analyzed your issue.

 

The Engineering team said that you were using the wrong converter to get the model path in this case.

ModelPathUtils.ConvertUserVisiblePathToModelPath(job.fileLocation); 

ConvertUserVisiblePathToModelPath is used to convert a path to a Revit Server path, sorry, too many types about model path.

 

See

https://www.revitapidocs.com/2020/0776a818-f032-a332-ac59-962953d8493a.htm 

 

The User need not use it if it is not a Revit Server path, that is why it reports
Path = "CLD:\\GLOBAL\{00000000-0000-0000-0000-000000000000}Project-UNO1-A\{00000000-0000-0000-0000-000000000000}UNO1A-PIM.rvt"

 

For a simple file path, you need to construct a FilePath for it based on Modelpath.

You need to use something like the below code

var filepath = new FilePath(@"C:\Users\ebar\AppData\Local\Launcher\Revit\UNO1A-PIM.rvt");
var uidoc = uiapp.OpenAndActivateDocument(filepath, options, false);

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes