A new version of Cineversity has been launched. This legacy site and its tutorials will remain accessible for a limited transition period

Visit the New Cineversity
   
 
Assign materials to Objects using Python
Posted: 14 January 2022 07:26 PM   [ Ignore ]  
Total Posts:  6
Joined  2020-02-20

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 07:30 PM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

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
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile
 
 
Posted: 15 January 2022 04:00 AM   [ Ignore ]   [ # 2 ]  
Total Posts:  6
Joined  2020-02-20

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: 15 January 2022 04:01 AM   [ Ignore ]   [ # 3 ]  
Total Posts:  6
Joined  2020-02-20

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: 15 January 2022 04:11 AM   [ Ignore ]   [ # 4 ]  
Administrator
Avatar
Total Posts:  12043
Joined  2011-03-04

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
Maxon Master Trainer, VES, DCS

Photography For C4D Artists: 200 Free Tutorials.
https://www.youtube.com/user/DrSassiLA/playlists

NEW:

NEW: Cineversity [CV4]

Profile