I want to do dag menu hack and i am not that good in mel can any one give me a clue how to do it using python Thanks in advance :D
On 9/11/12, Justin Israel <[email protected]> wrote: > Probably this: > (http://pastebin.com/fAgffsQf) > > def attachPref(sh, worldSpace): > a= "%s.%s" % (sh, "delightVertexPointPref") > if cmds.objExists(a): > cmds.addAttr(sh, dt="doubleArray", ln="delightVertexPointPref") > > # get points positons and write into one big string $data > ptsCnt = cmds.getAttr("%s.controlPoints" % sh, s=True) > data = [3*ptsCnt] > for i in xrange(ptsCnt): > if worldSpace: > pos = cmds.xform("%s.vtx[%d]" % (sh, i), q=True, ws=True, > t=True) > else: > pos = cmds.xform("%s.vtx[%d]" % (sh, i), q=True) > data.extend(pos) > > cmds.setAttr(a, data, type="doubleArray") > > > In python you can build up a list instead of formatting a string. > > > On Tue, Sep 11, 2012 at 8:43 AM, f.michal <[email protected]> wrote: >> Hello >> I have a workin MEL code that I need to convert to python. >> I'm not really sure how would I set values on doubleArray attributes - >> it's >> weird already with MEL. >> >> So, what would be the translation of following into python : >> >> global proc attachPref(string $sh, int $worldSpace) >> { >> string $a= $sh + "." + "delightVertexPointPref"; >> if(!`objExists ($a)`) >> addAttr -dt "doubleArray" -ln "delightVertexPointPref" $sh; >> >> //get points positons and write into one big string $data >> int $ptsCnt= `getAttr -s ($sh+".controlPoints")`; >> string $data; >> float $pos[3]; >> for($i= 0; $i<$ptsCnt; ++$i) { >> if($worldSpace) $pos= `xform -q -ws -t ($sh + ".vtx[" + $i + >> "]")`; >> else $pos= `xform -q -t ($sh + ".vtx[" + $i + >> "]")`; >> $data += $pos[0] + " " + $pos[1] + " " + $pos[2] + " "; >> } >> >> eval setAttr $a -type "doubleArray" (3*$ptsCnt) $data; >> } >> >> The last line is the important part :) >> >> Thanks ! >> ps. this is urgent :) >> >> -- >> view archives: http://groups.google.com/group/python_inside_maya >> change your subscription settings: >> http://groups.google.com/group/python_inside_maya/subscribe > > -- > view archives: http://groups.google.com/group/python_inside_maya > change your subscription settings: > http://groups.google.com/group/python_inside_maya/subscribe > -- view archives: http://groups.google.com/group/python_inside_maya change your subscription settings: http://groups.google.com/group/python_inside_maya/subscribe
