Hi @r_gigante & @zipit,
Thank you both for your replies. I am still experiencing the issue, unfortunately. I can set the Phong angle manually, but I want to set (or override) my object's Phong angle with a tag. As can be seen in this image, the Phong tag is at 91⁰.

It should look like this. (side note: when the object is made editable, it creates a Phong tag with the angle set with SetPhong
and deletes the previous one):

@zipit
My issue is not with setting the Phong. My issue is that I cannot surface the Phong tag to the user as is done with the Cinema 4D Primitives. Here is a code example that shows how the Phong tag I'm creating does not associate with the object's Phong tag until it is made editable.
import os
import math
import sys
import c4d
from c4d import utils
PLUGIN_ID = 1234569
class PhongDemoObject(c4d.plugins.ObjectData):
size = 100
def __init__(self, *args):
super(PhongDemoObject, self).__init__(*args)
self.SetOptimizeCache(True)
def Init(self, op):
tag = op.MakeTag(c4d.Tphong)
tag[c4d.PHONGTAG_PHONG_ANGLELIMIT] = True
tag[c4d.PHONGTAG_PHONG_ANGLE] = c4d.utils.DegToRad(91.0)
tag[c4d.PHONGTAG_PHONG_USEEDGES] = False
c4d.EventAdd()
return True
def GetVirtualObjects(self, op, hierarchyhelp):
ret = self.CreateMyObject()
if ret is None:
return None
ret.SetName(op.GetName())
return ret
def CreateMyObject(self):
node = c4d.PolygonObject(8, 6)
node.SetPoint(0, c4d.Vector(-self.size,-self.size,-self.size))
node.SetPoint(1, c4d.Vector(-self.size,self.size,-self.size))
node.SetPoint(2, c4d.Vector(self.size,-self.size,-self.size))
node.SetPoint(3, c4d.Vector(self.size,self.size,-self.size))
node.SetPoint(4, c4d.Vector(self.size,-self.size,self.size))
node.SetPoint(5, c4d.Vector(self.size,self.size,self.size))
node.SetPoint(6, c4d.Vector(-self.size,-self.size,self.size))
node.SetPoint(7, c4d.Vector(-self.size,self.size,self.size))
node.SetPolygon(0, c4d.CPolygon(3,1,7,5))
node.SetPolygon(1, c4d.CPolygon(3,5,4,2))
node.SetPolygon(2, c4d.CPolygon(4,6,0,2))
node.SetPolygon(3, c4d.CPolygon(6,7,1,0))
node.SetPolygon(4, c4d.CPolygon(0,1,3,2))
node.SetPolygon(5, c4d.CPolygon(4,5,7,6))
node.SetPhong(True, True, c4d.utils.DegToRad(40.0))
node.Message(c4d.MSG_UPDATE)
return node
"""
#this throws an error:
#AttributeError: 'function' object has no attribute 'im_func'
def Message(self, node, type, data):
if type == c4d.MSG_MENUPREPARE:
node.SetPhong(True, True, c4d.utils.DegToRad(40.0))
return True
"""
if __name__ == "__main__":
c4d.plugins.RegisterObjectPlugin(id=PLUGIN_ID,
str="PhongDemoObject",
g=PhongDemoObject,
description="phongdemoobject",
icon=None,
info=c4d.OBJECT_GENERATOR )
I got some errors without including the res
folder, so I've uploaded it if you wish to demo it on your machine:
Phong Demo Object.zip
@r_gigante
I am calling BaseObject::SetPhong()
as it is done in the example: py-rounded_tube_r13.pyp. In that file, the method that sets the Node's points & then the Phong (GenerateLathe) is called from ObjectData::GetVirtualObjects()
.
Using the code below threw this error AttributeError: 'function' object has no attribute 'im_func'
:
def Message(self, node, type, data):
if type == c4d.MSG_MENUPREPARE:
node.SetPhong(True, True, c4d.utils.DegToRad(40.0))
Am I doing this incorrectly?
Thanks again.