Arguments from the command line

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/11/2011 at 00:58, xxxxxxxx wrote:

Hello there!

I was wondering if it's possible to tell C4D to open a particular file and pass some arguments to a python script from a terminal command line.

I'm hoping to automate C4D to process some bitmap images into geometry and export as STL. I don't want to actually render anything.

Does this sound possible? Thanks in advance!

Cheers, sCam

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/11/2011 at 06:46, xxxxxxxx wrote:

Hi sCam, in your plugin you can ask for sys.argv to get a list of passed arguments. But this list is only available if C4D is full loaded - so on startup this is not set yet. This should be added. Thx for the report.  Until this is implemented, you could use environment variables which can be read out via os.environ. If you use R13 the best place is the PluginMessage function - just define it somewhere in your plugin, its a callback fired by c4d automatically on startup.

import os
  
def PluginMessage(id, data) :
    if id==c4d.C4DPL_COMMANDLINEARGS:
        print os.environ
        #TODO
        return True
    return False

Cheers, Sebastian

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/11/2011 at 09:40, xxxxxxxx wrote:

Hey!

Thanks very much for your reply. You'll have to forgive me as I'm kind of new to all of this Python in C4D stuff. I'm not running the code as a plug-in at the moment. Right now I'm running a script from the manager. Do you think I need to switch to creating a plug-in to achieve this result?

Also, are you aware of any resources on creating plug-ins in Python? My searches so far have turned up very little (the few bits and pieces out there seem to focus on C++). The SDK doesn't offer much help either.

Cheers, sCam

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/11/2011 at 09:56, xxxxxxxx wrote:

Do you think I need to switch to creating a plug-in to achieve this result?

In this case you can access the arguments with sys.argv and os.environ. But you cannot autostart the script on startup of c4d, you still have to start it manually. This would be not the case if you write a plugin. Just copy the code above in a *.pyp file and place the file somewhere in your plugins folder. Then start c4d with set environment variables and open the console of C4D.

Also, are you aware of any resources on creating plug-ins in Python? My searches so far have turned up very little (the few bits and pieces out there seem to focus on C++). The SDK doesn't offer much help either.

The documentation contains a folder called "examples" which contains some plugins.

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 04/11/2011 at 10:32, xxxxxxxx wrote:

May be of your interest, too. Even its still very incomplete.

http://forums.cgsociety.org/showthread.php?f=47&t=1005134

THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

On 05/11/2011 at 16:22, xxxxxxxx wrote:

Thanks all, gonna have a look at getting it going as a plugin. Expect more stoopid questions soon ;-)

Cheers, sCam