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

Getting element coordiantes on sheet

Message 1 of 28
6614 Views, 27 Replies

Getting element coordiantes on sheet

Hey all,

I am trying to get coordinates of objects on a sheet, as oppose to coordinates of the element in the model.


I am generating XPS, then PNG files of the viewsheet at 150 pixels per inch. So that is my scale. From what I understand according to this post the units are in feet, however that does not seem to add up for me. Because I can see there is both a translation and scale transformation for the elements locations to align with the coordiantes from get_BoundingBox.


This is the sum of what coordinates I am executing:

var bounding = element.get_BoundingBox(viewSheet);
File.AppendAllText(path, $"{element.Name}, {group.Key}, {bounding?.Max.X}, {bounding?.Max.Y}, {bounding?.Min.X}, {bounding?.Min.Y}\n");

Where viewSheet is a ViewSheet  object.


I tried looking at viewport.get_BoundingBox(viewSheet);. But that seems to give me numbers that are too small in relation to the sift need for the elements to the right location on the sheet.

How would I get the exact location on a XPS/PDF sheet of an element?


Message 21 of 28

@RPTHOMAS108  Thanks for the reply.

Actually I'm tackling the cases one by one as they appear now. But for the scope box I don't find any clue, it has no Transform property.

Let me know please if you figure out something.

Let it work like a charm.

Mustafa Salaheldin


Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 22 of 28

Hello @Mustafa.Salaheldin 


I've not been able to recreate the problem with views set to scope boxes do you have an example of one? It may be some other factor of the view and not the scope box itself.


Below is from rac_advanced_sample_project. I set one of the plan views to diagonally orientated scope box with circular rotation grip at top right then inverted at bottom left. Both of these cases seem fine but I've not tested beyond that.



Message 23 of 28

Hello @RPTHOMAS108 


Actually you have flawlessly reporouced the issue 😁. When using the code you get the correct Top-Right and Bottom-Left coordinates of the bounding boxes of the doors in the sheet after applying the scope box to their containing view, but if you wanted to draw a rectangular around them you will figure out that the Top-Left and the Bottom-Right points are not coming in place. That is, we need to apply the rotation of the scope box to each Door bounding box to calculate the proper coordinates of the the other rectangle vertcies.



Note in my image the tr, bl points are in the exact place (as you already reproduced), but when it comes to the tl, br points we need to apply some transform to set them properly.

What I miss here is how to get the angle of ScopeBox rotation 😉

Let it work like a charm.

Mustafa Salaheldin


Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 24 of 28

Hello @Mustafa.Salaheldin 


I think you have just wrongly assumed the other two points of the bounding box i.e. two points represent more than one unique rectangle. If you get all four points of the bounding box corners on plan without transformation and then transform them you can draw lines between them as below. I think what confused me when I looked at this originally was the double door families. Note however that in the case of the sample file all doors were parallel with the internal coordinate system. If your door instances were rotated (hosted on a non vertical or horizontal directional wall) the bounding box would still be orientated to the internal system not rotated with the door. So that aspect may add a layer of confusion, you would have to orientate the bounding box using the door instance transform first. This may not be possible actually since original two points circumscribe door with a box parallel to internal system, so when rotated this would be meaningless. In such a circumstance you likely need to build your own bounding box within the new orientation by looking at max/mins you get for the geometry in the new system.


You can't get the rotation of a scope box but if you set a view to one then you can compare 1,0,0 to the right direction of the view to get scope box rotation. This should not be required here because the view right direction is used so transform should already incorporate it. Useful to know however that the orientation of a scope box can be found this way (using one of those transaction rollback workflows). The alternative may be to interrogate the geometry of the scope box to find direction of lines around the scope box bounding box centre (for the top or bottom rectangle of the cube). Although you likely couldn't get a full roation between 0 and 2Pi for this due to symmetry. Depends on how geometry of cube is constructed in terms of line directions there may be some non symmetrical patterm of this (looking at all 12 lines etc.).












Dim Dr As Element = Doors(DRi)
Dim BB As BoundingBoxXYZ = Dr.BoundingBox(V)
Dim BL As New XYZ(BB.Min.X, BB.Min.Y, 0)
Dim BR As New XYZ(BB.Max.X, BB.Min.Y, 0)
Dim TL As New XYZ(BB.Min.X, BB.Max.Y, 0)
Dim TR As New XYZ(BB.Max.X, BB.Max.Y, 0)
BL = T.Inverse.OfPoint(BL).Multiply(1 / Scale) + Offset
BR = T.Inverse.OfPoint(BR).Multiply(1 / Scale) + Offset
TL = T.Inverse.OfPoint(TL).Multiply(1 / Scale) + Offset
TR = T.Inverse.OfPoint(TR).Multiply(1 / Scale) + Offset

Dim LN_B As Line = Line.CreateBound(BL, BR)
Dim LN_R As Line = Line.CreateBound(BR, TR)
Dim LN_T As Line = Line.CreateBound(TR, TL)
Dim LN_L As Line = Line.CreateBound(TL, BL)

Doc.Create.NewDetailCurve(AcView, LN_B)
Doc.Create.NewDetailCurve(AcView, LN_R)
Doc.Create.NewDetailCurve(AcView, LN_T)
Doc.Create.NewDetailCurve(AcView, LN_L)








Message 25 of 28


Thanks a lot. I already figured out that the BoundingBox will be always aligned to the cardinal axes (link). So I had to calculate tl, br points from the max and min then apply the transform (exactly like you explained in your answer).


I thought there will be a way to directly get the rotation angle. But anyway, thanks mate 👌

Let it work like a charm.

Mustafa Salaheldin


Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 26 of 28
in reply to: Anonymous

So I found when it breaks.
It happens when wither ViewDirection or UpDirection is some linear combination. The rule catches the issues:



if ( (0 == v.ViewDirection.X || v.ViewDirection.X == 1) && (0 == v.ViewDirection.Y || v.ViewDirection.Y == 1) && (0 == v.ViewDirection.Z || v.ViewDirection.Z == 1))


And then the same for UpDirection 


if ( (0 == v.UpDirection.X || v.UpDirection.X == 1) && (0 == v.ViewDirection.Y || v.UpDirection.Y == 1) && (0 == v.UpDirection.Z || v.UpDirection.Z == 1))



However this is just a workaround not to get false positives and omit wrong locations. It means there are two transformations missing to calculate where the elements are on the sheet.
If anyone knows where they should go and how to incorporate them in to class.txt in this comment with the original solution. It would be helpful for me, and also @Mustafa.Salaheldin also had issues with this.

Message 27 of 28
in reply to: Anonymous

Perhaps one of those cases as a concrete example would be easier to follow in terms of what is perhaps missing?


Since vectors are normalised where ViewDirection.X = 0, ViewDirection.Y must be 1 etc., so there is some scope to simplify conditions perhaps?


The second condition has a mixture of ViewDirection and UpDirection, is this intentional?

Message 28 of 28
in reply to: RPTHOMAS108

The second condition should be the same as the first for UpDirection. Its a typo.


I think the issue that it only works if they are unity vectors. As in there in the value 1 in one of the axis.


v=(1,0,0), v=(0,1,0) or v=(0,0,1)

Otherwise is a more complicated projection and fails.

I will try and look for cases where it still works as a counter example, but no luck yet. I would like to my files but they are under copyright and are a few hundred megabytes so I have no simple example.

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

Post to forums  

Autodesk Customer Advisory Groups

Rail Community