Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Getting the base point of the ActiveDocument

Anonymous

Getting the base point of the ActiveDocument

Anonymous
Not applicable

I am attempting to get the base point of the Revit document.

 

I am attempting to access the ActiveDocument property, but I am not sure what object I must instantiate (I tried instantiating the ActiveDocument object, but it's not a type, it's a property, yet I am not sure why I am getting this error then (First time working in C#):

 

1. Error (CS0120): An object reference is required for the non-static field, method, or property 'Autodesk.Revit.UI.Events.CommandEventArgs.ActiveDocument.get' (line 6
using DB = Autodesk.Revit.DB;
using UI = Autodesk.Revit.UI;
DB.Document activeDoc = Autodesk.Revit.UI.Events.CommandEventArgs.ActiveDocument;

DB.FilteredElementCollector locations = new DB.FilteredElementCollector(activeDoc).OfClass(typeof(DB.BasePoint));
foreach (var locationPoint in locations) {
  DB.BasePoint basePoint = locationPoint as DB.BasePoint;
  if (basePoint.IsShared == true) {
    //this is the survey point

    DB.Location svLoc = basePoint.Location;
    A = basePoint.get_Parameter(DB.BuiltInParameter.BASEPOINT_EASTWEST_PARAM).AsDouble();
    //projectSurvpntY = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_NORTHSOUTH_PARAM).AsDouble();
    //projectSurvpntZ = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM).AsDouble();

  }
}

 

 

Your help would be much appreciated.

 

Cross-posted here as well:

https://discourse.mcneel.com/t/c-getting-the-base-point-of-the-document/108681

0 Likes
Reply
1,020 Views
8 Replies
Replies (8)

joshua.lumley
Advocate
Advocate

Hi KV, the error message would suggest the cause is wider, not in the code you posted but rather where the code appears in the wider context. Try temporarily replacing all that code with Taskdialogue.show("Me", "Hello World"); and see if you get the same error message.

0 Likes

Anonymous
Not applicable

Thank you so much for your response. The code executes well and I get the pop-up until it gets to

DB.Document activeDoc = Autodesk.Revit.UI.Events.CommandEventArgs.ActiveDocument;

 Here are the docs for that property: https://www.revitapidocs.com/2020/c9769a52-5a67-3f36-e10c-676617376366.htm

 

 

0 Likes

Sean_Page
Collaborator
Collaborator

The argument from the method should be identified by a variable. That is the variable "args" or "e" is what you need to use to get the Document.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes

joshua.lumley
Advocate
Advocate

This is another way to get the document:

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{

Document doc = commandData.Application.ActiveUIDocument.Document;
0 Likes

Anonymous
Not applicable

Thank you for this, could you please explain where I can get the "args" argument to pass to that method? This is what you're saying, right? What I understood from your response is that I have to pass some data to the method in order to get the document?

0 Likes

Anonymous
Not applicable

Thanks so much! How would I initialize commandData?

Document doc = commandData.Application.ActiveUIDocument.Document;

 

0 Likes

Anonymous
Not applicable

I am totally shooting in the dark here....

 


@Sean_Page wrote:

The argument from the method should be identified by a variable. That is the variable "args" or "e" is what you need to use to get the Document.


Latest attempt:

       UI.Events.CommandEventArgs events = new Autodesk.Revit.UI.Events.CommandEventArgs();
       DB.Document activeDoc = new Autodesk.Revit.UI.Events.CommandEventArgs.ActiveDocument(events);

 

I do not know what I am supposed to pass into ActiveDocument()

 

1. Error (CS0143): The type 'Autodesk.Revit.UI.Events.CommandEventArgs' has no constructors defined (line 65)

2. Error (CS0118): 'Autodesk.Revit.UI.Events.CommandEventArgs.ActiveDocument' is a 'property' but is used like a 'type' (line 66)

 

0 Likes

mhannonQ65N2
Advocate
Advocate

Are you writing an external command or a macro?

 

If you are writing an external command, then you need to implement the IExternalCommand interface. The help docs likely have a tutorial on how to do so. You can also look at the SDK samples.

 

If you are writing a document macro, you can simply use the 

Document

property.

0 Likes