@dan rathbun said:
@kdasilva said:
how can I get 10 Point3d's evenly spread out along this line that I can use as anchors for my text....
Divide the line by 9
<span class="syntaxdefault">arr</span><span class="syntaxkeyword">=[]<br /></span><span class="syntaxcomment"># load array with the txt values in order<br /></span><span class="syntaxdefault">pt </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">start</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">position<br />vec </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> edge</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">line<br />num </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> dict</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">size</span><span class="syntaxkeyword">-</span><span class="syntaxdefault">1<br />seg </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> vec</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword">/</span><span class="syntaxdefault"> num<br />vec</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">length </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> seg<br />arr</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">each_with_index </span><span class="syntaxkeyword">{|</span><span class="syntaxdefault">e</span><span class="syntaxkeyword">,</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> pt</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">offset</span><span class="syntaxkeyword">!(</span><span class="syntaxdefault">vec</span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> if i</span><span class="syntaxkeyword">></span><span class="syntaxdefault">0<br /> entities</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">add_text</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> arr</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">i</span><span class="syntaxkeyword">],</span><span class="syntaxdefault"> pt </span><span class="syntaxkeyword">)<br />}</span><span class="syntaxdefault"> </span>
I am trying my hardest to get this to work, unfortunately I have been unsuccessful thus far.....i put in:
def draw_vision_field
vision_field = ["test1", "test2", "test3", "test4", "test5"]
pt = $line.start.position
puts pt
vec = $line.line
puts vec
num = vision_field.size - 1
puts num
seg = vec.length / num
puts seg
vec.length = seg
vision_field.each_with_index {|e,i|
pt.offset!(vec) if i > 0
$ents.add_text( vision_field[i], pt )
}
end
I just put a test array to print for now. I added the puts in order to try and debug, I am getting this error message regarding the length= function on a vector...also the last number before the word error (the vec.length /num ), weirdly enough is always 0, i removed the /num and it always prints as 2, no matter how long the line is i make)
(-350507.397831", 21906.712364", 0")
(-350507.397831", 21906.712364", 0")
(0.131501105216966, 0.991316023943281, 0.0)
4
0
Error; #<NoMethodError; undefined method `length=' for [Point3d(-350507, 21906.7, 0), Vector3d(0.131501, 0.991316, 0)];Array>
(eval);70;in `draw_vision_field'
(eval);55;in `draw_the_line'
(eval);28;in `onLButtonDown'
(eval);73
also... where does the method each_with_index come from? I can't find it in the sketchup api, and I could only find each_index in the ruby-doc http://www.ruby-doc.org/core/classes/Array.html#M000232
thanks for the help
korbin