Line and distance between selected cpoints



I’m looking for a part of code that draws a line between selected cpoints and get the distance.

To get the selected cpoints you can use:

m=Sketchup.active_model; s=m.selection; s.grep(Sketchup::ConstructionPoint);

but how can you transfer the collected points to usable points to create lines or get the distance between it?



Let’s assume:



  ### do something with each cpt here

E.G. to find the position of each ‘cpoint’ use:


This is a ‘point3d’ object.

If you want to draw a line to another point, use:

edg=m.active_entities.add_line(pt, some_other_point)

To find the distance from the pt to some_other_point, use:



Thanks again Tig,

I only get the following error:

undefined local variable or method ‘some_other_point’ for #<AS_RubyEditor::RubyEditor:0x000000078d3cc0

when i do this:

m=Sketchup.active_model; s=m.selection; cpts=s.grep(Sketchup::ConstructionPoint)

 ### do something with each cpt here
 edg=m.active_entities.add_line(pt, some_other_point)


Where and when did you define some_other_point? It either doesn’t exist at all, or is in a namespace that isn’t visible inside the each block.


The clue is in the error message !
If you don’t define ‘some_other_point’ as a point3d or a three element array, then it is going to fail !!

Please read what you type, and what error messages you get back.
I only used ‘some_other_point’ as a ‘placeholder’ in the code example - you need to expend at least a little effort to get it to work like you want it to…


A thanks sorry and i see the glue now :slight_smile: i was i little bit to fast