==== 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: 15937
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: 15937
Joined: Tue Mar 23, 2010 8:28 pm
Location: Türkiye

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

Postby Rookie » Thu Jul 01, 2021 6:15 am

Rookie Thu Jul 01, 2021 6:15 am
Hi :
I am working on my tool set,but i cannot switch render engine to octane correct. (C4D R24+octane 2020.2.3.R6)
the render engine in the drop down (render settings) is named Octane render,

but there is no "post effect" octane in the post effect list

If you have a new Document and you switch to octane render by hand and then back to standard by hand. and after that execute the script. the "post effect" octane will be there and the render will be the one to render.

Is there a right/better way to switch to octane. so that it works even if the user did not switch back before by hand?

wish your help plz



Code: Select all
import c4d

def main() :
rdata = doc.GetActiveRenderData()
vpost = rdata.GetFirstVideoPost()
OctaneRender_ID = 1029525
rdata[c4d.RDATA_RENDERENGINE] = OctaneRender_ID

on = False

while vpost:
if vpost.CheckType(c4d.VPxmbsampler) :
on = True
vpost = vpost.GetNext()

if on == False:
vpost = c4d.BaseList2D(c4d.VPxmbsampler)
rdata.InsertVideoPost(vpost)

c4d.EventAdd()

main()
Rookie
Licensed Customer
Licensed Customer
 
Posts: 1
Joined: Fri Nov 23, 2018 1:44 am

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

Postby alvaromartinlop » Wed Jul 21, 2021 7:41 pm

alvaromartinlop Wed Jul 21, 2021 7:41 pm
I used to use this script in c4d without any issues to copy render settings from c4d to the live viewer.

viewtopic.php?f=30&t=64484

I just upgraded to s24 and the script is no longer working, I'm unable to copy kernel settings anymore. After some investigation I found that

Code: Select all
rdata = doc.GetActiveRenderData()
octane = rdata.GetFirstVideoPost()
kernelType = octane[3001]
print("kernelType: " + str(kernelType))


prints

Code: Select all
kernelType: None


I was expecting 2 since I'm overwriting the setting with a path trancing kernel.
Has the id changed? Is there anything I'm doing wrong?

Thanks.
alvaromartinlop
Licensed Customer
Licensed Customer
 
Posts: 5
Joined: Fri Oct 26, 2018 7:13 pm

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

Postby alvaromartinlop » Wed Jul 21, 2021 8:12 pm

alvaromartinlop Wed Jul 21, 2021 8:12 pm
Figured it out

Code: Select all
octane = rdata.GetFirstVideoPost()


No longer works for me because it returns another video post, to get octane I had to get the second video post.

Code: Select all
octane = rdata.GetFirstVideoPost()
while octane and octane.GetName() != "Octane Renderer":
    octane = octane.GetNext()
alvaromartinlop
Licensed Customer
Licensed Customer
 
Posts: 5
Joined: Fri Oct 26, 2018 7:13 pm

creating shortcut via python for "Auto Arrange Selected"

Postby Delizade » Mon Jul 26, 2021 11:05 pm

Delizade Mon Jul 26, 2021 11:05 pm
Hello,
is it possible to create shortcut via python for "Auto Arrange Selected". If we can use octane functions via python it must be possible. Could you anyone knows anything about this?
for example I know we can add octane nodes via python so I thought that maybe we can use some menu commands as well.

thank you
Windows 10 (3090Ti) | MacBook Pro (M3 Max)
Delizade
Licensed Customer
Licensed Customer
 
Posts: 146
Joined: Thu Oct 18, 2018 10:38 pm
Location: Istanbul

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

Postby DunHou » Wed Jun 01, 2022 9:28 am

DunHou Wed Jun 01, 2022 9:28 am
yes ,Delizade is right. I also wang to a "Auto Arrange Selected" button.and a lot of setting in python i cannot find in octane,Now in 2021version,aov system seems not work with old pipline,and i cant fix it with py scripts.will octane post a sdk or provide a scirpts exsample .
Thanks
DunHou
Licensed Customer
Licensed Customer
 
Posts: 1
Joined: Mon Nov 29, 2021 3:14 am

Getting Current Rendering Information Via Python

Postby freakanay » Sat Jun 04, 2022 2:42 pm

freakanay Sat Jun 04, 2022 2:42 pm
Hi people!

I've been struggling with this for a while, and I still cannot find the correct way to do it: I would like to get current rendering information of my scene that's using Octane - things like what frame the render is currently on, how long it took to render per frame, etc.
I see in the console all the Octane info and basically, I just want the same info but through the Python terminal.

Does anyone know the right syntaxes for this?!

Thanks a bunch!
freakanay
Licensed Customer
Licensed Customer
 
Posts: 6
Joined: Wed Aug 31, 2016 2:52 pm
PreviousNext

Return to Help / Tutorials


Who is online

Users browsing this forum: No registered users and 5 guests

Thu Mar 28, 2024 3:34 pm [ UTC ]