Hi all,
I have a quick question about retrieving the Project Base Point Coordinates in Meters.
Here's what I'm currently doing:
foreach (Autodesk.Revit.DB.ProjectLocation location in document.ProjectLocations)
{
Autodesk.Revit.DB.ProjectPosition projectPosition = location.GetProjectPosition(Autodesk.Revit.DB.XYZ.Zero);
double ns = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(projectPosition.NorthSouth, Autodesk.Revit.DB.UnitTypeId.Meters);
double ew = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(projectPosition.EastWest, Autodesk.Revit.DB.UnitTypeId.Meters);
double el = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(projectPosition.Elevation, Autodesk.Revit.DB.UnitTypeId.Meters);
System.Diagnostics.Debug.WriteLine(ns.ToString(System.Globalization.CultureInfo.InvariantCulture));
System.Diagnostics.Debug.WriteLine(ew.ToString(System.Globalization.CultureInfo.InvariantCulture));
System.Diagnostics.Debug.WriteLine(el.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
And this is what it prints:
5805155.0267429
3526500.91565812
0
As you can see, the coordinates are off - in the case of N/S, by more than 5 meters.
Can anyone tell me what I am doing wrong?
This is Revit 2022 btw, but version doesn't seem to make a difference (other than the fact that in 2020 and earlier the unit type was passed differently).
Thanks and regards
Aminius
Solved! Go to Solution.
Solved by RPTHOMAS108. Go to Solution.
Hi @Aminius,
There was a discussion on about how Revit converts its units. The question below might not be similar, but the idea is the same:
https://forums.autodesk.com/t5/revit-api-forum/unit-conversion-question/td-p/9840508
thanks for the input, but I didn't find that very helpful. Since I am using Revit API functionality to convert from the internal units, I shouldn't need to know what those internal units actually are, as they are an implementation detail.
The actual question is why the GUI does the conversion correctly while my code does it incorrectly (or at least with different precision). Maybe there's a setting for precision somewhere?
I can't replicate that but I think it may depend on how far your base points are away from the internal origin. These things are also a combination of survey point and project base point. The XYZ.Zero you specify is based on internal origin but your survey point may have additional offsets.
Do you have a project file to share?
Hi @Aminius,
I have had a look at your snippet and the method you are using to convert is obsolete in Revit 2022 and beyond. That said, the way you have used it is not the correct way because it takes 2 arguments i.e.
value of type Double and DisplayUnitType of type Enum. On the DisplayUnitType enums I can see the member DUT_METERS which I guess is the one you want to use according to the documentation
https://www.revitapidocs.com/2021.1/9cc2c0ea-f59f-9d76-ce19-ae7eede03bbd.htm
Hi @RPTHOMAS108,
I currently don't have a Revit project file to share because this comes from a customer and I have to ask for clearance first.
I will do that and, in the meantime, investigate for possible additional offsets on the survey point. Thanks for the suggestion, that seems worth looking into!
@moturi.magati.george: Thanks for your suggestion as well, but you are wrong. As I mentioned in my original post, I'm aware that the 2nd parameter has changed since Revit 2021 onwards (from DisplayUnitType to ForgeTypeId), but my snippet is already using the current version of the call:
https://www.revitapidocs.com/2021.1/60c6aac3-8306-c56e-b62f-b7011b9ad7b6.htm
(directly below the one you linked to)
It is indeed quite strange... The conversion of the units using the Revit API UnitUtil static class works fine. but the value of the coordinates retrieved via API is indeed different from what is shown.
I have tested the Revit sample project "rac_basic_sample_project", and I set the survey and project base points to zeros. Then I tested your snipped and returned different values. seems the display value represents something different from what the API is retrieving... quite strange.
here are the results
foreach (Autodesk.Revit.DB.ProjectLocation location in RvtApi.Doc.ProjectLocations)
{
Autodesk.Revit.DB.ProjectPosition projectPosition = location.GetProjectPosition(Autodesk.Revit.DB.XYZ.Zero);
double ns = Autodesk.Revit.DB.UnitUtils.ConvertFromInternalUnits(projectPosition.NorthSouth, Autodesk.Revit.DB.UnitTypeId.Meters);
var nsManualConvertedValue = UnitUtils.Convert(projectPosition.NorthSouth, UnitTypeId.Feet, UnitTypeId.Meters);
System.Diagnostics.Debug.WriteLine(ns.ToString(System.Globalization.CultureInfo.InvariantCulture));
System.Diagnostics.Debug.WriteLine(nsManualConvertedValue.ToString(System.Globalization.CultureInfo.InvariantCulture));
System.Diagnostics.Debug.WriteLine(projectPosition.NorthSouth.ToString(System.Globalization.CultureInfo.InvariantCulture));
}
and the results are
-3.09083686241919 // ConvertFromInternalUnit static class conversion
-3.09083686241919 // UnitUtils conversion for testing purpose
-10.1405408872021 // the actual value retrieved via API
I think there is a bit of a misconception here.
The code snippet is a way of getting the transform values not a direct way of reporting what the project base point contains. If you look at the location of the internal origin from where you've moved the base points you'll see it is 3m south of where you now have the base points. The E/W value I don't know because you have not provided it.
10ft roughly equals 3m, the grid of the building is 3m, internal origin is just north of grid B and the base points that you have set to zero are just north of grid A.
By inputting XYZ.Zero you are getting the location of the internal origin relative to the basepoint if the basepoint itself is set to 0,0 (wherever it is).
yep, you are right about that... I have set the internal point to visible and did some tests to check the points and API values... seems all fine. I did notice it is mentioned already over the API documentation and i missed the word "offset" and not "actual"
NorthSouth Property
"The offset of the project location from the site location in the north/south direction. Measured in decimal feet."
https://www.revitapidocs.com/2015/f0d0e79a-c1de-9cd6-82a8-664fc76e7e41.htm
Thanks @RPTHOMAS108
I can confirm that your suspicion was right, the issue was me using XYZ.zero as a reference point rather than the Project Base Point, which happened to be not in the origin of the coordinate system.
Such an easy thing, really, it just did not occur to me... as the difference was rather small I jumped to the conclusion of it being related to precision.
Thanks again to everyone for your input!
Regards
Aminius
Can't find what you're looking for? Ask the community or share your knowledge.