Python
Cinema 4D R23.110
Windows 10 latest
I have written a simple back-converter to change Octane Materials back to Cinema 4D materials, for export or for members of our team who don't have Octane.
It basically works by creating a new Cinema 4D Material, setting it up & then changing the link in the existing Texture Tag from the Octane material to the new Cinema 4D material.
It all works fine, except that after the script has run, the 'Assign' tab of the new Cinema 4D material doesn't show the objects & texture tags to which it is assigned. This makes me worry that I'm missing some kind of message or initialisation step.
Here's the bit of code that's relevant:
def ReAssign(doc, oct_mat, c4d_mat): #Assigns the new Cinema 4D material to the texture tags
obj_link = oct_mat[c4d.ID_MATERIALASSIGNMENTS] #Get the link list for the Octane Material's assignment
link_count = obj_link.GetObjectCount() #Get how many objects are in the link list
for i in range(link_count): #For each of them...
tex_tag = obj_link.ObjectFromIndex(doc, i) #Get the texture tag
doc.AddUndo(c4d.UNDOTYPE_CHANGE, tex_tag) #Add an undo for the tex tag change
tex_tag[c4d.TEXTURETAG_MATERIAL] = c4d_mat #Replace the Octane Material with the Cinema 4D material
tex_tag.Message(c4d.MSG_CHANGE) #update the tex tag
c4d_mat.Message(c4d.MSG_CHANGE) #update the c4d material
Any pointers on what I'm missing/ best practice ?