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.
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.
Don Ireland
Engineering Design Technician
Solved! Go to Solution.
Solved by doni49. Go to Solution.
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
Thanks but this still gives errors.
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
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,
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
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
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