On 31/07/2018 at 20:04, xxxxxxxx wrote:
Hi everyone,
I've got two scripts that seemingly look like they're working correctly but put both together they don't. The main part is a script that iterates through all objects in a file, selects the ones with a specific name and then changes an attribute. However, that script doesn't work properly unless there's an object already selected so I am calling it from another script that will select the first object if none are already selected. Now I'm getting "not defined" errors from the main script because I guess it doesn't know that it's in the current document?
import c4d
def recur_iter(obj,ref) :
while obj:
if obj.GetName() == 'V1' and obj[c4d.LIGHT_VLTYPE] == 2:
print obj.GetName() + ' Now Has No Volumetrics'
obj[c4d.LIGHT_VLTYPE]=0
elif obj.GetName() == 'V1' and obj[c4d.LIGHT_VLTYPE] == 0:
print obj.GetName() + ' Now Has Volumetrics'
obj[c4d.LIGHT_VLTYPE]=2
recur_iter(obj.GetDown(),ref)
obj = obj.GetNext()
def recur_iter2(obj2,ref2) :
while obj2:
if obj2.GetName() == 'V2' and obj2[c4d.LIGHT_VLTYPE] == 2:
print obj2.GetName() + ' Now Has No Volumetrics'
obj2[c4d.LIGHT_VLTYPE]=0
elif obj2.GetName() == 'V2' and obj2[c4d.LIGHT_VLTYPE] == 0:
print obj2.GetName() + ' Now Has Volumetrics'
obj2[c4d.LIGHT_VLTYPE]=2
recur_iter2(obj2.GetDown(),ref2)
obj2 = obj2.GetNext()
def main() :
ref = op[c4d.LIGHT_BRIGHTNESS]
ref2 = op[c4d.LIGHT_BRIGHTNESS]
recur_iter(doc.GetFirstObject(),ref)
recur_iter2(doc.GetFirstObject(),ref2)
c4d.EventAdd()
if __name__=='__main__':
main()
import c4d, os
def main() :
FirstObject = doc.GetFirstObject()
selec = doc.GetActiveObject()
if selec == None:
FirstObject.SetBit(c4d.BIT_ACTIVE)
else:
pass
c4d.EventAdd()
execfile(c4d.storage.GeGetC4DPath(c4d.C4D_PATH_LIBRARY_USER)+os.sep+"scripts"+os.sep+"VolumetricSwitch.py")
c4d.EventAdd()
if __name__=='__main__':
main()