Using blocks, It may not be the best idea.
But I did not find another way to freeze the groups.
It works. I got this code from Mitch. https://discourse.mcneel.com/t/group-to-block
It remains to align in order.
import rhinoscriptsyntax as rs
def onegroup_filt(rhino_object, geometry, component_index):
return rhino_object.GroupCount==1
def ConvertGroupsToBlocks():
msg="Select group of objects to convert to block"
objs=rs.GetObjects(msg,group=True,preselect=True,custom_filter=onegroup_filt)
if not objs: return
group_set=set()
for obj in objs:
obj_g_names=rs.ObjectGroups(obj)
for g_name in obj_g_names:
group_set.add(g_name)
all_obj_groups=list(group_set)
#all_obj_groups should now contain unique list of groups
for group in all_obj_groups:
g_objs=rs.ObjectsByGroup(group)
origin=rs.coerce3dpoint([0,0,0])
block=rs.AddBlock(g_objs,origin,group,delete_input=True)
rs.InsertBlock(block,origin)
ConvertGroupsToBlocks()
def AlignObjs():
frame = rs.GetObjects("Select frame")
frame_bbox = rs.BoundingBox(frame)
frame_left = frame_bbox[0][0]
frame_width = abs(frame_bbox[0][0] - frame_bbox[1][0])
objects = rs.GetObjects("Select objects to align")
bboxes = [rs.BoundingBox(obj) for obj in objects]
widths = [abs(bbox[0][0] - bbox[1][0]) for bbox in bboxes]
x_positions = [bbox[0][0] for bbox in bboxes]
width_sum = sum(widths)
gap = (frame_width - width_sum) / len(objects)
current_x = frame_left + (gap/2)
for i, obj in enumerate(objects):
transform = [current_x - x_positions[i] ,0 ,0]
rs.MoveObject(obj, transform)
current_x += widths[i] + gap
rs.UnselectAllObjects()
AlignObjs()