Scripting Functionality Problems

Issue #734 closed
Jarreth Weiler created an issue

I am unable to call bpy.ops.daz.import_custom_morphs(), or anything that should be using import_daz.set_selection(), without receiving the no morphs selected message. I followed the instructions here: http://diffeomorphic.blogspot.com/2020/07/more-on-scripting.html

As well, looked through most blogs, and through commits. The documentation is also inconsistent, with setSelection being used even in the most recent posts, despite not existing in the scripts.

This makes it essentially impossible to use scripting functionality that uses external files as far as I can tell.

Edit: It seems the first stopping point is that G.theFilePaths returns [] when used in the import_custom_morphs() command, in the getMultiFiles, called from fileutils.py. Similarly, calling get_selection from this context also doesn’t work. This seems to be why set and get selection can function in editor, but the command doesn’t get it.

Comments (21)

  1. Jarreth Weiler reporter

    I manually passed in a list of strings with full filepaths into the places G.theFilePaths was being used, and I can confirm it now functions. It seems that globvars doesn’t work in certain places. Happy I have a temporary fix, and I hope this helps.

  2. Thomas Larsson repo owner

    Scripting hasn’t been given any attention for a while, and some thing have changed since I last wrote about it. The scripting docs should be up-to-date for version 1.6.0:

    All functions intended for external use are defined in api.py, so look there for a really up-to-date info.

    I started a new repo for sample scripts. They idea is that they should work both as a set of examples and as a test suite.

    https://bitbucket.org/Diffeomorphic/daz-importer-scripts/

    Some day I should write an up-to-date blog post about scripting.

  3. Jarreth Weiler reporter

    So does your test suite work for you? Because it doesn’t work for me. G.theFilePaths still returns [] when your function asks for it, despite it returning the proper value in the console.

  4. Thomas Larsson repo owner

    All sample scripts work for me, yes.

    You are not really supposed to use G.theFilePaths directly; the sample scripts use import_daz.set_selection instead. It should be use immediately before you call an operator that takes multiple inputs, to pass arguments that would otherwise be chosen in a file selector or popup. After the operator has been executed, the selection is empty; you need to set a new selection for the next operator. So the get_selection function isn’t really useful.

    You can think of the selection as an extra argument to the next operator. So

    import_daz.set_selection(paths)
    bpy.ops.daz.import_units()

    morally means the same as

    bpy.ops.daz.import_units(selection=paths)

    The reason why it is not done in the latter way is that I want to pass a plain list of strings, but keyword arguments for Blender operators must be properties.

  5. Jarreth Weiler reporter

    As I said, your scripts don’t work for me due to G.theFilePaths not returning a value when the addon itself tries to return values from it internally, for example within morphing.py.

    If it is working on your end, but not mine, then I’m unsure of what to do, but I guess it might be some sort of addon conflict?

    My solution is the same as bpy.ops.daz.import_units(selection=paths) for now. I simply pass a string into a string property and split it, checking if it’s empty, and if it is, I use the old code.

    Still, thank you for updating the documentation. Your work has otherwise been incredibly helpful.

  6. Jarreth Weiler reporter

    It’s really that simple. I have the mesh selected, and it returns the daz error “no morphs selected”
    When I say it’s G.theFilePaths not returning a value, it’s because I modified the addon to include a print for it when it’s used, and it returns [].

  7. Thomas Larsson repo owner

    OK, now I see what you mean. The purpose of the file selection is to act as an extra argument to the next operator, so it makes little sense to access the selection after the operator has finished. But the get_selection() function is there, so either it should be removed or made to work properly. With the last commit the current selection is maintained across operators.

  8. Thomas Larsson repo owner

    Strange. Assuming that the path is correct and that the dsf file actually contains a morph, which it should given its location, it should work. The latest update is more forgiving (you can separate directories with backslash and use paths relative to the DAZ root paths), but your code should have worked before those changes.

    Does my test file work for you (after editing the root path)?

  9. Jarreth Weiler reporter

    It did not work.

    Traceback (most recent call last):
    File "\Text", line 19, in <module>
    AttributeError: module 'import_daz' has no attribute 'get_absolute_paths'
    Error: Python script failed, check the message in the system console

  10. Thomas Larsson repo owner

    Are you sure that you are using the latest development build? In particular:

    get_absolute_paths is defined in api.py, line 152.

    Everything in api.py is imported into the top module in __init__.py, line 79.

  11. Alessandro Padovani

    @Jarreth Just to check, are you using blender 2.93 ? Because 3.0 is not supported yet.

  12. Jarreth Weiler reporter

    Missed the reply, and yes I was using the most recent development build when I checked. I’ll do some tests tomorrow.

  13. Log in to comment