Pymel / Python Coding

Curve fix and setup for Renderman/3delight

coded this up in pymel and used qt designer for the GUI in maya. This GUI sets up the normals on curves for rendering in renderman / 3delight – and is used in conjunction with primitive variables on each curve and a curve shader.

As you can see in (1) a regular curve prior to be fixed is all kinds of wonky. With this technique the ‘Face Camera’ of the normals are disabled and they can be set to all face the direction selected.

GUI enables per item or selection
1 Fix
2 set direction
3 color
5 Animation of Curve based on curve length proportion or custom set. Start and end frames
can also be set.

6 Width for start and end can be adjusted

qt designer

http://dopesheet.co.uk/?p=91

maya

http://dopesheet.co.uk/?p=86

import pymel.core as pm
pm.shadingNode ('ramp',asTexture=True,n="curveRamp")
pm.shadingNode ('place2dTexture',asUtility=True,n="curveRamp_place2dTexture")
pm.connectAttr ("curveRamp_place2dTexture.outUV", "curveRamp.uv");
pm.connectAttr( "curveRamp_place2dTexture.outUvFilterSize", "curveRamp.uvFilterSize");
pm.disconnectAttr ("curveRamp_place2dTexture.outUV", "curveRamp.uvCoord");
if (pm.window('Normal_Curve_Creator',exists=True)):
    pm.deleteUI('Normal_Curve_Creator')
import curve_fixer
reload(curve_fixer)
dialog2 = pm.loadUI(f="C:/Users/luke/Documents/QTDESIGNER/rebuild_curve.ui")
allowedAreas = ['right', 'left']
pm.showWindow()
pm.dockControl(area='left',content=dialog2,allowedArea=allowedAreas,l='Normal_Curve_Creator')

pymel
http://dopesheet.co.uk/uncategorized/curve_fixer-py/

3delight geo attributes_

# create geo attributestring $dga_node = DGA_create();DGA_visibilityTransmissionCreateAttr($dga_node);DGA_visibleToCameraCreateAttr($dga_node);DGA_geometryCurves($dga_node);setAttr ($dga_node + “.visibilityTransmission”) 0; //opaquestring $sl[] = `ls -sl -l`;DL_setObjectAttrib($dga_node, “delightGeoAttribs”, $sl); # change property of existing geo attributestring $dga_node = “delightGeoAttribs2”;setAttr ($dga_node + “.visibilityTransmission”) 1; //opaque For creating mask set per selection:

Processing to Maya

Set up command ports in Maya First thing is to open a port in maya this enables a processing sketch to communicate in real time back to maya. The port numbers need to match up with those used in the sketch. // mel script open port commandPort -name “127.0.0.1:6004” // mel script close port commandPort…

Triple Shading Switch for per object shading

I wanted to render using the maya hardware renderer (very quick). For this to work colors need to be visible in the viewer. Triple Shading Switch in Maya is equivalent to Renderman per object primitive variable shading that I’ve used on other projects. Scroll down for alternative 3delight/Renderman version with pros and cons.    …

Dictionaries, Pickle and Python

### data sample from country-capitals.csv United Arab Emirates,Abu Dhabi,24.4666666667,54.366667,AE,Asia Nigeria,Abuja,9.0833333333,7.533333,NG,Africa Parse a .csv file and create a Dictionary. import pymel.core as pm dataPath = “C:/country-capitals.csv” f = open(dataPath) line = f.readline() mapDict = {} while line: parts = line.split(“,”) countryObject = parts[0].strip() cityObject = parts[1].strip() latObject = parts[2].strip() lonObject = parts[3].strip() mapDict[countryObject]=[cityObject,latObject,lonObject] line = f.readline()…

Normalized Values

Sometimes its helpful to have a data range scaled into another range aka normalised. I’ve used this for things like having numbers scale into a color ramp that works in the 0-1 range inputVal = 2.1 minVal = 1.2 maxVal = 4.5 normalizedValue = (inputVal – minVal) / (maxVal – minVal) print normalizedValue In this…