Adding Dimensions to a Line with Ruby


#1

Hello. I am new to building plug ins for Sketchup. I have figured out how to draw a simple line, but I would then like to have the dimensions of that line show with it. This is what I have.

model = Sketchup.active_model
entities = model.entities
pt1 = [0, 0, 0]
pt2 = [0, 350, 0]
new_line = entities.add_line pt1, pt2

So this makes my line. Now the next part, I think should have something like
add_dimension_linear pt1, pt2, [0,0,0]

However that is not working. If someone could please help me with this, it would be greatly appreciated.

Thanks


#2

What version of SketchUp are you using? SketchUp 14 is the first version to support adding Linear Dimensions in the Ruby API. So this simply can not be accomplished in earlier versions of SketchUp.

Open the Ruby Console from the Window menu, then run your code. Are there any error messages? Post them here.

However I went ahead and tried your example. The code I tried first is:

model    = Sketchup.active_model
entities = model.entities
pt1      = [0, 0, 0]
pt2      = [0, 350, 0]
new_line = entities.add_line pt1, pt2
new_dim  = entities.add_dimension_linear(pt1, pt2, [0, 0, 0])

Which looks correct but gives me this not terribly helpful error message: #<ArgumentError: Invalid arguments>

I’ll give you a hint. The 3rd argument [0,0,0] is a Vector representing a parallel offset from the Edge at which to place the LinearDimension. What is the magnitude and direction of this Vector?


#3

Yes, I am using Sketchup 14.

Thank you for the help. I am sure that I tried that last night, but maybe not. I changed me last vector to [0,1,0] and it worked perfectly.

Thanks