run a script from within a script

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Display Modes
  09 September 2013
run a script from within a script

Hi there,

I implemented a "save and renderbutton" into m the settings script of FS_preview_render
and after savinf the ini file I start the render script with call command. unfortunately the call command is different on different machines.
basically I just want to start a python script from within a python script.

I looked around and people say to use the os.system() command, witch (not surprisingly) is not working.

I triend to import my script:

import c4d, FS_preview_redner

... doesn't work.

I am shure this is not a dificult task to do, but unfortunately I was not able to find it in der SDK ether... so please

I need help :(

thanks a lot in advance
  09 September 2013
Hi Jops,

if only one part of the code differs depending on the circumstances, there is no need to create two separate scripts. This is what the if-statement is for

    if use_command_1:

Out of interest, can you tell me what command differs on which machines? The change of Command IDs is rather a rare case in between C4D releases, and especially between platforms. Note that the ID of scripts is different from machine to machine, so you should not try to invoke another script via CallCommand().

To answer your actual question in case you really have to execute another script (which is usually only useful for dynamic loading of code):

def execute_script(filename):
    fl = open(filename, 'rb')
    code = compile(, filename, 'exec')
    scope = {'__file__': filename, '__name__': '__main__'}
    exec code in scope

Cinema 4D Plugin Developer | Freebies | Plugins
  09 September 2013
Hi Niklas,

what would I do without you

even though I had the idea this coud be bad I used CallCommand() ... well stupid, I know. but I was tired and it worked for me

the reason I want to start the second script is this. I have preview render and preview settings as two scripts.
they have different icons and this makes sense as you do not want to always click twice if you could click just once

there might be a posibility to to have two icons and just one script, but back in the days I just coded it that way.

with the new version I wanted to implement this "save and render" Button, so if you change settings you don't have to hit ok (save) and then hit the icon for the render script.

your solution works nice (as always)
after helping me so many times at least 20% of this script is yours

again thanks so much.
and best regards

  09 September 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 01:57 PM.

Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.