How can we access to context.data outside of process method? [Solved]


#1

Hello guys
After a long time i back to ask a question.

problem:

My problem here is that we have two step publishing with pyblish, from wip to publish folder that give the file version, date, and name of author, after that supervisor will open the first level published file and check it and again will publish in final folder.
now i want to change it to one step for supervisors, it means that when supervisor opened the wip version of file he can publish it in one step but into two place.

now i want to know that can i hide an integrator or validator or extractor from pyblish gui with having a series of conditions on families?

it means, based on some conditions, can i change families in the body of my plugin?

here, for example, i have a collector that will text that a user can save a file in final folder or not (he is supervisor or not), then based on it will save a data in context (context.data[“fullPermission”].
i want to know that can i access to the data inside my plugin, and outside of process method?

Sample Code:

Collect_permission_new.py :

import pyblish.api

class CollectPermissionNew(pyblish.api.ContextPlugin):
    ''''''
    order = pyblish.api.CollectorOrder
    hosts = ["maya"]
    label = "Collect Permission"

    def process(self, context):
        context.data['fullPermission'] = False
        # context.data['fullPermission'] = True
        self.log.info('fullPermission: %s' % context.data['fullPermission'])

validate_test_collector_new.py :

import pyblish.api


class ValidateTestCollectorNew(pyblish.api.InstancePlugin):
    ''''''
    order = pyblish.api.ValidatorOrder

    if context.data['fullPermission']:
        families = ['anr2.model',
                'anr2.model.final']
    else:
        families = []

    hosts = ['maya']
    optional = True
    version = (0, 0, 1)
    label = "++TEST++"

    def process(self, instance):
        self.log.info('Processing...')

this snippet does not work

    if context.data['fullPermission']:
        families = ['anr2.model',
                'anr2.model.final']
    else:
        families = []

because we can’t access to context.data["..."] in body of plugin.

do you think there is a way to do that and can change families??

thanks


#2

Hi @Mahmoodreza_Aarabi,

Would it be possible to move your if logic to the process method?

from pyblish import api


class CollectPermissionNew(api.ContextPlugin):
    order = api.CollectorOrder - 0.1

    def process(self, context):
        context.data["fullPermission"] = False
        # context.data["fullPermission"] = True


class CollectInstances(api.ContextPlugin):
    order = api.CollectorOrder

    def process(self, context):
        instance = context.create_instance("MyInstance")
        instance.data["families"] = ["anr2.model"]

        if context.data["fullPermission"]:
            instance.data["families"].append("anr2.model.final")


class ValidateModel(api.InstancePlugin):
    order = api.ValidatorOrder
    families = ["anr2.model"]

    def process(self, instance):
        self.log.info("Validating model..")


class ValidateModelFinal(api.InstancePlugin):
    order = api.ValidatorOrder
    families = ["anr2.model.final"]

    def process(self, instance):
        self.log.info("Validating final model..")


api.register_plugin(CollectPermissionNew)
api.register_plugin(CollectInstances)
api.register_plugin(ValidateModel)
api.register_plugin(ValidateModelFinal)


from pyblish import util
context = util.publish()

for result in context.data["results"]:
    for record in result["records"]:
        print(record.msg)

Now you can control the inclusion of ValidateModelFinal by toggling the fullPermission boolean.


#3

Hello @marcus
Thanks for reply.
If it give me the toggle between showing or hiding our integrator or validator, yes, i can use it in process.
but in GUI i don’t know it does it for me or not.

Unfortunately i’m not at work to test it now, but do you think when a plugin is showing in list of plugins for a family can we hide it based on a context.data?

i mean when we want to process a plugin, we have it in our list, so how can we hide it from list when we are processing it?

make sense?


#4

this is good idea to handle a family inside CollectInstance, i hope it works for me, i have to test it tomorrow and continue to talk.
i will be appriciated if you be here tomorrow.


#5

Yes, in pyblish-qml plug-ins are automatically hidden if there is no instance with a compatible family. In pyblish-lite however it does not. @p4vv37 is working on this here.


#6

I should say that i’m using Pyblish 1.3.1 yet
it works on it?
i didn’t upgrade yet.


#7

and now i found that this line does not work for me
context = util.publish()

is it related to version of my publish?


#8

Yes, this will work with 1.0 and above.


#9

context = util.publish()
error:
# Error: AttributeError: file <maya console> line 1: 'module' object has no attribute 'publish' #


#10

BTW, i will test it tomorrow
i think it will work.
thanks man
see ya


#11

My problem solved, i did this way and it works good
thanks


#12

Excellent, happy to help!