OpenAndActivateDocument exits macro

OpenAndActivateDocument exits macro

LukeDavenport
Collaborator Collaborator
602 Views
4 Replies
Message 1 of 5

OpenAndActivateDocument exits macro

LukeDavenport
Collaborator
Collaborator

 

Well I thought the OpenAndActivateDocument method should be simple, but I am getting an unexpected exit when running a Macro. Simple reproducible example shown below - what am I doing wrong? The code exits (without an error!) straight after the document has been opened and activated, and doesn't continue to subsequent code.....

 

Help please!

 

Public Sub TestOpenActivate()
    
        Dim App As Autodesk.Revit.ApplicationServices.Application = Me.Application
        Dim UIApp As UIApplication = New UIApplication(Me.Application)
        
        ' Open and activate document 
        Dim WorkingDocUI As UIDocument = UIApp.OpenAndActivateDocument("C:\Temp\TestProject.rvt")
        ' DOCUMENT IS SUCCESSFULLY OPENED AND ACTIVATED, BUT THE CODE EXITS UNEXPECTEDLY HERE.....
        
        ' Do some other stuff here...
         Dim NewProjFilePath As String = App.DefaultProjectTemplate
        Dim WorkingDoc As Document = App.NewProjectDocument(NewProjFilePath)
    
End Sub

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

LukeDavenport
Collaborator
Collaborator

 

Really appreciate help anyone can offer - pretty sure I'm doing something simple and stupid.

 

I'm using Revit 2017 SP2

 

Many thanks in advance

Luke

0 Likes
Message 3 of 5

Charles.Piro
Advisor
Advisor

Hi,

 

When you create your Macro, are you in Application or in Project ?

For open and Active an other Document, your Macro must be create in Application :

 

public void TestOpenAndActiveDoc()
{
			UIApplication uiapp = ActiveUIDocument.Application;
			UIDocument _uidoc = uiapp.OpenAndActivateDocument(@"C:\Temp\Projet1.rvt");
			Document doc = _uidoc.Document;
}

Smiley Wink

 



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes
Message 4 of 5

LukeDavenport
Collaborator
Collaborator

 

Hi Charles, thanks for the reply!

 

Yes I am using an Application macro. 

 

I get the same issue with your code. However on further investigation it seems that it is an issue with SharpDevelop debugging specifically, as the code runs fine when 'running' normally.

 

Can you try something for me? When I run this simple C# macro below - the project is activated successfully, but then the debugger skips step through for all the subsequent lines of code. Do you get the same behaviour?

 

Many thanks for your help.

Luke

 

public void TestOpenAndActiveDoc()
{
    UIApplication uiapp = ActiveUIDocument.Application;

    // Open and activate document 
    UIDocument WorkingDocUI = uiapp.OpenAndActivateDocument(@"C:\StartProject.rvt");
    // DOCUMENT IS SUCCESSFULLY OPENED AND ACTIVATED, BUT THE DEBUGGER DOES NOT ALLOW STEP THROUGH FROM HERE ONWARDS

    // Do some other stuff here...
    string Dummy = "";

    TaskDialog.Show("ABC""Finished");

}

0 Likes
Message 5 of 5

Anonymous
Not applicable

 

There does seem to be a genuine problem with using OpenAndActivateDocument method in the SharpDevelop debugger. Can anyone help on this, or is everyone else using Visual Studio for debugging their Revit code?

 

Thanks,

Luke

0 Likes