Help us understand the problem. What is going on with this article?

[Cinema 4D] マテリアルアサインリスト

More than 1 year has passed since last update.

今回は各マテリアル側から,アサインしているオブジェクトにアクセスする方法を試してみます.

マテリアルがシーン内のオブジェクトに適用されている場合は,マテリアルのAssignmentを見ればわかります.ここにアクセスするには[c4d.ID_MATERIALASSIGNMENTS]を使います.

MatAssignDataのドキュメントはこちら
c4d.MatAssignDataクラス

ObjectFromIndex(doc, lIndex)
この戻り値はそのマテリアルが適用されているオブジェクトのテクスチャタグとなります.

tag.GetObject()を使うことでオブジェクトにアクセスできます.

doc = c4d.documents.GetActiveDocument()
mat = doc.GetFirstMaterial()

while mat:
    objLink = mat[c4d.ID_MATERIALASSIGNMENTS]
    objCnt  = objLink.GetObjectCount()

    if objCnt > 0:
        for i in xrange(objCnt):
            print "Material Name :", mat.GetName()

            tag = objLink.ObjectFromIndex(doc, i)
            print "Link index[", i, "] :", tag

            obj = tag.GetObject()
            print "Object name :", obj.GetName()

    mat = mat.GetNext()

そのマテリアルがシーン内で使われているかの確認や,マテリアルが適用されているオブジェクトにアクセスすることができ,こちらのほうが都合がよいこともありそうです.

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした