Import multiples SAT files into Revit with Revit API

Import multiples SAT files into Revit with Revit API

Anonymous
Not applicable
1,005 Views
5 Replies
Message 1 of 6

Import multiples SAT files into Revit with Revit API

Anonymous
Not applicable

Hello,

 

I'm trying to import with the Revit API multiples SAT files that I'have created with Dynamo into Revit. Because with Revit it is possible to import a SAT file but it's only one by one. So my goal is to use Revit API to create a Ribbon Button that select a directory and import all SAT files into the active document. 

I have successfuly created a Ribbon Button and i have tried to follow this topic : https://forums.autodesk.com/t5/revit-api-forum/import-sat-files-from-the-api/td-p/3902783

to import just one file but i can't get the active document and visual studio say that it is impossible to convert from Autodesk.Revit.UI.UIDocument to Autodesk.DB.Document.

Do you have any idee how can i succeed ?

I'm new with Revit API and c# sorry for the mistakes ...

erros.PNGscript.PNG

Thanks,

Raphaël 

0 Likes
1,006 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor

To get Document from UIDocument it is: UIDocument.Document

0 Likes
Message 3 of 6

lukaskohout
Advocate
Advocate

You have actually commented the line in your code snippet visible in posted image.


Hitting Accepted Answer is a Community Contribution from me as well as from you.
======================================================================
0 Likes
Message 4 of 6

Anonymous
Not applicable

Hello @RPTHOMAS108 , 

 

I have these two libraries : Autodesk.Revit.UI; and using Autodesk.Revit.DB.

When I write UIDocument I don't have .Document...

UIDocument.Document.PNG

Do you have any idea why ?

 

Thanks,

Raphaël

 

0 Likes
Message 5 of 6

Anonymous
Not applicable

Hello @lukaskohout ,

 

Thank you for answer. It was wanted, I commented it because it wasn't working. When I copy the exact same code as the topic i got these two erros :erros 2.PNG

Do you have an other idea ?

 

Thank you,

Raphaël

0 Likes
Message 6 of 6

lukaskohout
Advocate
Advocate

For ambiguous reference try this:

 

 

 

Autodesk.Revit.DB.Document doc

 

 

 

 But firstly I would check if you need the Autodesk.Revit.Creation reference.

 

For the second error, you have to pass the UIDocument to your class in the class constructor. In order to have working addin, you have to have iExternalCommnad od IExternalApplication passing this argument to your class. Something like this:

 

 

 public class Command : IExternalCommand
   {      
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            // NOTES: Anything can be done in this method, such as create a message box, 
            // a task dialog or fetch some information from revit and so on.
            // We mainly use the task dialog for example.

            // Get the application and document from external command data.
            if (commandData == null)
                throw new ArgumentNullException(nameof(commandData), Resources.Resource.ResourceManager.GetString("commandDataNull", CultureInfo.CreateSpecificCulture("cs-CZ")));
            UIApplication uiapp = commandData.Application;

            //Your class initialization
            UIDocument uidoc = uiapp.ActiveUIDocument;
            YourClass c = new YourClass(uidoc);                   

            return Autodesk.Revit.UI.Result.Succeeded;
        }       
    }

 

 

And the constructor can look like this:

class YourClass
{
   UIDocument uidoc;
   
   public YourClass(UIDocument uidoc)
   {
      this.uidoc = uidoc;
   }
   
   //rest of the methods in the class
}

Hitting Accepted Answer is a Community Contribution from me as well as from you.
======================================================================
0 Likes