Chat GPT python 3 updates

Useful snippets

# primary visibility on off on multiple selection

import maya.cmds as cmds

def turn_off_arnold_visibility(selected_objects, visibility_value):
    for obj in selected_objects:
        try:
            cmds.setAttr(f"{obj}.primaryVisibility", visibility_value)
            print(f"Arnold primary visibility set to {visibility_value} for {obj}.")
        except Exception as e:
            print(f"Error setting primary visibility for {obj}: {e}")

# Get the current selection
selected_objects = cmds.ls(selection=True)

# Check if there is any selection
if selected_objects:
    # Prompt the user to enter visibility value
    visibility_value = int(input("Enter visibility value (0 or 1): "))
    
    if visibility_value in [0, 1]:
        turn_off_arnold_visibility(selected_objects, visibility_value)
    else:
        print("Invalid visibility value. Please enter 0 or 1.")
else:
    print("No objects selected. Please select objects to modify.")
# extrude Nurbs curve profile along Nurbs curve
# select profiles – select profile curve last
# chat gpt update to python 3

import maya.cmds as mc

# Get selected curves
ListCurves = mc.ls(sl=True)

# Initialize variables
paths = ListCurves[:-1]  # Exclude the last curve for the profile
ExtrudeProfile = ListCurves[-1]  # The last curve is the profile curve
selSize = len(paths)

# Loop through curves and extrude
for i in range(selSize):
    mc.extrude(ExtrudeProfile, paths[i], n='myRibbons_' + str(i), ch=1, rn=0, po=1, et=2, ucp=1, fpt=1, upn=1, rotation=0, scale=1, rsp=1)

# Create clusters on curve
 
import maya.cmds as mc

 
myCurve = mc.ls(sl=True)[0]

curve_CVs = mc.getAttr( " % s. cp " % myCurve, size=True )

for cv in range(curve_CVs):

    mc.cluster (' % s.cv [%s] ' %(myCurve, cv), relative=True )

#Mel - Delete unknown nodes
{
    string $unknownNodes[] = `lsType unknown`;
    for($node in $unknownNodes){
        if($node=="<done>")
            break;
        if(`objExists $node`)
        {
            int $lockState[] = `lockNode -q -l $node`;
            if($lockState[0]==1)
            lockNode -l off $node;
            delete $node;
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *