GHPYTHON_block_scatter

A simple ghpython component.

which can copy your rhinoObject (block,mesh) automaticly. Enjoy it!

__author__ = "jasonSong"
__version__ = "2020.03.11"
                                
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import random 
ghenv.Component.Message = 'copy blocks'
        
if Guid==None or pts==None:
    print "Please select location points of trees"
    info = "Please select location points of trees"
else:
    print "Generate successfully"
    info = "Generate successfully"
                                    
#Sorting points function
def sortpt(point):
    value = (point.Z * 10000) + (point.Y * 100) + point.X
    return value
sortedpts = sorted(pts,key = sortpt,reverse = False)
        
#change doc to Rhino.Doc and generate
if Button:
    sc.doc = Rhino.RhinoDoc.ActiveDoc 
    for pt in sortedpts:
        angle = random.randint(-90,90)
        scale = random.uniform(1.0,1.5)
        obj = rs.RotateObject(Guid,Guid_pt,angle)
        G = rs.ScaleObject(obj,Guid_pt,[scale,scale,scale])
        G1 = rs.CopyObject(G,pt)
        rs.ObjectName(G1,Name)
        rs.DeleteObject(G)
        rs.AddGroup(Name)
        rs.AddObjectToGroup(G1,Name)
        
#change doc back gh_canvas
sc.doc = ghdoc