Hi folks - long time no see! I have 2500 holes to place at point locations in my file. I found this old Rhinoscript by Damon - any chance I could get it rewritten in Python so I can use it in Mac Rhino?
Option Explicit
'Script written by Damon Sidel
'Script copyrighted by Damon Sidel
'Script version Sunday, April 19, 2009 7:22:34 PM
Call CopyToPoints()
Sub CopyToPoints()
Dim pts : pts = Rhino.GetPointCoordinates("Select points",True)
If IsNull(pts) Then Exit Sub
Dim copyObj : copyObj = Rhino.GetObject("Select object to copy")
If IsNull(copyObj) Then Exit Sub
Dim copyObjOrigin : copyObjOrigin = Rhino.GetPointCoordinates("Select point at origin of object being copied")
If IsNull(copyObjOrigin) Then Exit Sub
Call Rhino.EnableRedraw(False)
Dim arrPt
If IsArray(pts) Then
For Each arrPt In pts
Call Rhino.CopyObject(copyObj,copyObjOrigin(0),arrPt)
Next
End If
Thanks for any help offered in the form of yummy virtual beer.
import rhinoscriptsyntax as rs
pts = rs.GetPointCoordinates("Select points",True)
if pts is None: sys.exit()
copyObj = rs.GetObject("Select object to copy")
if copyObj is None: sys.exit()
copyObjOrigin = rs.GetPoint("Select point at origin of object being copied")
if copyObjOrigin is None: sys.exit()
rs.EnableRedraw(False)
for arrPt in pts:
vec = rs.VectorCreate(arrPt, copyObjOrigin)
rs.CopyObject(copyObj,vec)
@markleichliter, below is another version which handles redraw when hundrets of points are involved:
import Rhino
import scriptcontext
import rhinoscriptsyntax as rs
def CopyObjectToPoints():
pts = rs.GetObjects("Points to copy to", rs.filter.point, True, True, False)
if not pts: return
copyObj = rs.GetObject("Select object to copy")
if not copyObj: return
copyObjOrigin = rs.GetPoint("Origin of object to copy")
if not copyObjOrigin: return
rs.EnableRedraw(False)
for pt_obj in pts:
pt = rs.PointCoordinates(pt_obj)
rs.CopyObject(copyObj, pt - copyObjOrigin)
rs.EnableRedraw(True)
CopyObjectToPoints()
@Alain, there is a bug in rs.GetPointCoordinates which applies to Rhino 5 and 6. If you run the method and press Enter when it asks for the points without selecting any, it gives this error:
Message: iteration over non-sequence of type NoneType
Hi Scott - thanks man!
This -almost- works. It doesn’t seem to take into account any transforms the have been applied to the points - the copied geometry appears at the original location of the points (I’ve copied and pasted the original geometry, with the points, from another file, then moved said geo to be closer to the origin).
I’ll try Clement’s version and see if the same issue happens
It works if the circle is centered on the world origin, but if drawn anywhere else, the script creates the copies offset from the points the equivalent distance from the points as the circle is from the world origin. (Wow that is barely coherent)
Must have been something quirky in that one file, as I’ve burned through placing 2000 of the 2500 holes with no issues. Thanks again for the help, Clement.