Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Retrieving Project Coordinates (rounding error)

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
Aminius
453 Views, 10 Replies

Retrieving Project Coordinates (rounding error)

Hi all,

 

I have a quick question about retrieving the Project Base Point Coordinates in Meters.

 

Aminius_0-1673870749968.png

 

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

10 REPLIES 10
Message 2 of 11

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 

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 3 of 11
Aminius
in reply to: Aminius

Hi @moturi.magati.george,

 

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?

 

Message 4 of 11
RPTHOMAS108
in reply to: Aminius

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?

 

 

Message 5 of 11

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

 

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 6 of 11
Aminius
in reply to: RPTHOMAS108

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)

 

 

Message 7 of 11
Moustafa_K
in reply to: Aminius

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

 

 

mostafa90_0-1673897134408.png 

 

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 8 of 11
RPTHOMAS108
in reply to: Moustafa_K

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). 

Message 9 of 11
Moustafa_K
in reply to: RPTHOMAS108

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 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 10 of 11
Aminius
in reply to: RPTHOMAS108

@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

Message 11 of 11
Moustafa_K
in reply to: Aminius

a wise man once told me, the more the merrier... I learned something new from your question 😊.

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community