c4d python 插件_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() < 1: return None

#Get a clone

#Always work on the clone so we aren't changing the object in the OM

source =obj.GetClone()

#Run EdgeToSpline - returns a Boolean (True)

#Note that SendModelingCommand expects a list []!

if c4d.utils.SendModelingCommand(c4d.MCOMMAND_EDGE_TO_SPLINE, [source]):

#Splines are created as children of the source object

#Return a clone of the splines, otherwise the won't be "Alive"

return source.GetDown().GetClone()

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值