THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 28/05/2012 at 12:17, xxxxxxxx wrote:
Give this a try:
import sys, time
from c4d import utils
def main() :
obj = doc.GetActiveObject() #The object you want to add the hair on
c4d.CallCommand(1018401) #Adds the hair object and automatically links it to the active object
hair = doc.SearchObject("Hair") #Grab the new hair object and give it a variable assignment so we can use it for stuff
Cube= doc.SearchObject("Cube") #Grab the instance object we'll add to the hair's instance field later on
#Change the "Generate" option to "instance" mode
#Now that the mode is correct...We can put the instance object into the link field
c4d.EventAdd() #Force C4D to update the changes
c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW) #IMPORTANT!! Redraw all the views before proceeding further!!!
time.sleep(2) #Give the sysytem time to catch up
convert = utils.SendModelingCommand(c4d.MCOMMAND_MAKEEDITABLE,
list = [hair],
mode = c4d.MODIFY_ALL,
bc=c4d.BaseContainer(), doc = doc)
Generating hairs can take a long time. Depending on how many you're generating.
It might be bad practice to do this kind of thing from a script. So be careful with how many hairs you generate.
Using Sleep() & DrawViews() like I did in this case lets C4D sort of catch it's breath for a second. And get caught with all of the changes that happened.
But it's a terrible hack...Not something I'd want to use a lot.
There might be a better(safer) way to make the script pause and catch up.