Merge shapes under one transform dose not work properely (Python)


#1

Hello i can`t figure out how to merge list of shapes under one transform
If to open a new scene the create 4 nurbsCircles move rotate scale them
then run this script:

import maya.cmds as mc
#----------------------------------------ShapeCombiner---------------------------------------------#
#Desctiption : create circle with parameters
class ShapeCombiner ():


    # constructor
    def __init__ ( self, curves = ['']):
                     
        #private members
        self.shapes = [''] 
        mc.makeIdentity (curves, apply = True, t =1, r = 1, s = 1, n = 0, pn = 1)                           
            
        # appending shapes to array        
        for curve in curves :            
            for shape in mc.listRelatives(curve, fullPath = 1, shapes = 1) :
                self.shapes.append(shape)
            
         #collect all shapes exept first one
        tmpChildShapes = ['']
        for i in range (2, len (self.shapes)):
             tmpChildShapes.append( self.shapes[i])
            
        i = 0               
        #combining shapes under one transform       
        for shape in tmpChildShapes:                             
             i = i + 1
             if i > 1:
                mc.parent(shape, curves[0], add = 1, shape = 1)   
            
        #deleting old transform nodes
        i = 0        
        for xform in curves:              
           i = i + 1
           if i > 1:
              mc.delete(xform)            
          
        #clear selection
        mc.select(clear = 1) 
        #end ifif len (curves) > 0:    
       
        #combined shapes are all under this member
        self.CombinedCurve = curves[0]   
            
#----------------------------------------------------------------------------------------------#

# Test  Build
c = ShapeCombiner(mc.ls (sl = 1))
# Status : stable


#2

Hmmm… here everything seems to work fine here. Everything stays in place and is grouped under one transform.


#3

Well this script i wrote yesterday not working properly not at work nor at home.
Create any count of shapes - then move them rotate scale and run this script.

And only that parent transform curve stays at please all other moving in random direction.
I tried to set pivot point of all curves into center of coordinates but it did`nt help.


#4

Freeze transformations of objects solve problem.


#5
mc.makeIdentity (curves, apply = True, t =1, r = 1, s = 1, n = 0, pn = 1)    

this code do that


#6

As mentioned, I created several nurbs circles, moved them, rotated them and scaled them. And it worked fine.


#7

What maya are you using?
U have maya 2016 - SP5


#8

I tested this script in Maya 2015 - result is the same. It just moves the shapes.
And no matter what to use MEL or Python - reslult is the same.


#9

For me script also does not work properly until i freeze transforms with Maya UI (2015) before run it.
May be you should apply makeIdentity in a loop for each selected obj?


#10

Resolved!

Guys this is the solution.
It is very confusing for me but, all code works fine exept one thing. Th shapes i added to the parent transform node - are instances for some reason, so once all shapes are unnder transform you should duplicate new "combined " curve and delete previous curves - this will make all right.
Will Post Script here and on Creative Cash this evennig.