Assign materials to Objects using Python
Posted: 14 January 2022 11:26 AM   [ Ignore ]  
Total Posts:  6
Joined  2020-02-19

Hello!
I would like to automate the replacement of materials loaded in Alembic.

How can I change the attached python code to replace the material with a material with the same name as the one applied in Alembic?

I would appreciate your advice.


import re
import c4d

def main():
  doc = c4d.documents.GetActiveDocument()
  oplist = doc.GetObjects()
  if not oplist: return
  matlist = doc.GetMaterials()
  if not matlist: return
  if oplist:
      for op in oplist:
        opname = op.GetName()       
        mat = doc.SearchMaterial(opname)
        if not mat:
          for mat in matlist:
              mname = mat.GetName()
        mname = mat.GetName()
        match = re.match(opname, mname)
        if match:
          textag = c4d.TextureTag()
          textag.SetMaterial(mat)
          textag[c4d.TEXTURETAG_PROJECTION]=c4d.TEXTURETAG_PROJECTION_UVW
          op.InsertTag(textag)
  c4d.EventAdd()
if __name__==‘__main__’:
  main()

Profile
 
 
Posted: 14 January 2022 11:30 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
Total Posts:  10903
Joined  2011-03-03

Hi staff,

(This name is misleading, as you are not part of the Cineversity staff here, would you mind changing it? Thanks for considering it. Use the contact us button, left lower corner.)

For anything Python and developing, please use the forum Maxon provides for developers:

https://developers.maxon.net/?page_id=1114

All the best

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004

Photography For C4D Artists: 200 Free Tutorials. Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile
 
 
Posted: 14 January 2022 08:00 PM   [ Ignore ]   [ # 2 ]  
Total Posts:  6
Joined  2020-02-19

Thank you.
It seems that https://developersに投稿してみましたが is hardly ever viewed.
I am hoping for replies on Cineversity as well.

I understand about the name!

Profile
 
 
Posted: 14 January 2022 08:01 PM   [ Ignore ]   [ # 3 ]  
Total Posts:  6
Joined  2020-02-19

Thank you.
I tried posting this on https://developers, but it seems to get very little views.
I am hoping for replies on Cineversity as well.

I understand about the name!

Profile
 
 
Posted: 14 January 2022 08:11 PM   [ Ignore ]   [ # 4 ]  
Moderator
Avatar
Total Posts:  10903
Joined  2011-03-03

Hi staff,

Thanks for understanding.

You might have the wrong link: (It is the link I gave you, then the forum; perhaps we see different things based on location?)
https://plugincafe.maxon.net

In this forum (plugincafe), with its previous, we had over 60K posts (…and certainly more views). I wouldn’t call that little.
People over there, so far my observation react pro-active if a reasonable question is asked.

I try not to mix this here, as it would water down each side. Python coding belongs to that forum, not here. Similar to that: I forward any tech support question to the Maxon Support Team.

All the best

 Signature 

Dr. Sassi V. Sassmannshausen Ph.D.
Cinema 4D Mentor since 2004

Photography For C4D Artists: 200 Free Tutorials. Texture, Panorama, HDRI, Camera Projection, etc.
https://www.youtube.com/user/DrSassiLA/playlists

Profile