Get Project Base Point Revit API 2025

Get Project Base Point Revit API 2025

Bruno_Senna
Participant Participant
1,035 Views
1 Reply
Message 1 of 2

Get Project Base Point Revit API 2025

Bruno_Senna
Participant
Participant

Hello everyone,

I am developing a plugin for Revit (version 2024/2025) and facing difficulties retrieving the absolute coordinates of the Base Point for linked models using the Revit API.

So far, I have tried multiple approaches to access this information:

  1. Used FilteredElementCollector with BuiltInCategory.OST_ProjectBasePoint and BuiltInParameter.BASEPOINT_*, but the values returned are always 0.0 or incorrect.
  2. Explored using the Transform of linked models to calculate the global coordinates, but the results did not match the expected absolute Base Point.
  3. Tried methods such as BasePoint.IsShared and other parameters, but the values retrieved were still inconsistent.
  4. Checked various suggestions from forums and the official Revit API documentation, but I couldn’t find a solution that worked for this specific need.

Goal:

The goal is to:

  • Retrieve the absolute Project Base Point for each linked model within the global context, similar to what Revit displays in the project properties.

Question: Is there a specific or less conventional approach to retrieve the Base Point of linked models using the Revit API? Am I missing a crucial configuration or detail that would allow this?

0 Likes
1,036 Views
1 Reply
Reply (1)
Message 2 of 2

jeremy_tammik
Alumni
Alumni

Dear Bruno, 

 

I grabbed your question, added a persona prompt, and fed the rest of the question unmodified into Gemini 2.0 Flash Experimental. Below is my persona prompt, followed by your original text, and Gemini's response. Can you please evaluate the response and let us know whether it solves your question? Thank you!

 

Happy New Year to you and everyone, and cheers,

 

Jeremy

 

Jeremy says: you are a bim expert, experienced revit application ewngineer and proficient .net, revit api and bim programmer. can you please help with this revit api question, maybe discussed in the revit api discussion forum, by the building coder blog, or other revit api exchanges: Get Project Base Point Revit API 2025 Hello everyone, ... <your text>.

 

Gemini responds: You're hitting a common Revit API hurdle. Getting the absolute project base point of a linked model isn't directly exposed as a simple property. The ProjectBasePoint element itself represents the base point in the host model's coordinate system. To get the linked model's base point in the host's coordinate system (which is what you need for "absolute" positioning within the host), you need to combine the linked instance's transform with the linked model's internal base point.

Here's the breakdown of the correct approach, along with explanations and common pitfalls, drawing from established Revit API best practices (like those found on The Building Coder and the Revit API forums):

C#
 
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System.Linq;

public static XYZ GetLinkedInstanceBasePoint(Document hostDoc, RevitLinkInstance linkInstance)
{
    // 1. Get the linked document.
    Document linkedDoc = linkInstance.GetLinkDocument();
    if (linkedDoc == null)
    {
        // Handle the case where the link is unloaded or invalid.
        TaskDialog.Show("Error", "Linked document is unloaded or invalid.");
        return XYZ.Zero; // Or throw an exception, depending on your needs.
    }

    // 2. Get the Project Base Point from the linked document.
    ProjectBasePoint linkedBasePoint = new FilteredElementCollector(linkedDoc)
        .OfClass(typeof(ProjectBasePoint))
        .Cast<ProjectBasePoint>()
        .FirstOrDefault();

    if (linkedBasePoint == null)
    {
        TaskDialog.Show("Error", "Could not find Project Base Point in the linked document.");
        return XYZ.Zero;
    }

    // 3. Get the linked instance's transform. This is KEY.
    Transform linkTransform = linkInstance.GetTotalTransform();

    // 4. Get the linked model's base point coordinates (relative to *its own* origin).
    XYZ linkedBasePointLocation = linkedBasePoint.GetTransform().Origin; // or linkedBasePoint.Location.Point;

    // 5. Transform the linked model's base point using the link instance's transform.
    XYZ absoluteBasePoint = linkTransform.OfPoint(linkedBasePointLocation);

    return absoluteBasePoint;
}


// Example usage within an external command:
[Transaction(TransactionMode.Manual)]
public class GetLinkedBasePointCommand : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        UIApplication uiapp = commandData.Application;
        UIDocument uidoc = uiapp.ActiveUIDocument;
        Document doc = uidoc.Document;

        // Get all Revit link instances.
        FilteredElementCollector collector = new FilteredElementCollector(doc);
        collector.OfClass(typeof(RevitLinkInstance));

        foreach (RevitLinkInstance linkInstance in collector)
        {
          XYZ absoluteBasePoint = GetLinkedInstanceBasePoint(doc, linkInstance);
          TaskDialog.Show(linkInstance.Name, $"Absolute Base Point: {absoluteBasePoint}");
        }

        return Result.Succeeded;
    }
}

Explanation and Key Improvements:

  • GetTotalTransform(): This is the correct way to get the instance transform. It accounts for all transformations applied to the linked instance (rotation, translation, mirroring). Using just Location or other methods will not give the correct result.
  • Linked Document Access: The code explicitly checks if the linked document is valid (GetLinkDocument() can return null if the link is unloaded). This prevents null reference exceptions.
  • Error Handling: Includes basic error handling with TaskDialog to inform the user if the linked document or base point cannot be found. More robust error handling might be appropriate for a production plugin.
  • Clearer Variable Names: Uses more descriptive variable names (e.g., absoluteBasePoint, linkedBasePointLocation) for better readability.
  • Simplified Base Point Retrieval: Uses LINQ's FirstOrDefault() for concise base point retrieval.
  • Complete Example: Provides a complete example of how to use the function within an external command, demonstrating how to iterate through linked instances.
  • linkedBasePoint.GetTransform().Origin or linkedBasePoint.Location.Point: both methods are correct to get the base point location.
  • No use of BuiltInParameter.BASEPOINT_*: You don't need to access the base point coordinates through parameters. It is more direct to get the location from the transform.

Why your previous attempts failed:

  • Accessing BASEPOINT_* parameters on the linked instance gives you parameters related to the linking process (shared coordinates, etc.), not the actual location of the base point within the linked model's own coordinate system.
  • Without using the GetTotalTransform(), you're not accounting for the instance's placement within the host model.

This revised approach is the standard, reliable method for obtaining the absolute base point of linked models in Revit using the API. This is the approach recommended by the Revit API experts and is consistent with the solutions provided on The Building Coder.

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes