Project Position

Project Position

Project position is an object that represents a geographical offset and rotation. It is usually used by the ProjectLocation object to get and set geographical information. The following figure shows the results after changing the ProjectLocation geographical rotation and the coordinates for the same point. However, you cannot see the result of changing the ProjectLocation geographical offset directly.

Figure 125: Point coordinates

Note: East indicates that the Location is rotated counterclockwise; West indicates that the location is rotated clockwise. If the Angle value is between 180 and 360 degrees, Revit transforms it automatically. For example, if you select East and type 200 degrees for Angle, Revit transforms it to West 160 degrees.

Figure 126: Geographical offset and rotation sketch map

The following sample code illustrates how to retrieve the ProjectLocation object.

Code Region 21-1: Retrieving the ProjectLocation object

public void ShowActiveProjectLocationUsage(Autodesk.Revit.DB.Document document)
{
        // Get the project location handle 
        ProjectLocation projectLocation = document.ActiveProjectLocation;

        // Show the information of current project location
        XYZ origin = new XYZ(0, 0, 0);
        ProjectPosition position = projectLocation.get_ProjectPosition(origin);
        if (null == position)
        {
                throw new Exception("No project position in origin point.");
        }

        // Format the prompt string to show the message.
        String prompt = "Current project location information:\n";
        prompt += "\n\t" + "Origin point position:";
        prompt += "\n\t\t" + "Angle: " + position.Angle;
        prompt += "\n\t\t" + "East to West offset: " + position.EastWest;
        prompt += "\n\t\t" + "Elevation: " + position.Elevation;
        prompt += "\n\t\t" + "North to South offset: " + position.NorthSouth;

        // Angles are in radians when coming from Revit API, so we 
        // convert to degrees for display
        const double angleRatio = Math.PI / 180;        // angle conversion factor

        SiteLocation site = projectLocation.SiteLocation;
        prompt += "\n\t" + "Site location:";
        prompt += "\n\t\t" + "Latitude: " + site.Latitude / angleRatio + "¡ã";
        prompt += "\n\t\t" + "Longitude: " + site.Longitude / angleRatio + "¡ã";
        prompt += "\n\t\t" + "TimeZone: " + site.TimeZone;

        // Give the user some information
        TaskDialog.Show("Revit", prompt);
}
Note: There is only one active project location at a time. To see the result after changing the ProjectLocation geographical offset and rotation, change the Orientation property from Project North to True North in the plan view Properties pane.

Figure 128: Project is rotated 30 degrees from Project North to True North

Figure 129: Project location information

Creating and Deleting Project Locations

Create new project locations by duplicating an existing project location using the Duplicate() method. The following code sample illustrates how to create a new project location using the Duplicate() method.

Code Region 21-2: Creating a project location

public ProjectLocation DuplicateLocation(Autodesk.Revit.DB.Document document, string newName)
{
        ProjectLocation currentLocation = document.ActiveProjectLocation;
        ProjectLocationSet locations = document.ProjectLocations;
        foreach (ProjectLocation projectLocation in locations)
        {
                if (projectLocation.Name == newName)
                {
                        throw new Exception("The name is same as a project location's name, please change one.");
                }
        }
        return currentLocation.Duplicate(newName);
}

The following code sample illustrates how to delete an existing project location from the current project.

Code Region 21-3: Deleting a project location

public void DeleteLocation(Autodesk.Revit.DB.Document document)
{
    ProjectLocation currentLocation = document.ActiveProjectLocation;
    //There must be at least one project location in the project.
    ProjectLocationSet locations = document.ProjectLocations;
    if (1 == locations.Size)
    {
        return;
    }

    string name = "location";
    if (name != currentLocation.Name)
    {
        foreach (ProjectLocation projectLocation in locations)
        {
            if (projectLocation.Name == name)
            {
                ICollection<Autodesk.Revit.DB.ElementId> elemSet = document.Delete(projectLocation.Id);
                if (elemSet.Count > 0)
                {
                    TaskDialog.Show("Revit","Project Location Deleted!");
                }
            }
        }
    }
}
Note: The following rules apply to deleting a project location:
  • The active project location cannot be deleted because there must be at least one project location in the project.
  • You cannot delete the project location if the ProjectLocationSet class instance is read-only.