How to load Revit file in API using C#?

How to load Revit file in API using C#?

Anonymous
4,273 Views
7 Replies
Message 1 of 8

How to load Revit file in API using C#?

Anonymous
Not applicable

I want to load the *.api file in C# code. I am trying to export the images from Revit file for specific views in the c# application. The issue is to get the ExternalCommandData from the revit (*.rvt) file.

 

public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
   ref string message, ElementSet elements)
    {
      UIApplication uiapp = revit.Application;
    }

I want to browse *.rvt file and call above method from the Windows form.

 

Please help asap.

Thank You

0 Likes
4,274 Views
7 Replies
Replies (7)
Message 2 of 8

jeremytammik
Autodesk
Autodesk

Dear Pravin,

 

Thank you for your query.

 

Calling directly into the Revit API from an external context is, was and always has been illegal.

 

The Revit API cannot ever be used except within a valid Revit API context.

 

Such a context is provided exclusively by Revit call-back methods.

 

You need to subscribe to a Revit event, such as an external command Execute method.

 

Within the event handler, the Revit API can be used.

 

You can also use the Revit API to set up an external event that can be raised from a non-Revit-API context, such as your standalone external application.

 

This is demonstrated by the ModelessDialog/ModelessForm_ExternalEvent SDK sample.

 

This question has been answered and discussed in depth numerous times in the past, both in the Revit API discussion forum and by The Building Coder.

 

Many examples and further explanations are provided in The Building Code topic group on Idling and External Events for Modeless Access and Driving Revit from Outside:

 

 

Here are some of the Revit API forum discussion threads addressing similar issues:

 

 

I hope this helps.

 

Best regards,

 

Jeremy



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

0 Likes
Message 3 of 8

Anonymous
Not applicable

Hi ,
Let me explai what I am trying to do.
I have houses that have been built with different materials. So for eg. Same house can have a double window or a single window, multiple types of floorings etc.
Now the client wants to have the images of every view with the materials selected by him.
1. So some how, the inputs I will have is the materials selected.
2. Based on the materials/options selected, i want to take images of the views (the front, back, side and top)
3. Export the images in a pdf and email it to the client.


Now the above happens over a website. So the options selected for the house is stored somewhere on the DB and using those selections i want to get images from revit.

I want this as a automation process will work automatically from the c#.

Is this possible and how do I approach this problem.

Thanks.

0 Likes
Message 4 of 8

jeremytammik
Autodesk
Autodesk

Thank you for your clarification.

 

My answer remains unchanged.

 

It covers all your needs.

 

I wish you lots of fun and success exploring and implementing your add-in!

 

Best regards,

 

Jeremy



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

0 Likes
Message 5 of 8

Anonymous
Not applicable

Hi,

I will create a plugin for this, but can we use this plugins for the REVIT Server?

0 Likes
Message 6 of 8

jeremytammik
Autodesk
Autodesk

If all you want to do is export images from the RVT or RFA file, your needs may already be completely covered by Forge.

 

For full details on how and why, please refer to my blog post on External Access to the Revit API.

 

Cheers,

 

Jeremy



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

0 Likes
Message 7 of 8

ashraf_salim88
Community Visitor
Community Visitor

Dears 

I have question may be out of scope but i want to understand more

I have Rvt file and I need to read it and convert this to GIS format

i have devep api this code 

[HttpPost("upload")]
public async Task<IActionResult> UploadRvt(IFormFile file)
{

string bucket = await CreateBucket();
string bucketKey = bucket.ToString();
TwoLeggedApi oauth = new TwoLeggedApi();
dynamic credential = await oauth.AuthenticateAsync(
clientId, clientSecret,
"client_credentials",
new[] { Scope.DataRead, Scope.DataWrite });

ObjectsApi objectsApi = new ObjectsApi();
using (var stream = file.OpenReadStream())
{
var response = await objectsApi.UploadObjectAsync(bucketKey,
file.FileName,
(int?)file.Length, stream,
"application/octet-stream",
credential.access_token);
return Ok(response.objectId);
}
}

but is not working 

 

0 Likes
Message 8 of 8

jeremy_tammik
Autodesk
Autodesk

I see that you are uploading the file to a bucket and using OAuth authentification:

   

  

That seems to indicate that you wish to process your RVT model in the cloud, e.g., using APS. In that case, unfortunately, this is not the best place to ask such a question. Please note that this discussion forum is dedicated to programming desktop Revit using the desktop Revit API. For all APS-related questions, you should ask through the dedicated APS help channels:

    

  

I hope this clarifies. Thank you for your cooperation and understanding.

   

Best regards,

  

Jeremy

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes