==== Octane useful scripts ====

Forums: ==== Octane useful scripts ====
Sub forum for help and tutorials.

Moderator: aoktar

Re: ==== Octane useful scripts ====

Postby weirdcore » Sun May 13, 2018 10:52 am

weirdcore Sun May 13, 2018 10:52 am
@mikeadamwood
yes this PBR images template/script sound ideal/amazing,, did you get any further with that?
if so i'd love to know more
if not, i'd love to make this happen,, i don't how to code much either, but i could ask around
weirdcore
Licensed Customer
Licensed Customer
 
Posts: 4
Joined: Fri May 12, 2017 10:01 am

Python script for saving layers as separate projects

Postby mofostopheles » Sat Jul 14, 2018 5:10 pm

mofostopheles Sat Jul 14, 2018 5:10 pm
This is a script I wrote to optimize a part of our production pipeline. I typically have scenes with, say, a product on a table, props, background, different lights for hard and soft shadows, maybe a reflection pass, etc. Some of these objects would need to be occluded using Octane's Render Layer functionality using the Render ID number. Also, some of these passes didn't require the same high sample or depth rates either, which can save a lot of money/time if you ship all your stuff to an external render farm. Hence there was a lot of project files with the same objects and camera moves but with different render settings and passes. As you might imagine doing this by hand is not advised. I wrote this script to create all the separate scene files from each layer in a master project. Changes to a scene happen in one place, your master project, and all of the layer projects can be autogenerated from this one place. As an example, now you can go into one of these projects and set up an Octane render layer ID, or fuss with other settings like the sample/depth just for the layers concerned.

This script does the following actions:

1: starts out by turning off visibility and render for all layers
2: for each layer, turn on the vis/render and then...
3: save a copy of the project, appending the layer name to whatever your base name is.
IMPORTANT: basename should end in a dash. Change this in the code to suit your needs.

You will end up with several projects with the appropriate layers turned on and all others turned off. Any objects not on a layer will of course be visible/renderable by default.

import c4d
from c4d import gui
'''
__author__ = "Arlo Emerson <[email protected]>"
__status__ = "production"
__version__ = "1.0"
__date__ = "13 July 2018"

WHAT IT IS
Automated layer toggle+file-save script for separating each identified layer into its own scene file...This is useful because Octane doesn't offer this feature, only a manual setting of layerID (one at a time), nice but tedious if you have lots of things needing to be rendered separately at various samples/depths. It is a little different than using the Octane Render layer functionality in that you won't get occlusion effects which is really what that feature is great for. However, you can save yourself a bit of time by placing objects to be occluded on their own layer e.g. "power_cord", then enabling Render Layer for just that one project file.

This script does the following actions:

1: starts out by turning off visibility and render for all layers
2: for each layer, turn on the vis/render and then...
3: save a copy of the project, appending the layer name to whatever your base name is.
IMPORTANT: basename should end in a dash. Change this in the code to suit your needs.

You will end up with several projects with the appropriate layers turned on and all others turned off. Any objects not on a layer will of course be visible/renderable by default.

USAGE
Under Render Settings, Save tab, Regular Image file name should be something terminating in a dash e.g. d:\path\to\project\BASENAME-

Run the script. A series of Save-as dialogs will appear, simply hit Save as these cycle through. The last layer's project file will be left open.

Tested on r13. Please report bugs to the author.
'''

#--- LICENSE ------------------------------------------------------------------
# This code contained in save_layers_as_scenes.py and covered by the MIT License.

# MIT License

# Copyright (c) 2017, 2018 Arlo Emerson, [email protected]

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.


def main():
_root = doc.GetLayerObjectRoot()
_layerList = _root.GetChildren()

_renderData = doc.GetActiveRenderData()
_pathName = _renderData[c4d.RDATA_PATH]

#turn off visibility and render for all layers
for tmpLayer in _layerList:
print( tmpLayer.GetName() )
_layerData = tmpLayer.GetLayerData(doc)
_layerData['render'] = False
_layerData['view'] = False
tmpLayer.SetLayerData(doc,_layerData)
c4d.EventAdd()

#loop each layer
#toggle the layer's vis/render, then:
#save a copy with [LAYER_NAME]
#next, re-toggle the layer back to off/off
#loop will repeat this process
for tmpLayer in _layerList:
_layerData = tmpLayer.GetLayerData(doc)
#toggle the properties
_layerData['render'] = not _layerData['render']
_layerData['view'] = not _layerData['view']
tmpLayer.SetLayerData(doc,_layerData)
c4d.EventAdd()
_pathName = _pathName[0:_pathName.rfind("-")+1]

_projectFileName = _pathName + tmpLayer.GetName()

print("current path to output render: " + _projectFileName )

_renderData[c4d.RDATA_PATH] = _projectFileName
c4d.EventAdd()
doc.SetDocumentName( _projectFileName )
c4d.CallCommand(12218) # Save as...

#toggle layer properties back to original state
_layerData['render'] = not _layerData['render']
_layerData['view'] = not _layerData['view']
tmpLayer.SetLayerData(doc,_layerData)
c4d.EventAdd()

if __name__=='__main__':
main()
mofostopheles
Licensed Customer
Licensed Customer
 
Posts: 1
Joined: Mon Dec 12, 2016 10:58 pm

Re: ==== Octane useful scripts ====

Postby aoktar » Mon Oct 22, 2018 10:15 am

aoktar Mon Oct 22, 2018 10:15 am
How to get Octane version number and more about Octane settings from scene by python script
You can find all required IDs in vprenderer.h under c4doctane/res

Code: Select all
import c4d
from c4d import gui

ID_OCTANE_LIVEPLUGIN = 1029499

def main():
    bc = doc[ID_OCTANE_LIVEPLUGIN]       
    print "Octane version=",bc[c4d.SET_OCTANE_VERSION]
    print "Lock resolution=", bc[c4d.SET_LOCKRES]
    print "Check camera updates=", bc[c4d.SET_CHECK_CAMERA]
    print "Default environment color=", bc[c4d.SET_DEF_ENV_COLOR]

    print "Kernel tip=", bc[c4d.SET_KERNEL_TYPE]
    print "DL Max samples=", bc[c4d.SET_DIRECT_MAXSAMPLES]
    print "PT Max samples=", bc[c4d.SET_PATHTRACE_MAXSAMPLES]


if __name__=='__main__':
    main()

Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 12259
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

Re: ==== Octane useful scripts ====

Postby aoktar » Sun Oct 28, 2018 4:45 pm

aoktar Sun Oct 28, 2018 4:45 pm
Here's a quick script I made now. It's forcing the reloading the ImageTextures in selected material.
Code: Select all
import c4d
from c4d import gui

ID_OCTANE_IMAGE_TEXTURE = 1029508

def collect(shdList, n):
    if n.GetType()==ID_OCTANE_IMAGE_TEXTURE: 
        ix=-1
        try:
            ix = shdList.index(n)
        except:
            ix=-1

        if ix==-1:  shdList.append(n)

    if n.GetDown(): collect(shdList, n.GetDown())
    if n.GetNext(): collect(shdList, n.GetNext())
       
def main():
    mat = doc.GetActiveMaterial()
    shaders=[]

    collect(shaders, mat.GetFirstShader())
   
    for n in shaders:
        n[c4d.IMAGETEXTURE_FORCE_RELOAD]=1
        n.SetDirty(c4d.DIRTYFLAGS_ALL)
   
    c4d.EventAdd()   

if __name__=='__main__':
    main()
Octane For Cinema 4D developer / 3d generalist

3930k / 16gb / 780ti + 1070/1080 / psu 1600w / numerous hw
User avatar
aoktar
Octane Plugin Developer
Octane Plugin Developer
 
Posts: 12259
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye
Previous

Return to Help / Tutorials


Who is online

Users browsing this forum: No registered users and 1 guest

Mon Aug 19, 2019 11:39 pm [ UTC ]