Problems trying to move a group of objects

Hey all, I’m banging my head on a very frustrating bug that I can’t figure out. I have a simple script that I use to vertically move objects down (or up) to the world-xy plane. I’m slicing objects to then be CNC’d. The script works great for single objects, but once it’s a group of objects I can’t get it to work. Here’s what I have:

import rhinoscriptsyntax as rs

objectIds = rs.GetObjects("Select objects to move")

def moveObjects( objectsList ):
    bbox = rs.BoundingBox(objectsList, view_or_plane=None, in_world_coords=True)
    objectsMoved = 0
    if bbox:
        bottomPoint = bbox[0]
        zHeight = bottomPoint[2]
        rs.MessageBox( 'SendToXYPlane: zheight %f' % zHeight )
        idsMoved = rs.MoveObjects(objectsList, [0,0,-zHeight])
        objectsMoved += len( idsMoved )
    return objectsMoved

if objectIds:
    objectsMoved = 0
    groupsMoved = 0
    groupsToMove = []
    for objectId in objectIds:
        objectGroups = rs.ObjectGroups( objectId )
        if objectGroups:
            for group in objectGroups:
                if group not in groupsToMove:
                    groupsToMove.append( group )
        else:
            objectsMoved += moveObjects( [objectId] )
    for group in groupsToMove:
        groupsMoved += 1
        objectsMoved += moveObjects( rs.ObjectsByGroup( group ) )
    rs.MessageBox( 'SendToXYPlane: Moved %i object(s) in %i group(s) to WorldXY plane' % (objectsMoved, groupsMoved) )
else:
    rs.MessageBox( 'SendToXYPlane: Error, no objects moved' )

The problem seems to be that the rs.MoveObjects command fails if the objects are in a group. I’ve retooled the script so it tries to move all the objects in the group at once, but it still fails. I can’t find any info on how I should move groups otherwise, but is there some other command to do this?

I’m running 5.2.1 on a Mac

Hi Zoltan,

It seems the script works as expected over here.
Might it be that some objects are in more than one group?

Can you elaborate in what way the script fails, does nothing get moved or incorrectly?

Maybe if you send a file along that shows the incorrect behaviour someone over here can have a look at the possible cause.

-Willem

Hey Willem, thanks for having a look at this.

Upon restarting Rhino the script seems to function properly. Generally when it fails nothing gets moved at all, and the counts that get displayed in the dialog boxes are accurate (“0 object(s) moved”) so it seems like the rs.MoveObjects is what fails.

I’ve had the script stop functioning a couple times now and a Rhino restart fixes it. One thing to note, I am mostly using this script to move mesh objects. Not sure if that’s an issue.