How can I set an Attibute to an Tag
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2011 at 06:49, xxxxxxxx wrote:
Hi all
after solving my last Problem (thanks to nux95 )Here a second Question:
How can I define the value of the Phong-Tag?
It should bo on an the angle should be 35° (0,61)
I catched something out of the Skript log and modified it.
But, it does' t work!def setAllPolygonObjectsPhongTag(doc) : obj = doc.GetFirstObject() while obj: if obj.CheckType(c4d.Opolygon) : c4d.SetActiveTag(c4d.Tphong, 0) <------------ c4d.PHONGTAG_PHONG_ANGLELIMIT=True <------------ c4d.PHONGTAG_PHONG_ANGLE=0.611 <------------ obj.SetBit(c4d.BIT_ACTIVE) else: obj.DelBit(c4d.BIT_ACTIVE) obj = walk(obj)
Does anybody has an idea???
Thanks
Rgds -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2011 at 07:30, xxxxxxxx wrote:
c4d.PHONGTAG_PHONG_ANGLELIMIT and 4d.PHONGTAG_PHONG_ANGLE are just constant ID (Integer values). You can't just set them to another value (ok, they are not really constant, that's because of Python) and hope this will change the attribute of the tag. How should c4d know what object you mean ? You can use either the comfortable way, using \__getitem\_\_ and \__setitem\_\_, that implement the [] bracket syntax, or the uncomfortable but mor flexible way using a BaseContainer.
# the comfortable way using [] syntax (__getitem__, __setitem__) import c4d import math obj[c4d.PHONGTAG_PHONG_ANGLELIMIT] = True obj[c4d.PHONGTAG_PHONG_ANGLE} = math.degrees(35) # note that this syntax is all equivalent with obj.__setitem__(c4d.PHONGTAG_PHONG_ANGLELIMIT, True) obj.__setitem__(c4d.PHONGTAG_PHONG_ANGLE, math.degrees(35))
# the more flexible but uncomfortable way import c4d import math bc = obj.GetData() bc.SetBool(c4d.PHONGTAG_PHONG_ANGLELIMIT, True) bc.SetReal(c4d.PHONGTAG_PHONG_ANGLE, math.degrees(35)) obj.SetData(bc) # not that when calling `obj.GetDataInstance()` instead # of `obj.GetData()` you obtain the **original** c4d.BaseContainer # instance, so you do not have to call `obj.SetData(bc)` afterwards.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2011 at 09:35, xxxxxxxx wrote:
Thanks for the answer.
I have testet al 4 Versions.
But nothing happens ???
Here must be a mistake in my Code:import c4d import math from c4d import gui #Welcome to the world of Python def walk(obj) : if not obj: return elif obj.GetDown() : return obj.GetDown() while obj.GetUp() and not obj.GetNext() : obj = obj.GetUp() return obj.GetNext() def selectAllPolygonObjectsPhong(doc) : print 'selectAllPolygonObjects Phong START' obj = doc.GetFirstObject() while obj: if obj.CheckType(c4d.Opolygon) : print c4d.BaseObject.GetName(obj) #Testausgabe bc = obj.GetDataInstance() bc.SetBool(c4d.PHONGTAG_PHONG_ANGLELIMIT, True) bc.SetReal(c4d.PHONGTAG_PHONG_ANGLE, math.degrees(35)) obj = walk(obj) print 'selectAllPolygonObjects Phong FERTIG' def main() : selectAllPolygonObjectsPhong(doc) if __name__=='__main__': main()
or
import c4d import math from c4d import gui #Welcome to the world of Python def walk(obj) : if not obj: return elif obj.GetDown() : return obj.GetDown() while obj.GetUp() and not obj.GetNext() : obj = obj.GetUp() return obj.GetNext() def selectAllPolygonObjectsPhong(doc) : print 'selectAllPolygonObjects Phong START' obj = doc.GetFirstObject() while obj: if obj.CheckType(c4d.Opolygon) : print c4d.BaseObject.GetName(obj) #Testausgabe obj[c4d.PHONGTAG_PHONG_ANGLELIMIT] = True obj[c4d.PHONGTAG_PHONG_ANGLE} = math.degrees(35) obj = walk(obj) print 'selectAllPolygonObjects Phong FERTIG' def main() : selectAllPolygonObjectsPhong(doc) if __name__=='__main__': main()
or with an error
import c4d import math from c4d import gui #Welcome to the world of Python def walk(obj) : if not obj: return elif obj.GetDown() : return obj.GetDown() while obj.GetUp() and not obj.GetNext() : obj = obj.GetUp() return obj.GetNext() def selectAllPolygonObjectsPhong(doc) : print 'selectAllPolygonObjects Phong START' obj = doc.GetFirstObject() while obj: if obj.CheckType(c4d.Opolygon) : print c4d.BaseObject.GetName(obj) #Testausgabe bc = obj.GetData() bc.SetBool(c4d.PHONGTAG_PHONG_ANGLELIMIT, True) bc.SetReal(c4d.PHONGTAG_PHONG_ANGLE, math.degrees(35)) obj.SetData(bc) obj = walk(obj) print 'selectAllPolygonObjects Phong FERTIG' def main() : selectAllPolygonObjectsPhong(doc) if __name__=='__main__': main()
Sorry asking sutch NOOB questions
What am I doing wrong -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2011 at 10:51, xxxxxxxx wrote:
Most things in live are so easy
The solution is:
obj.SetPhong(1,1,0.610865238)
and it works
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2011 at 11:35, xxxxxxxx wrote:
Originally posted by xxxxxxxx
The solution is:
obj.SetPhong(1,1,0.610865238)
Glad you found the solution.
Be aware that the first and second parameters aren't numbers, but booleans (True or False, like a checkbox). So you could call SetPhong() like this: obj.SetPhong(True, True, 0.610865238)
And thanks for pointing out this method, its documentation is broken !
Confused
[URL-REMOVED]. I'll fix it.
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 09/11/2011 at 13:03, xxxxxxxx wrote:
In your code, obj is not the phong tag, it is still the polygon object.
Just like the c4d module does not know what tag you want to affect, when you wanted to do c4d.PHONGTAG_PHONG_ANGLELIMIT = True, the polygon object doesn't know either.Obtain the phong tag using
tag = obj.GetTag(c4d.Tphong) if not tag: # the object does not have a phong tag continue # go to the next loop tag[c4d.PHONGTAG_PHONG_ANGLELIMIT] = True # ...
_And I have to correct something from above, of course you need to use math.radians and not math.degrees. _