美文网首页CgTd
Including Classes

Including Classes

作者: N景波 | 来源:发表于2018-06-25 16:46 被阅读0次

创建C4D 插件时,可以在外部文件定义类来组织项目。 这样就必须import 类,并继承此类。

首先,在别的文件中用类名实例化此类。(此文件为MyClass.py)

class MyClass():
  def __init__(self, name='KeyframeHandler'):
  #构造函数需要一个名字
    self.name=name

在插件主文件中,添加插件路径并导入类

import os
import sys
__currdir__ = os.path.dirname(__file__)

if __currdir__ not in sys.path:
  sys.path.insert(0, __currdir__)
  from MyClass import MyClass

此时就可以在插件的方法中引用此类了

def Execute(self, tag, doc, op, bt, priority, flags):
  s = MyClass()  
  print s.name
  return c4d.EXECUTIONRESULT_OK

相关文章

网友评论

    本文标题:Including Classes

    本文链接:https://www.haomeiwen.com/subject/xbjenttx.html