Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get name of active document file?

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
doni49
17497 Views, 6 Replies

Get name of active document file?

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.

6 REPLIES 6
Message 2 of 7
jeremytammik
in reply to: doni49

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
in reply to: jeremytammik

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.

Message 4 of 7
jeremytammik
in reply to: doni49

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

Message 5 of 7
doni49
in reply to: jeremytammik

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.

Message 6 of 7
jeremytammik
in reply to: doni49

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

Message 7 of 7
doni49
in reply to: jeremytammik

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community