Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5892

Problems trying to move a group of objects

$
0
0

@zoltan wrote:

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

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5892

Trending Articles