On 31/07/2018 at 20:04, xxxxxxxx wrote:
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?
def recur_iter(obj,ref) :
if obj.GetName() == 'V1' and obj[c4d.LIGHT_VLTYPE] == 2:
print obj.GetName() + ' Now Has No Volumetrics'
elif obj.GetName() == 'V1' and obj[c4d.LIGHT_VLTYPE] == 0:
print obj.GetName() + ' Now Has Volumetrics'
obj = obj.GetNext()
def recur_iter2(obj2,ref2) :
if obj2.GetName() == 'V2' and obj2[c4d.LIGHT_VLTYPE] == 2:
print obj2.GetName() + ' Now Has No Volumetrics'
elif obj2.GetName() == 'V2' and obj2[c4d.LIGHT_VLTYPE] == 0:
print obj2.GetName() + ' Now Has Volumetrics'
obj2 = obj2.GetNext()
def main() :
ref = op[c4d.LIGHT_BRIGHTNESS]
ref2 = op[c4d.LIGHT_BRIGHTNESS]
import c4d, os
def main() :
FirstObject = doc.GetFirstObject()
selec = doc.GetActiveObject()
if selec == None:
On 01/08/2018 at 09:40, xxxxxxxx wrote:
It seems you're getting "not defined" errors for 'op' variable in the executed script with execfile().
'op' is None when there is no selected object before running the main script.
So in the executed script, if 'op' is None it should then be assigned the active object returned by doc.GetActiveObject().
On 02/08/2018 at 10:24, xxxxxxxx wrote:
Thanks, that pointed me in the right direction.
This worked for me
doc = c4d.documents.GetActiveDocument() # Get the open document
obj = c4d.documents.BaseDocument.GetFirstObject(doc) # Get first object in hierarchy
op = obj