Plugin to create all possible lines between points
-
Hi,
My first question:
I have a set of construction points, which coordinates I want to catch in an Array.
How do I do that?Second question:
I want to draw al the possible lines to connect all the cpoints in that Array.
I think I have to use
line = entities.add_line point1,point2But how do I iterate through the couples in the array?
Examplearray = [A, B, C]Gives me these three couples / lines:
AB
AC
BCAnd of course BA CA and CB but these are duplicate lines..
But how to automate this process??
Thanxs for your input!
-
@liquid98 said:
Hi,
My first question:
I have a set of construction points, which coordinates I want to catch in an Array.
How do I do that?Second question:
I want to draw al the possible lines to connect all the cpoints in that Array.
I think I have to use
line = entities.add_line point1,point2But how do I iterate through the couples in the array?
Examplearray = [A, B, C]Gives me these three couples / lines:
AB
AC
BCAnd of course BA CA and CB but these are duplicate lines..
But how to automate this process??
Thanxs for your input!
-
For the first question, you have to tell how is the "set of construction point", i.e., is it a list of Point3d? if so, you get the [x, y, z] of a Point3d <pt> with
pt.to_a -
For the multi-connection, use that code
def messy_connect_points(entities, list_points) n = list_points.length - 1 for i in 0..n pti = list_points[i] for j in i+1..n entities.add_line pti, list_points[j] end end endFredo
-
-
if the construction points are in the model
mod = Sketchup.active_model ent = mod.entities sel = mod.selection pts=[];#initialize the points array #find all the construction points ent.each{|p| pts.push p.position if p.is_a?(Sketchup;;ConstructionPoint)} #draw all possible lines for i in 0...pts.length-1 for j in 1...pts.length ent.add_line(pts[i],pts[j]) end end -
Hi Sam and Fredo,
Thnx for your help! Exactly what I was after..
@Sam
pts=[];#initialize the points array
why the;??Thnx
-
force of habit. the ; just seperates multiple statements on a single line. In this case the # is used to comment the remainder of the line.
-
Sam,
Well, I'm supposed to know the use of the ; but i forgot..
Again thanx for your help. The Math part was easier than the constructionpointarraycreation.

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement