Get name of active document file?

Get name of active document file?

doni49
Mentor Mentor
20,019 Views
6 Replies
Message 1 of 7

Get name of active document file?

doni49
Mentor
Mentor
Get the handle of current document. Autodesk.Revit.DB.Document document = application.ActiveUIDocument.Document;

 

I'm trying to get the name of the active document. I'm looking at the API developer's guide and at the bottom of the page at the following link, there is an example involving something similar.

 

[url=http://help.autodesk.com/view/RVT/2014/ENU/?guid=GUID-5282B7DB-E7A7-465B-A925-53BBBC3CC8D7]Help[/url...

 

Following is a snippet from that example. In my example, I'm not passing the application variable. The image shows a screenshot of what I see in VS2010 -- I don't see ActiveDocument as a child of UIApplication. 

 

 

 RevitFileName (1).pngRevitFileName.png



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Accepted solutions (1)
20,020 Views
6 Replies
Replies (6)
Message 2 of 7

jeremytammik
Autodesk
Autodesk

Dear Don,

 

You can navigate to the active document name from the command data argument provided to the Execute method like this:

 

  UIApplication uiapp = commandData.Application;
  UIDocument uidoc = uiapp.ActiveUIDocument;
  Document doc = uidoc.Document;
  string name = doc.Title;
  string path = doc.PathName;

 

Please note that the title is not set on an unsaved document.

 

Best regards,

 

Jeremy



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

Message 3 of 7

doni49
Mentor
Mentor

Thanks but this still gives errors.

 

RevitFileName2.png

 

Here's what I have at the top (for "using").

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 4 of 7

jeremytammik
Autodesk
Autodesk

Please work through the getting started material:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#2

 

You have not defined an external command.

 

Every external command has an Execute method.

 

Have fun!

 

Cheers,



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

0 Likes
Message 5 of 7

doni49
Mentor
Mentor

I think I have done that.  I was just showing the portion of code presenting the error.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;


namespace RevitFilenameToParam
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Automatic)]
    public class Class1 : IExternalCommand
    {
        // Get the handle of current document.
        UIApplication uiapp = commandData.Application;
        UIDocument uidoc = uiapp.ActiveUIDocument;
        Document doc = uidoc.Document;
        string name = doc.Title;
        string path = doc.PathName;
        //Autodesk.Revit.DB.Document document = UIApplication.

        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
{
TaskDialog.Show("Revit", "Hello World");
return Autodesk.Revit.UI.Result.Succeeded;
}
    }
}

 



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.

0 Likes
Message 6 of 7

jeremytammik
Autodesk
Autodesk

No you have not.

 

You have defined a class derived from the IExternalCommand interface.

 

You have however not defined its Execute method.

 

Please work through the getting started material to see how to implement the external command interface.

 

You can also use a wizard to do the job:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.20

 

Please do not use the wizard before working through the process manually to understand it well.

 

Thank you.

 

Cheers, 

 

Jeremy

 



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

0 Likes
Message 7 of 7

doni49
Mentor
Mentor
Accepted solution

Ok thanks.  I found out that I DID have the external command in the code -- but it was BELOW the code that I was using to get the file name.

 

I rearranged the code and got it working now.



Don Ireland
Engineering Design Technician




If a reply solves your issue, please remember to click on "Accept as Solution". This will help other users looking to solve a similar issue. Thank you.


Please do not send a PM asking for assistance. That's what the forums are for. This allows everyone to benefit from the question asked and the answers given.