1
[C4D] General Discussion / Re: C4D 2026
« on: 2025-09-11, 09:25:32 »
Yeah, guess we can skip the update to 2026 for now. :)
Having trouble verifying your license? If you are seeing a license verification message or are unable to access your Chaos products, please follow these simple steps to fix sign-in issues. If you have already tried this and are still unable to access your Chaos products, please contact Support.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
import c4d
def get_all_objects_iterative(doc):
"""
Collects and returns a list of all objects in the document.
"""
result = []
op = doc.GetFirstObject()
while op:
result.append(op)
op = op.GetNext()
i = 0
while i < len(result):
current = result[i]
child = current.GetDown()
while child:
result.append(child)
child = child.GetNext()
i += 1
return result
# Global variable to store the last active index.
global g_lastActiveIndex
if 'g_lastActiveIndex' not in globals():
g_lastActiveIndex = None
def main():
# Get the active document.
doc = c4d.documents.GetActiveDocument()
if not doc:
print("No active document found.")
return
# New boolean user data to enable/disable the script (ID 12).
# When false, the script will exit immediately, allowing you to make changes without swapping.
enabled = op[c4d.ID_USERDATA, 12]
if not enabled:
print("Script disabled via user data parameter. No processing will be done.")
return
# Retrieve materials from custom user data.
# IDs: 1 = material0, 2 = material1, ..., 10 = material9.
mat0 = op[c4d.ID_USERDATA, 1]
mat1 = op[c4d.ID_USERDATA, 2]
mat2 = op[c4d.ID_USERDATA, 3]
mat3 = op[c4d.ID_USERDATA, 4]
mat4 = op[c4d.ID_USERDATA, 5]
mat5 = op[c4d.ID_USERDATA, 6]
mat6 = op[c4d.ID_USERDATA, 7]
mat7 = op[c4d.ID_USERDATA, 8]
mat8 = op[c4d.ID_USERDATA, 9]
mat9 = op[c4d.ID_USERDATA, 10]
# Active Index: keyframeable integer from 0 to 9 (ID 11).
activeIndex = op[c4d.ID_USERDATA, 11]
print("Current active index (new selection):", activeIndex)
# Build list of material options.
matOptions = [mat0, mat1, mat2, mat3, mat4, mat5, mat6, mat7, mat8, mat9]
# Validate activeIndex.
if activeIndex < 0 or activeIndex >= len(matOptions):
activeIndex = 0
# Get the new material from the active index.
newMat = matOptions[activeIndex]
if newMat and newMat.CheckType(c4d.Ttexture):
new_material_ref = newMat.GetMaterial()
else:
new_material_ref = newMat
print("New material reference (active):", new_material_ref)
# Use a global variable to know the previous selection.
global g_lastActiveIndex
if g_lastActiveIndex is None:
g_lastActiveIndex = activeIndex
print("Initializing g_lastActiveIndex to", activeIndex)
return # Nothing to swap on first run.
print("Previous active index (g_lastActiveIndex):", g_lastActiveIndex)
if activeIndex == g_lastActiveIndex:
print("Active index has not changed. Nothing to swap.")
return
# Get the previous material reference based on the previous active index.
oldMat = matOptions[g_lastActiveIndex]
if oldMat and oldMat.CheckType(c4d.Ttexture):
old_material_ref = oldMat.GetMaterial()
else:
old_material_ref = oldMat
print("Old material reference (previous active):", old_material_ref)
if new_material_ref is None:
print("New material reference is None. Aborting swap.")
return
# Get all objects from the scene.
objects = get_all_objects_iterative(doc)
objectCount = len(objects)
print("Total objects scanned:", objectCount)
swapCount = 0
# Iterate over the list of objects.
for obj in objects:
for tag in obj.GetTags():
if tag.CheckType(c4d.Ttexture):
currentMat = tag.GetMaterial()
# Compare by pointer equality OR by comparing material names.
if (currentMat == old_material_ref) or \
(currentMat and old_material_ref and currentMat.GetName() == old_material_ref.GetName()):
print("Swapping on object:", obj.GetName(),
"Tag:", tag.GetName(),
"\n from:", old_material_ref,
"\n to:", new_material_ref)
tag.SetMaterial(new_material_ref)
swapCount += 1
print("Finished swapping. Total tags swapped:", swapCount)
# Update the global variable with the new active index.
g_lastActiveIndex = activeIndex
c4d.EventAdd()
A fresh setup did the trick. And somehow, if the Distance Shader range has no noise / textures linked, the viewport update is immediate. If there is a noise texture linked, the viewport refreshes after I've disabled and enabled the Scatter. Thanks for your input!
If you can reliably reproduce this behaviour, then consider reporting it as a bug. https://forum.corona-renderer.com/index.php?board=55.0