Vector referred to screen reference system

Dear community,

happy new year! Wish all the best for an incredible 2024!

I’m searching for a rule for the correct placement of 3D text alongside the edges of a polyline.

In the cases that I am interested in, I would like my texts to be positioned in such a way that the X axis of the 3D text is parallel to the edge of the polyline but this sometimes generates notable situations that I am forced to discriminate, such as those in the images below:



I always have to deal with open polylines (therefore no face will be created) sometimes built clockwise, sometimes built anti-clockwise. As you can see, the 3D texts on sides 6 and 7 cannot be read correctly because they are oriented in a way that does not facilitate reading.
Same thing happens with the 3D texts on sides 4, 5, 6 and 7 of the second image.

This is why I ask you: is it possible to evaluate the components of a vector with respect to an absolute reference system that is not that of the 3D model?

For example, is it possible to generate vectors evaluated with respect to the screen coordinate systems?

If I were able to evaluate the components of the vectors parallel to each edge of the polylines that you see in the images above, with respect to an absolute reference system (even 2D, like the screen reference system), I would be able to discriminate the cases in which the texts are oriented in an unwanted way.

In particular: all cases in which the components of the vectors (referred to the absolute 2D reference system with the x axis in red and the y axis in green, in the image below) have negative x and positive y or both negative components, in this cases I need to reoriented them correctly:


I cannot use the reference system of the model nor the one of a group/component because it always varies based on conditions that I cannot control.

I think that it will be possible also to evaluate the difference between the vertices position with respect to the screen coordinates system: if the difference between the x coordinate of the next point and the previous point of the polyline is negative and the difference between the y coordinate of the next point and the previous point of the polyline is also negative or positive, then I will be able to act and correct the position of the 3D text. Does anyone have experience with this way of working? Problems that can arise?

Thank you

You can get the screen coords of start and end ponint and caluculate your own vector.
Does it help?

By the way, do you need a 3D text? If not you can use overlay text. Something like this…

The API does not really (yet) fully expose a screen coordinate system.

(a) The screen coordinates are really 2D viewport coordinates, meaning that the 2D origin is at the top left of the modeling viewport, not the top left of the display screen. The width and height max coordinates depend upon how the user has setup trays and toolbars.

(b) So the Y axis for the 2D screen space points downward toward your desktop (Ie, the bottom of the display.)

(c) The units for 2D screen space are in pixels (either logical or physical depending upon which API method is used.) But the units for 3D vectors in model space are always in inches for the SketchUp API.

Actually, the model axes cannot be changed. The Ruby API predefines X_AXIS, Y_AXIS and X_AXIS.

Do not confound the drawing (user tool) axes with the model axes (the latter never changes.)

We ( @slbaumgartner and I) faced a similar situation when creating a second version of Angular Dimension (on SketchUcation extension store). Steve solved it, so that the text is angled in the view in which it is placed with its bottom towards the bottom of the screen, and parallel or normal to the angle bisector of the dimensioned angle.

Have a look at the code for that (it’s not encrypted) to see if it helps.

It is NOT independent of the view, though. If you orbit, the text doesn’t reorient in 3D space.

Consider using the camera’s orientation to align 3D text along polyline edges in SketchUp. Flip the text direction if its ‘up’ orientation is opposite to the camera’s ‘up’. This ensures readability from the user’s perspective, regardless of how the polyline is drawn :smiley:


Thank you all Guys!!

@rtches it could be a chance to test! Actually I’m developing an extension that I want to run also on SK2020 and overlay method is not available!

@DanRathbun thank you for your clarification, it helps a lot as always!

@john_mcclenahan I will have a look to your extension, thank you indeed!

@curic4su you got it! I want to do what you have done in the video!! Just a few things: I don’t need to generate the 3D Text on mouse move while genereting the polyline, I want to generate the polyline and the 3D Text in the same time, just as in the video below:

Do you have some snipped code to refer at, just to replicate it? Actually I’m aligning the 3D Text group to the edges in a way that the X axis of the 3D Text is parallel to the edge and the Y axis is perpendicular to it (Z is created as a cross product), following the suggestion of @slbaumgartner to use a matrix transformation (you can refer to Align Group based on vectors topic I recently open):

for i in 0...@vettore.length
  @grouptext = disgn.entities.add_group = txt_display[i].to_s + " 3D Text"
  @grouptext.entities.add_3d_text(txt_display[i].to_s, TextAlignCenter, "Arial", false, false, 2.0, 0.0, 0.0, true, 0.0)

  @textx = txpoint[i].x
  @texty = txpoint[i].y
  @textz = txpoint[i].z
  @new_x = @vettore[i]
  @new_y = @v_off[i]
  @new_z = @vettore[i]*@v_off[i]



Where posiziona_3dText recall the transformation matrix:

  def posiziona_3dText
    trans_array = []
    trans_array[0] = @new_x[0]
    trans_array[1] = @new_x[1]
    trans_array[2] = @new_x[2]
    trans_array[3] = 0.0
    trans_array[4] = @new_y[0]
    trans_array[5] = @new_y[1]
    trans_array[6] = @new_y[2]
    trans_array[7] = 0.0
    trans_array[8] = @new_z[0]
    trans_array[9] = @new_z[1]
    trans_array[10] = @new_z[2]
    trans_array[11] = 0.0
    trans_array[12] = @textx
    trans_array[13] = @texty
    trans_array[14] = @textz
    trans_array[15] = 1.0


Again, thank you all!

Hello @curic4su! Thank you indeed for your suggestion! It is exactly what I want to do!

I evaluated the camera up as:

camera =
cam_upDir = camera.yaxis

Now, I’m wondering how you control "if “up” orientation of 3D Text is opposite to the camera’s “up”"?

I tried using samedirection method comparing camera’s “up” direction with my 3D Text’s “up” in a cycle and then flip the 3D Text if they are in the same direction:


but it works only if the two vectors are parallel.

Could you please help me?

Thank you very much!!

…maybe using dot product between the 3D Text Y axis and the camera up axis…Tomorrow I will try!!

… can also be defined via:

    trans_array = [

Thank you @DanRathbun!! Good advise! Is it more efficient in the calculation?

Yes!! It works!! Projecting the vector parallel to the edge on x and y camera axis and checking their value solved my issue!!

Thank you again @curic4su


No, but it saves you retyping the array reference and a subscript index for every new element.

1 Like