How to open an Autodesk document file via Revit Api ?

How to open an Autodesk document file via Revit Api ?

Hans_Dwe
Enthusiast Enthusiast
1,784 Views
7 Replies
Message 1 of 8

How to open an Autodesk document file via Revit Api ?

Hans_Dwe
Enthusiast
Enthusiast

Hello everyone, 

 

I would like to ask how it would be possible to open the file or multiple files from the Autodesk document in Revit via Revit API. I tried to use the OpenAndActiveDocument Method for a local file and it worked,  so I would like to ask if this method works then how to get the Cloudfile path? How to get the File Path in the AutodeskDoc? 

 

here is a sample 

"

using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.Attributes;
using System;

namespace OpenAutodeskDocFiles
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;

string filePath = @Anonymous;

try
{

UIDocument uiDoc = uiApp.OpenAndActivateDocument(filePath);


TaskDialog.Show("Document Activated", "Successfully activated: " + uiDoc.Document.Title);
}
catch (Exception ex)
{
TaskDialog.Show("Error", "Failed to open and activate document: " + filePath + "\n" + ex.Message);
return Result.Failed;
}

return Result.Succeeded;
}
}
}

 

thanks 

0 Likes
Accepted solutions (1)
1,785 Views
7 Replies
Replies (7)
Message 2 of 8

Mohamed_Arshad
Advisor
Advisor

HI @Hans_Dwe 

 

    OpenDocumentFile Method  will open the document in hidden mode, we can't able to see the documents. To see the document we need to use OpenAndActivateDocument() method.

 

Reference Code

 public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {

            UIApplication uiApp = commandData.Application;
            Application app = uiApp.Application;

            {
                string cloudPath = @" ";

                try
                {
                    ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(cloudPath);
                    OpenOptions openOptions = new OpenOptions();


                    UIDocument uiDoc = uiApp.OpenAndActivateDocument(modelPath, openOptions,false);

                    ///Opened File Document
                    Document doc = uiDoc.Document;


                    TaskDialog.Show("Document Opened", "Successfully opened: " + doc.Title);
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("Error", "Failed to open document: " + cloudPath + "\n" + ex.Message);
                    return Result.Failed;
                }
            }

            return Result.Succeeded;

        }

 

Hope this will Helps 🙂


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 8

Hans_Dwe
Enthusiast
Enthusiast
@Mohamed_Arshad thanks for the answer, this is exactly what i am looking for, but how i can obtain the AutodeskDoc file path ?
0 Likes
Message 4 of 8

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @Hans_Dwe 

   

    You can check the below post, I think it is not possible through Revit API we need to use Forge API.

https://thebuildingcoder.typepad.com/blog/2020/04/revit-2021-cloud-model-api.html#4.4 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 5 of 8

Hans_Dwe
Enthusiast
Enthusiast

Hi again, so the Path Name when i snoop the active view via LookUp Revit is not what I should look for ?

 

 

 

0 Likes
Message 6 of 8

Mohamed_Arshad
Advisor
Advisor

To Open the Cloud Model, You need to register the Forge API (Design Automation API). Kindly read the below post

 

https://thebuildingcoder.typepad.com/blog/2020/04/revit-2021-cloud-model-api.html#4.4:~:text=To%20co... 

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 7 of 8

Hans_Dwe
Enthusiast
Enthusiast

Okay, thanks i will check it out . 

Message 8 of 8

Hans_Dwe
Enthusiast
Enthusiast

yes it worked according to your suggestion, thanks a lot @Mohamed_Arshad

 

0 Likes