본문 바로가기

Cinema 4D Scripts & Plugins

[Cinema 4D Python tag] MW Auto Layer Tag

Create a Python tag for the selected object, paste the code below, and the child object's layers will automatically be replaced with the parent object's layers. For clarity, the color of the Python tag is linked to the object's layer color.

You can add this Python tag to a preset in the Asset Browser for easy access and use.


원하는 오브젝트에 파이썬 태그를 생성하고, 하단 코드를 붙여넣으면 자식 오브젝트의 레이어들이 자동으로 상위 오브젝트의 레이어로 바뀝니다. 가시성을 위해 파이썬 태그 색은  오브젝트의 레이어 색과 연동되도록 했습니다.

파이썬 태그의 프리셋에 등록해두고 쓰면 편하게 꺼내 쓰실 수 있습니다.

GUMROAD DOWNLOAD LINK

# MW Auto Layer Tag
# This Python Code made by MW
# instagram / @dding_one
# Code is on this link : https://auddnjs135.tistory.com/10
import c4d

CHECK_TAGNAME = 'MW Auto Layer Tag'

def SetLayerChildren(op, layer):
    pytag = op.GetTag(c4d.Tpython, 0)
    if pytag: #자식 파이썬 태그가 있으면?
        if pytag[c4d.ID_BASELIST_NAME] == CHECK_TAGNAME:
            return
     #자식 파이썬 태그 유무 검사

    # 자식에 부모 레이어 덮어씌우기
    op[c4d.ID_LAYER_LINK] = layer

    # 자식 없으면 종료
    if op.GetChildren() is None: return

    # 자식 재귀적으로 처리
    for child in op.GetChildren():
        SetLayerChildren(child, layer)

def main():
    # 애니메이션 실행 시 작동 중지
    if c4d.CheckIsRunning(c4d.CHECKISRUNNING_ANIMATIONRUNNING) \
    and c4d.CheckIsRunning(c4d.CHECKISRUNNING_EXTERNALRENDERING):
        return

    obj = op.GetObject() #Get Object
    layer = obj[c4d.ID_LAYER_LINK] #Get Object's Layer
    if layer:
        op[1041670] = 1 #Icon Enable
        op[c4d.ID_BASELIST_ICON_COLOR] = layer[c4d.ID_LAYER_COLOR]
        obj[1041670] = 1 #Icon Enable
        obj[c4d.ID_BASELIST_ICON_COLOR]= layer[c4d.ID_LAYER_COLOR]
    else:
        op[1041670] = 0 #Icon Disable
        obj[1041670] = 0 #Icon Disable
	
    op[c4d.ID_LAYER_LINK] = None
    op[c4d.ID_BASELIST_NAME] = CHECK_TAGNAME

    pytag = obj.GetTag(c4d.Tpython, 0)
    if pytag != op:
        if pytag[c4d.ID_BASELIST_NAME] != CHECK_TAGNAME:
            c4d.gui.MessageDialog('You must put this python tag before any other python tags!')
        return

    #현재 오브젝트의 자식 순차적으로 검사
    for child in obj.GetChildren():
        SetLayerChildren(child, layer)

if __name__=='__main__':
    main()

 


Tutorial for someone who never used python tag
파이썬 태그를 사용안해본 분들을 위한 사용법

Add a Python tag to the desired object and copy and paste the code above.
원하는 오브젝트에 파이썬 태그를 달고 상단의 코드를 그대로 복사해서 붙여넣는다. (사실상 적용 끝)

Add a layer to the desired object. End.
원하는 오브젝트에 레이어를 추가한다. 끝.

You can then copy the Python tag you created to other objects and use it directly.
To apply this feature to a children object, apply the Python tag to the children object first, and then apply the children object's layer.
If it doesn't work, make sure that all the code in the MW Auto Layer Tag is up to date. I'm constantly updating my code, so there may be compatibility issues.

이렇게 만든 파이썬 태그를 다른 오브젝트에 복사해서 바로 사용할 수 있습니다.
하위 오브젝트에 이 기능을 적용하려면 하위 오브젝트에 먼저 파이썬 태그를 적용하고, 그 다음에 하위 오브젝트의 레이어를 적용해주세요.
만약 작동이 잘 안되면 MW Auto Layer Tag의 코드가 모두 최신 코드인지 확인해주세요. 계속 코드 업데이트를 하고 있어서 호환성 문제가 생길 수도 있습니다.

 

 

2024.05.22 MW Auto Layer Tag로 이름 변경 및 파이썬 태그에 레이어가 적용 안되게 수정
2024.01.15 렌더 시 작동안하게 최적화 설정 및 오류 수정
2024.01.13 최적화 및 오류 발생 방지 메세지 추가
2024.01.10 아이콘 색도 레이어 색을 따라 변경되도록 설정
2024.01.06 파이썬 태그에도 레이어가 자동으로 추가되도록 설정 line 37
2023.12.28 렌더 시에는 작동안하게 최적화 설정

Cinema 4D R25, 2023, 2024 버전만 테스트 완료했습니다.