Temporary Dimension in Tool

I’ve had some requests for displaying a dimension in my draw wall tool (wall length). This is not something I’ve done before so I am looking into it further and checking through the API for any sort of methods for this type of feature.

I can manually create the dimension line along with the arrowheads and text but I am wondering if there is a simpler way to go about this.

It doesn’t appear that there is.

Based on the lack of response I’m going to assume that there is not a method for doing this quickly and cleanly within the API. I will need to come up with my own solution.

You can use the methods in the View class to draw text and geometry to the screen.


That is kind of what I figured I would need to do. I’ve got this.

My opening move tool already has some code for drawing temporary arrows/dimensions, so I just need to recycle some code and I’ll be up and running.

I just wanted to check in first though, no point in recreating the wheel on something when there is possibly a much simpler way to do it.

With the draw_test method I’m not seeing a way to rotate the text in the options. I’m assuming this is not possible. I’m wanting to align the text parallel to the wall wireframe so that it give the impression of a typical dimension (length).

@Aerilius is the resident SU openGL draw expert…

he has some bits in github worth looking at…


Why make a “dimension” per se ?
Just use the ‘VCB’ output box to display the wall’s length as the mouse moves…
In the Tool’s onMouseMove() method, with suitable tests to use after the second [?] point is about to be picked for its ‘length’.
Assuming @ip1 and @ip2 are set up as the start and [potential] end input-points… use something like:

Sketchup::set_status_text("Wall Length", SB_VCB_LABEL)
if @ip2.valid?
  Sketchup::set_status_text(length.to_s, SB_VCB_VALUE)

Perhaps with some ‘flattening’ of the points - so perhaps use,

p2=@ip2.position; p2.z=p1.z

to ensure the ‘length’ is ‘horizontal’ ?

1 Like

I am already doing this in the VCB but the users want to have a dimension so that it resembles and acts like Chief Architect when you draw a wall.

Here is what I have so far:

Not shown is the same dimension information in the VCB.

My code is:

wallvec = @pts[1] - @pts[0]
    		if (wallvec.length > 0)
        		if @Walljust == "Front"
    				transform = Geom::Transformation.new(@pts[0], [0, 0, 1], 90.degrees)

				wallvec2 = wallvec.transform(transform)
    				wallvec2.length = @Stud_depth_draw
    				offset_start_pt = @pts[0].offset(wallvec2)
    				offset_end_pt = @pts[1].offset(wallvec2)

				view.line_width = 2
				previewcolor = "#808080"
				view.drawing_color = previewcolor
    				view.draw(GL_LINE_STRIP, @pts[0], offset_start_pt)
    				view.draw(GL_LINE_STRIP, offset_start_pt, offset_end_pt)
    				view.draw(GL_LINE_STRIP, offset_end_pt, @pts[1])

				if @Preview3d == "YES"
					hgtvec = Geom::Vector3d.new(0,0,@Wallhgt_draw)
					# hgtvec.length = @Wallhgt_draw
					pt0b = @pts[0].offset(hgtvec)
					pt1b = @pts[1].offset(hgtvec)
					pt2b = offset_start_pt.offset(hgtvec)
					pt3b = offset_end_pt.offset(hgtvec)

					view.draw(GL_LINE_STRIP, pt0b, pt1b)
    					view.draw(GL_LINE_STRIP, pt0b, pt2b)
    					view.draw(GL_LINE_STRIP, pt2b, pt3b)
					view.draw(GL_LINE_STRIP, pt3b, pt1b)

					view.draw(GL_LINE_STRIP, @pts[0], pt0b)
    					view.draw(GL_LINE_STRIP, @pts[1], pt1b)
    					view.draw(GL_LINE_STRIP, offset_start_pt, pt2b)
					view.draw(GL_LINE_STRIP, offset_end_pt, pt3b)


				# Temp Dimension

				vector_ext = wallvec2.clone.reverse!	
				vector_ext.length = 18.0

				vector_ext_off = wallvec2.clone.reverse!	
				vector_ext_off.length = 1.5

				vector_dim = wallvec2.clone.reverse!	
				vector_dim.length = 12.0

				ext_start_pt1 = @pts[0].offset(vector_ext)
				ext_end_pt1 = @pts[1].offset(vector_ext)

				ext_start_pt0 = @pts[0].offset(vector_ext_off)
				ext_end_pt0 = @pts[1].offset(vector_ext_off)

				dim_start_pt = @pts[0].offset(vector_dim)
				dim_end_pt = @pts[1].offset(vector_dim)
				view.drawing_color = "#0000ff"
				view.line_width = 1

				view.draw(GL_LINE_STRIP, ext_start_pt0, ext_start_pt1)
    				view.draw(GL_LINE_STRIP, ext_end_pt0, ext_end_pt1)
				view.draw(GL_LINE_STRIP, dim_start_pt, dim_end_pt)
				# Draw Arrow Heads (triangle)

				if @width > 14
					vector_xh = wallvec2.clone	
					vector_xh.length = 1.5
					vector_yh = wallvec.clone	
					vector_yh.length = 7.0

					ah01 = dim_start_pt.offset(vector_xh)
					ah02 = dim_start_pt.offset(vector_xh.reverse)
					ah01 = ah01.offset(vector_yh)
					ah02 = ah02.offset(vector_yh)
					view.draw(GL_POLYGON, dim_start_pt, ah01, ah02)

					ah11 = dim_end_pt.offset(vector_xh)
					ah12 = dim_end_pt.offset(vector_xh.reverse)
					ah11 = ah11.offset(vector_yh.reverse)
					ah12 = ah12.offset(vector_yh.reverse)
					view.draw(GL_POLYGON, dim_end_pt, ah11, ah12)

				textoptions = {
  				:font => "Arial",
  				:size => 14,
  				:bold => false,
				:color => "0000ff",
  				:align => TextAlignCenter
				midx = (@pts[0].x + @pts[1].x) * 0.5
				midy = (@pts[0].y + @pts[1].y) * 0.5
				midz = (@pts[0].z + @pts[1].z) * 0.5
				midpoint = [midx, midy, midz]
				vector_dim.length = 20.0
				dimpt = midpoint.offset(vector_dim)

				view.draw_text(view.screen_coords(dimpt), @width.to_s, textoptions)

I’d use a unique color so my users appreciate that I’m generating that information…


I find this type of feature consistent with the simplicity of how SketchUp works. You don’t have to watch the VCB while drawing your wall.

You may save a tiny fraction of a second per operation.

Chief Architect have probably analysed the efficiency advantages before implementing - maybe there is information available somewhere.

There can also be a psychological advantage to this type of visual aid - the user can actually feel more confident and in control of the process.

Down the road - also consider the graphic quality of visual aids - the more sophisticated they look and operate, the more the user will tend to adopt them.

1 Like

I’ll add to why? a unique color is preferable…

my ‘selected’ color preference matches your ‘added’ color exactly, and could cause confusion…


1 Like

So why not make a 1" long dimension SKP component.
Ship that with your code-set.
In your code load it into the model.definitions, if it doesn’t exist.
Place an instance of it, anchored at p1 and scale its transformation/rotation to p2.
Update that transformation p1 >>> p2, until p2 is confirmed.
Ensure that its instance is always erased when the tool completes, or the tool exits for ANY other reason…

Yes, blue is probably not the best color for this. That is why I’m putting it out on the boards to try and determine the best color to use.

What would you recommend?

What would be the advantage to loading a component vs. just drawing it via the OpenGL methods?

I guess one could then utilize quite fancy 3D arrow heads etc… but I think that might be too over the top (gold plated) for some people.

In general - the design of visual aids should be consistent with their role. If you are depicting a temporary measurement, a translucent appearance would likely be appropriate. Also, you probably don’t want it to look exactly like dimension lines, so you could consider a wider “bar” appearance.

As for colour, as the SU templates, etc., are quite customizable, I would recommend user customizable colour.

1 Like

avoid these…

model = Sketchup.active_model
used = []
used << model.rendering_options['BackgroundColor'].to_a
used << model.rendering_options['HighlightColor'].to_a
used << model.rendering_options['ForegroundColor'].to_a


code that checks what they are and comes up with a complimentary color to use is useful…

you never know the users template choices…


Wow, I learn something new every day, I didn’t even know you could access these options. I guess I need to spend more time perusing the API just to know what tools are at my disposal.

I guess I could go with a muted color (to indicate it is a temporary element) just as I am doing with the wireframe, perhaps a gray or a smoke bluish color?

1 Like

This is a translucent red - not obvious in this capture.

I would guess most users would prefer a subtle colour.

actually I think magenta comes out as the least used as a preset color…

aqua is also good on white or black…


Better translucent impression.

1 Like