C4D中的python生成器

首页 > 影视软件 > C4D >

C4D中的python生成器

| 万视网

python生成器是预制的python 插件的objectData的封装(就和脚本是插件commandData的封装一样)。这样创建生成器对象就不用写全脚本了,注意这物体仅仅是生成器,想创建变形器,还得老老实实创建objectData插件。

在生成器内的python代码会生成一个object。默认下,生成了一个立方体,并返回: import c4d def main(): return c4d.BaseObject(c4d.Ocube)UserData输入

当然也可以返回别的物体,或者用userdata调整物体参数。注意op可以快速引用生成器对象。

importc4d defmain(): cone =c4d.BaseObject(c4d.Ocone) cone[c4d.PRIM_CONE_TRAD] = op[c4d.ID_USERDATA,1] return cone 对象输入--pipe生成器

许多c4d生成器会将其孩子作为输入,这里咱也可以这么干。通过 op.GetDown()能获取第一个熊孩子,用 op.GetChildren()能获取所一窝熊孩子。接下来就要折腾熊孩子了,为了他们的安全,咱先弄一个拷贝。

创建整个对象层次也不难,一般创建完层次会返回顶层对象。如果选了这个生成器,还返回了 MakeEditable,就能看到创建好的整个层级结构。上代码:

importc4d def main(): #Get the child object (to use as the sweep spline) #Use GetClone so we aren't working on the object itself source =op.GetDown().GetClone() #Create a Circle Primitive to act as the sweep profile circle =c4d.BaseObject(c4d.Osplinecircle) #Set the radius based on UserData 1 circle[c4d.PRIM_CIRCLE_RADIUS] =op[c4d.ID_USERDATA,1] #Create a new SweepNURBS sweep =c4d.BaseObject(c4d.Osweep) #Insert the source sweep spline under the SweepNURBS source.InsertUnder(sweep) #Insert the circle profile spline under the SweepNURBS circle.InsertUnder(sweep) #Return the SweepNURBS return sweep 建模命令-边到样条线

建模命令也能生成新对象。再次强调,需要在拷贝原物体后在拷贝上进行操作,就不会直接修改层级里面的对象。下面的例子给当前选中的物体输出了样条线。

importc4d defmain(): #Get the child object obj =op.GetDown() #We can only continue if there was a child if not obj: return None #Also need to check that it's a poly object if not obj.CheckType(c4d.Opolygon): return None #And that at least one edge is selected if obj.GetEdgeS().GetCount()

注意,这个例子需要选中一个物体的一条边。生成器的cache检测不到选中物体的变化,因此需要关闭优化cache才能更新。不幸的是关闭优化还不能正常工作,以后会正常的。