torsdag 20 juni 2013

C#/C++/Python

Been doing a lot of programming lately. From having no experience at all, I know have a pretty good understanding about the compiler, classes, inheritance, types and so forth.
Have been programming and watching tutorials for like a month and I just started out programming with Python. Made some scripts for Maya and Nuke (Nothing complicated and I think the code is awful but anyway it's fun to just try things) :)
My goal is to follow 3dbuzz course and write a modular rigging system.

Created my own bulk-renamer



Here is some code I have been scripting:




This is my Rename-Tool.
It creates a nameField for all your selections so you quickly can rename them
And if you want you can add a prefix  and replace words in your names.
(this script looks pretty awful but it works)



#Importera maya cmds som cmds.

import maya.cmds as cmds


#använder slObj för att räkna ut hur många selections som finns.
slObj = 0
#Spar alla selections i en variabel "selection"
selection = cmds.ls(sl=True)


#Skapar fönster
window = cmds.window( title="ReName", iconName='ReName')
cmds.columnLayout( adjustableColumn=True)


#Skapar ett nameField för alla selections. kollar så det finns selections
if selection == []:
    cmds.text("Must select objects before running script!")
    cmds.text("*")
    cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )

else:
    cmds.text("Rename your selections:")

    for s in selection:
        selection
        cmds.nameField(object=s)

        slObj +=1


    cmds.text("You have selected %s" % slObj + " object(s)")


#Skapar ett textField/knapp för att kunna lägga till Prefixer


    cmds.text("Add prefix")

    prefixName = cmds.textField('prefixName', text = "_prefix")



    def click(text):
        createPrefix(prefixName)


    cmds.button(label='Add Prefix', command=click)


    def createPrefix(prefixName):

        newSelection = cmds.ls(sl=True)
        prefixVal = cmds.textField(prefixName, query=True, text = True)

        for s in newSelection:
        cmds.rename(s,s + prefixVal)


#Funktion för att kunna byta ut textrader i namnet till andra texter.
    cmds.text("*")
    cmds.text("Replace:")

    oldName= cmds.textField('oldName',text="old")

    cmds.text("With:")

    newName= cmds.textField('newName',text="new")

    def Replace(text):

        replaceSelection = cmds.ls(sl=True)

        oldNameVal = cmds.textField('oldName', query=True, text=True)
        newNameVal = cmds.textField('newName', query=True, text=True)

        for i in replaceSelection:

        replacedName=i.replace(oldNameVal,newNameVal)
        reName = i
        cmds.rename(reName,replacedName)

        cmds.button(label='Replace',command=Replace)



    cmds.text("**")



#Skapar en knapp för att kunna stänga fönster & för att visa fönster..
cmds.button( label='Close', command=('cmds.deleteUI(\"' + window + '\", window=True)') )
cmds.showWindow( window )

-------------


Here is a another script that fix texture paths, had some problem with it earlier when I was
moving project files from my school computer to my computer @ home.
and this is an easy fix.
------------


import maya.cmds as cmds
import os

fileNodes = cmds.ls(type="file")

for f in fileNodes:
    attrb = "%s.fileTextureName" % f
    fullname = cmds.getAttr(attrib)
    name = os.path.split(fullname)[-1]
    newName = os.path.join("Textures", name)
    cmds.setAttr(attrib, newName, type="string")

-----------

I have written some more (like some cool nukescripts!) but I'll not post it because it takes up to much space.
-----------





Inga kommentarer:

Skicka en kommentar