<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Execfile with loaded script errors]]></title><description><![CDATA[<p dir="auto"><em>On 31/07/2018 at 20:04, <strong>xxxxxxxx</strong> wrote:</em></p>
<p dir="auto">Hi everyone,</p>
<p dir="auto">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?</p>
<pre><code>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()
</code></pre>
<pre><code>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()
</code></pre>
]]></description><link>http://developers.maxon.net/forum/topic/10894/14341_execfile-with-loaded-script-errors</link><generator>RSS for Node</generator><lastBuildDate>Sun, 10 May 2026 08:23:37 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/10894.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 01 Sep 2018 10:53:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Execfile with loaded script errors on Sat, 01 Sep 2018 10:53:13 GMT]]></title><description><![CDATA[<p dir="auto"><em>On 02/08/2018 at 10:24, <strong>xxxxxxxx</strong> wrote:</em></p>
<p dir="auto">Thanks, that pointed me in the right direction. <br />
This worked for me</p>
<pre><code>    doc = c4d.documents.GetActiveDocument() # Get the open document
  
    obj = c4d.documents.BaseDocument.GetFirstObject(doc) # Get first object in hierarchy
    
    op = obj
</code></pre>
]]></description><link>http://developers.maxon.net/forum/post/55367</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/55367</guid><dc:creator><![CDATA[Helper]]></dc:creator><pubDate>Sat, 01 Sep 2018 10:53:13 GMT</pubDate></item><item><title><![CDATA[Reply to Execfile with loaded script errors on Sat, 01 Sep 2018 10:53:10 GMT]]></title><description><![CDATA[<p dir="auto"><em>On 01/08/2018 at 09:40, <strong>xxxxxxxx</strong> wrote:</em></p>
<p dir="auto">Hi,</p>
<p dir="auto">It seems you're getting "not defined" errors for 'op' variable in the executed script with <em>execfile()</em>.<br />
'op' is None when there is no selected object before running the main script.<br />
So in the executed script, if 'op' is None it should then be assigned the active object returned by doc.GetActiveObject().</p>
]]></description><link>http://developers.maxon.net/forum/post/55366</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/55366</guid><dc:creator><![CDATA[Helper]]></dc:creator><pubDate>Sat, 01 Sep 2018 10:53:10 GMT</pubDate></item></channel></rss>