Hi all, I am having this issue in which I am unable to create a new set of nHairSystem if I run my script twice in a row.
I am actually creating a ribbon spine in which I have hardcode it to create out nurbs plane with a set number of spans etc.
This is the code that I have used to create the hair:
mm.eval("CreateHair 1 5 5 0 0 0 0 5 0 2 1 1;")
However, while everything works fine and at origin, when I tried to execute the second time, I would got the warning // Warning: file: /apps/Linux64/aw/maya2014/scripts/others/createHair.mel line 770: createHair: follicles currently exist at all create locations, no new hairs created //
Thus is it possible for me to code it in any python manner to re-create another new set?
Quickly testing that mel code snippet shows (in Maya 2014) that I can easily apply it to two different surfaces in a row in a single scene without getting that error. Though you can’t perform that function twice on the same piece of geometry.
Note that this snippet behaves on your selection so you need to select the nurbsPlane that you create.
It’s likely that you hardcoded the name of the nurbsPlane that you create, though the second time you run it the nurbsPlane ends up getting a new unique name (eg. nurbsPlane2) because it already exists.
I don’t know how the rest of your code looks like but I would recommend doing this:
import maya.cmds as mc
nurbsPlane = mc.nurbsPlane()
mc.select(nurbsPlane, r=1)
over
import maya.cmds as mc
mc.nurbsPlane()
mc.select("nurbsPlane", r=1)
Thus avoid hard coding string names, and always use the return values.
Of course if you run the command directly after creating a new object there is no explicit need to select the object, since it’s automatically selected on creation.
Though many would recommend being explicit (thus doing so) over implicit in scenarios that might not be instantly clear, this could be considered one of them.
Another tip is that you can find where the .mel scripts reside on your computer. The confusing thing about your command is that CreateHair is a runtime command and createHair is not.
It’s possible that it’s just calling createHair internally (especially since the error you’re getting is referring to the file), so this could help:
You are pretty right on what I have did, however just before the end operation of my script, I have define a function in which it renames all the items, eg. nurbsPlane to nurbsPlane1, and thus I was thinking that if the user is reclicking onto the script again, it will simply creates as nurbsPlane (which will then be renamed as nurbsPlane2, since nurbsPlane1 exists) and it works, except that the error as I have mentioned will prompts up.
I do get what you mean by the difference of CreateHair and createHair, and I have tried both, however for some reasons, no matter what I did, even if I do use the CreateHair command, it seems to be ‘referencing’ back to the first set of nHair I have done instead of generating a new one.
I pasted the function that I have did for creating the said plane. Hopefully it makes sense else please do tell me and I can provide more information