Skip to content

Instantly share code, notes, and snippets.

@bonsak
Last active March 26, 2018 17:35
Show Gist options
  • Select an option

  • Save bonsak/7ed3514746de1bd7ce81 to your computer and use it in GitHub Desktop.

Select an option

Save bonsak/7ed3514746de1bd7ce81 to your computer and use it in GitHub Desktop.
Mimic UDIM in Cinema4D
import re, c4d
from c4d import documents as docs
# Python tag that Mimics UDIM for texture tags in Cimena4D.
# Name your texture tags 1001, 1002, 1021 etc
# Doesn't check the number of tag on each row
# Iterates through all tags on the object that this script is attached to
# Find all texture tags with with name that starts with 10 (UDIM style)
# Check if they are of type texture (5616)
class TagIterator:
def __init__(self, obj):
currentTag = None
if obj :
self.currentTag = obj.GetFirstTag()
def __iter__(self):
return self
def next(self):
tag = self.currentTag
if tag == None :
raise StopIteration
self.currentTag = tag.GetNext()
return tag
def main():
obj = op.GetObject()
tags = TagIterator(obj)
for tag in tags:
# Check first if tag type is Texture
if tag.GetType() == 5616:
# Then check if Tag name starts with 10
if tag[c4d.ID_BASELIST_NAME][:2] == "10":
# Take the 4th character and subtract 1 to get U
offsetU = float(tag[c4d.ID_BASELIST_NAME][3]) - 1.0
# Take the 3rd character and multiply with -1 to get V
offsetV = float(tag[c4d.ID_BASELIST_NAME][2]) * -1
# print "Offset U %s" % tag[c4d.TEXTURETAG_OFFSETX]
# print "Offset V %s" % tag[c4d.TEXTURETAG_OFFSETY]
# Set U and V
tag[c4d.TEXTURETAG_OFFSETX] = offsetU
tag[c4d.TEXTURETAG_OFFSETY] = offsetV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment