Skip to content

Instantly share code, notes, and snippets.

@SatishGodaPearl
Created January 22, 2019 21:10
Show Gist options
  • Save SatishGodaPearl/8a4c22af80d2bb7fa59f8699ebc8811d to your computer and use it in GitHub Desktop.
Save SatishGodaPearl/8a4c22af80d2bb7fa59f8699ebc8811d to your computer and use it in GitHub Desktop.
Lunaria Variant Workflow Prototypes
import maya.app.renderSetup.model.override as override
import maya.app.renderSetup.model.selector as selector
import maya.app.renderSetup.model.collection as collection
import maya.app.renderSetup.model.renderLayer as renderLayer
import maya.app.renderSetup.model.renderSetup as renderSetup
import maya.cmds as cmds
rs = renderSetup.instance()
defaultRenderLayer = rs.getDefaultRenderLayer()
defaultRenderLayer.getChildren()
defaultRenderLayer.name()
visibleRenderLayer = rs.getVisibleRenderLayer()
if visibleRenderLayer == defaultRenderLayer:
pass
renderLayers = rs.getRenderLayers()
if not renderLayers:
pass
variant_layers = {}
for variant in variants:
name = "variant {0}".format(variant)
rLayer = rs.createRenderLayer(name)
variant_layers[variant] = rLayer
assetNode = pm.PyNode(assetName)
shapes = assetNode.listRelatives(ad=True, type='shape')
assert not shapes, "There are no shapes"
geometry = []
for shape in shapes:
geometry.append(shape.getParent())
for name, variantLayer in variant_layers.iteritems():
collection_name = "geometry_{0}".format(name)
collection = variantLayer.createCollection(collection_name)
selector = collection.getSelector()
selector
variant_name = variant
geometry_collection = variant_layers[variant].getCollectionByName("geometry_{0}".format(variant))
selector = geometry_collection.getSelector()
# pm.select(geometry, replace=True)
geos = ','.join(map(lambda geo: geo.longName(),geometry))
selector.setPattern(geos)
for dagPath in selector.paths():
print dagPath.fullPathName()
selector.setPattern("")
class WorkFileData(object):
def __init__(self):
pass
assetNode = pm.PyNode(assetName)
shapes = assetNode.listRelatives(ad=True, type='shape')
assert not shapes, "There are no shapes"
geometry = []
for shape in shapes:
geometry.append(shape.getParent())
import pymel.core as pm
import sgtk
import re
sceneName = pm.sceneName()
tk = sgtk.sgtk_from_path(sceneName)
context = tk.context_from_path(sceneName)
assetName = context.entity['name']
filters = [['project', 'is', context.project],
['id', 'is', context.entity['id']]
]
fields = ['sg_asset_variants', 'parents', 'assets']
entity_asset = tk.shotgun.find_one('Asset', filters=filters, fields=fields)
entity_asset
# Result: {'assets': [],
# 'id': 2052,
# 'parents': [],
# 'sg_asset_variants': 'A, B, C',
# 'type': 'Asset'} #
def parse_variants(data):
# pattern_asset_variants = r""""""
# re.match(pattern_asset_variants, entity_asset['sg_asset_variants'])
return data.split(', ')
variants = parse_variants(entity_asset['sg_asset_variants'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment