Can I tell program to wait?.... (closing and reopening document problem)

Can I tell program to wait?.... (closing and reopening document problem)

Anonymous
Not applicable
1,865 Views
6 Replies
Message 1 of 7

Can I tell program to wait?.... (closing and reopening document problem)

Anonymous
Not applicable

Hi, 

I am not sure if I should post this on this forum as it might more a C# specific problem.

 

I am Closing and re-opening a file in the same program and this causing revit to have an unrecoverable error.

Is there any way for me to wait a couple of seconds before reopening it?

 

I am trying to avoid using threads because its my achillees heal in programming. So if there is any other options or advice I would love to hear them.

 

If it helps I am using the building coder's program here as a basis 

http://thebuildingcoder.typepad.com/blog/2012/12/closing-the-active-document.html
Instead i am opening the placeholder, closing the main project and then opening the main project and closing the placeholder  

 

Thank you in advance,

Jack

            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            string filename = "_placeholder_.rvt";
            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string myPath = Path.Combine(docPath, filename);

            string userPath = doc.PathName;
            
	        m_CloseHelper = new UiCloseHelper(uiapp,myPath);
	        m_CloseHelper.CloseAndSave(uidoc);

            TaskDialog.Show("next", "Now lets re-Open the file");
            //********************crashes here***********************//           
            m_CloseHelper = new UiCloseHelper(uiapp, userPath);
            m_CloseHelper.CloseAndSave(uidoc);

            return Result.Succeeded;
0 Likes
Accepted solutions (1)
1,866 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

I believe the DocumentClosed  event was what I needed.

0 Likes
Message 3 of 7

jeremytammik
Autodesk
Autodesk
Accepted solution

I believe so too  🙂

 

If you really want to wait for a specific amount of time, you can use the .NET and Windows API function Thread.Sleep to do so.

 

There are some samples on using it on The Building Coder.

 

Asking for notificfation from Revit when the document really has closed is a much better approach, though.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 7

Anonymous
Not applicable

Hi Jeremy

I have handled the event but the program still seems to be crashing. I can't figure out what is happening and I have been stuck on this for a few days.

I hope it is not down to poor coding, I am still a junior developer.

 

Here is my code if anyone wants to take a look at it, I don't want to hassle people though.

 

Thank you, 

Jack

0 Likes
Message 5 of 7

jeremytammik
Autodesk
Autodesk

Dear Jack,

 

I think that the following two lines will not work as you are hoping:

 

            while ((closed == false) || (saved == false)){
            }

 

The will hog all the execution.

 

The Revit API does not support multi-threading.

 

I think you will have to re-think.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 7

Anonymous
Not applicable

Capture.PNG

 

This is my original code, seems pretty straight forward to me but still causes and unrecoverable error 😞

0 Likes
Message 7 of 7

Anonymous
Not applicable

In code above i was handling the document.closed event with a piece of code that closed a document. dumb mistake on my part, sorry

0 Likes