I have 400 points in my 3d coordinate system, I am trying to connect all of these points to one defined point. This is the code I have so far, I’m wondering if theres a way to use the AddLine command for one point to many others.
import rhinoscriptsyntax as rs
point1 = rs.GetPoint("Pick first point")
if point1:
other_points = rs.AllObjects()
rs.AddLine(point1, other_points)
import rhinoscriptsyntax as rs
# GetObject (point object, not GetPoint() which looks for a xyz *location*
point1 = rs.GetObject("Select the first point", 1, preselect=True)
# the result from getObject() is a an object GUID, not a point in space
#Get the 3d location of the point object as a 'Point3d'
#There is also rs.PointCoordinates(id) which may also work fine here
p1 = rs.coerce3dpoint(point1)
# turn off the screen redraw to make it faster, otherwise the screen
#redraws every time a line is added.
rs.EnableRedraw(False)
if point1:
#Get all the other point objects available
# but ignore any other object types (that have different codes).
# i.e. you do not need to worry about non-eligilbe objects being in the
# scene, as you would with rs.AllObjects()
other_points = rs.ObjectsByType(1)
#iterate through the list of point objects
# for each one check that it is not the same one as the first selcted point
# then, if not, get its point3d location and feed that to rs.AddLine() with th
# first point
for id in other_points:
if id != point1:
rs.AddLine(p1,rs.coerce3dpoint(id))
#make sure to redraw the scene when done.
rs.EnableRedraw(True)
@pascal
thank you, worked perfectly.
Although you’ve done enough and understand if you dont do this, could you give a quick summary as to what you did?
@pascal
How could I change this code to draw a line from one point to each point for EVERY point. I.e. looping this process for every point on in the 3d plane
Hello - you can, but that is a lot of lines. ca. 80,000 or so… for 400 pts.
import rhinoscriptsyntax as rs
import itertools
def test():
rs.EnableRedraw(False)
points = rs.ObjectsByType(1)
if not points: return
if len(points) < 2: return
pairs = itertools.combinations(points, 2)
for pair in pairs:
rs.AddLine( rs.coerce3dpoint(pair[0]), rs.coerce3dpoint(pair[1]))
#make sure to redraw the scene when done.
rs.EnableRedraw(True)
test()
Im trying to call the “createLines()” command on multiple points selected (what is starred at the bottom of my code). Any ideas how do do this?
import rhinoscriptsyntax as rs
def createLines():
point1 = rs.GetObject("Select the first point", 1, preselect=True)
p1 = rs.coerce3dpoint(point1)
rs.EnableRedraw(False)
if point1:
other_points = rs.ObjectsByType(1)
for id in other_points:
if id != point1:
rs.AddLine(p1, rs.coerce3dpoint(id))
rs.EnableRedraw(True)
******if pt is selected, then createLines()
Hi, I’m now trying to do something similar with an added step. So far, this is what I have to create lines from one selected point to all other points.
import rhinoscriptsyntax as rs
def createLines():
point1 = rs.GetObject("Select the first point", 1, preselect=True)
p1 = rs.coerce3dpoint(point1)
rs.EnableRedraw(False)
if point1:
other_points = rs.ObjectsByType(1)
for id in other_points:
if id != point1:
rs.AddLine(p1, rs.coerce3dpoint(id))
rs.EnableRedraw(True)
createLines()
Now, I’m trying to add the function of either:
once created, delete those lines that intersect with the planes in my model
or
if id != point1:
AND if path doesnt intersect planes
addLine