How do I run import_action in a script while giving it a file name

Issue #1562 resolved
Joe Morris @ FAST Animation Studio Toolz created an issue

I got this class that I'm trying to run and I wondered if you guys could give me a little help you know developer to developer:

I'm trying to pass a file path to import_action but can't really figure out how to do that could you guys edit the import action part of my code so it will import from a file path…😁

class SSM_OT_diffeomorphic_one(bpy.types.Operator):
    """First Diffeomorphic Task"""
    bl_idname = "ssm.diffeomorphic_one"
    bl_label = "Diffeomorphic One"
    bl_options = {"REGISTER",}

    _timer = None
    loading_complete = False  # Flag to track loading completion

    def execute(self, context):
        self._timer = context.window_manager.event_timer_add(1.0, window=context.window)
        context.window_manager.modal_handler_add(self)

        bpy.ops.daz.easy_import_daz('INVOKE_DEFAULT')

        return {'RUNNING_MODAL'}

    def modal(self, context, event):
        if event.type in {'CANCELLED'}:
            context.window_manager.event_timer_remove(self._timer)
            return {'CANCELLED'}

        if event.type == 'TIMER':
            # Check console output here
            for line in console_output.contents.split('\n'):
                if r"File C:\Users\W\Desktop\EFFIECENCY EXPERT 3\DAZ\1.duf loaded in" in line:
                    self.loading_complete = True
                    print("Match found in console output!")  # Debug print statement
                    break
                
        if self.loading_complete:
            bpy.ops.daz.import_duf(filepath="C:/Users/W/Desktop/EFFIECENCY EXPERT 3/POSE/I could use some fresh towels.duf")
            context.window_manager.event_timer_remove(self._timer)
            return {'FINISHED'}

        return {'PASS_THROUGH'}

    def cancel(self, context):
        if self._timer:
            context.window_manager.event_timer_remove(self._timer)
            self._timer = None

Comments (19)

  1. Thomas Larsson repo owner

    Well, that code makes my head spin. I never try to invoke an operator, but would execute it instead. The output of the file selector can be set with the function import_daz.set_selection, which you call immediately before executing the operator. This piece of code easy-imports a character and then imports an action to it.

    import bpy
    import import_daz
    
    theDufFile = "D:/home/bugs/genesis/G8/g8f.duf"
    theActionFile = "C:/Users/Public/Documents/My DAZ 3D Library/people/genesis 8 female/Poses/Base Poses/Base Pose Kneeling B.duf"
    
    import_daz.set_silent_mode(True)
    import_daz.set_selection([theDufFile])
    bpy.ops.daz.easy_import_daz()
    
    import_daz.set_selection([theActionFile])
    bpy.ops.daz.import_action()
    

    That said, there was actually a bug in bpy.ops.daz.import_action which prevented the file from being loaded. Now fixed.

    The special functions defined by the plugin are listed in https://bitbucket.org/Diffeomorphic/import_daz/wiki/Scripting/DAZ Importer Functions. You can find a similar example in the Sample Scripts repo, called easy_import.py.

  2. Thomas Larsson repo owner

    It turned out that several of the sample scripts did not work with the latest version. Both the sample scripts and the plugin needed some fixes.

  3. Joe Morris @ FAST Animation Studio Toolz reporter

    Thank you so much you created an API… that is so perfect…..…….you are so nice to do that for people OK can you tell me do I need to redownload the latest version 1.7 because of that error fix or would that error fix still be in the development version

  4. Joe Morris @ FAST Animation Studio Toolz reporter

    Thank you so much I figured out oh the reason why my super solid mode add-on wasn't getting too many sales it's because nobody can tell what it does I'm gonna split off one of the world class features that aren't available anywhere else the automatic keying of green screen video and sell that as its own separate add-on as well as the Google F3 voice search… use the money and leverage this new API that you provided oh after I rebrand from super solid mode to I think to sitcom maker or something like that but I'm gonna use this new API that you provided and your add-on itself as an engine for the ultimate in fast video production content so one person by themselves could theoretically make their own sitcom in blender…. I'm pretty good at programming Python now and I got the best programmer in the world on my team so it should be like really really polished and really supreme so I thank you very much for this API

  5. Joe Morris @ FAST Animation Studio Toolz reporter

    So I already have my add-on installing the stable version of diffeomorphic when it's installed but I guess I'll switch to the development version then and then I'll be constantly working with your code in huge like 4 gigabyte scenes with a bunch of stuff in it and so I'll be constantly testing all the angles of features you provide so I'll be able to post back errors from a real production environment…. When you break it down with your new API diffeomorphic is an awesome engine for exactly the kind of thing I'm trying to do I'm just gonna automate the processes take out the guesswork remove chances of error because a lot of people that approach diffeomorphic find it too complex in some areas some things are hard for people… but the great thing is when all the hard stuff is done and taken out of the mix with my sitcom maker out on then it will be a chance where I could actually oh focus on the acting and the comedy of my creations and other people can too there will be a real engine not that yours isn't like extremely awesome already which it is but there will be an even more streamline tool that people could use to create large amounts of video content quickly which is important to grow a YouTube channel or in business to make business presentations or advertisements anything and as always if you see any functionality I think I gave you my gum road free code but if I didn't I'll give it again if you see any functionality you want that you think would improve diffeomorphic it's yours just take it and if you could send me a message to one of my comments I'll get it one of my comments here that you've done it and I'll just remove that functionality from my add-on….. Then after I uh really figure this out and really make my creation an automatic tool oh the next step utilizing diffeomorphic of course and other tools is to break apart ian huberts processes and automate as much as of what he does as possible and create a Hollywood movie maker add on…. The more button clicks you take out of these processes in diffeomorphic the stronger a tool it is for business… I mean mimic may not be perfect for lip sync but it's really awesome and the way you have it set up in diffeomorphic it takes like 5 minutes to make a lip sync animation like totally perfect

  6. Joe Morris @ FAST Animation Studio Toolz reporter

    And if there is any way you could put diffeomorphic in 3D view instead of import in add on preferences that would be such a lifesaver I just hate that extra button click taking the 10 seconds to reach up and type daz…. I think everywhere we could take button clicks out of processes makes it way more fun

  7. Joe Morris @ FAST Animation Studio Toolz reporter

    Do you guys increment the number between development versions like whenever you update development version

  8. Joe Morris @ FAST Animation Studio Toolz reporter

    Is the code you provided supposed to run in the scripting editor because I keep getting module not found on import_daz…. Running it from the scripting editor with diffeomorphic development version installed and also running it from within my add-on I added some try and accept oh around it try and EXCEPT around it like when I normally do but it seems like the code you gave me should run from the scripting editor with diffimorphic installed

  9. Joe Morris @ FAST Animation Studio Toolz reporter

    OK the import_daz line works in blender 1.7 but not dev…………………………… I noticed when installing your dev add-on in my code I couldn't use import_daz for the module name it was Diffeomorphic-import_daz-52c5e820d696 there was required to install and enable your add-on in code… I don't know if that's relevant or I got the wrong development version if there is more than one version online

  10. Joe Morris @ FAST Animation Studio Toolz reporter

    But as you stated in version 1.7 the code just doesn't work so after entering the file path in your easy import dazz script nothing was imported

  11. Noel Lang

    You need to rename “Diffeomorphic-import_daz-52c5e820d696” in the addons folder (in AppData) to import_daz.

  12. Alessandro Padovani

    @Thomas Larsson Personally I always install by hand and rename the folder to “import_daz“, but I see a number of users having issues with the installation because of the strange name in the zip folder “diffeomorphic-import_daz-<release>“. Would it be possible to do the distribution just with “import_daz“ in the zip ?

  13. Thomas Larsson repo owner

    No, I don’t think so. Bitbucket adds the release number automatically and I don’t think it is possible to avoid that. But I could add a line to the docs, just below the link to the zip file.

  14. Joe Morris @ FAST Animation Studio Toolz reporter

    Thank you so much for providing that API with too many commands to even Scroll down and comfortably look at if you guys could see it from my eyes you would know this is a true engine for incredibly fast animation production…….using your API soon I'm gonna research the possibilities involving getting chatGPT involved on this and iterate over your API like the coolest way I can imagine… there's already ChatGPT material creation…. imagine saying ChatGPT add a denim material to Victoria 8.1 pants and it works I already have the Google Voice recognition in my add-on so you won't even have to type… there's already a video about mesh creation with the artificial intelligence what about a researching mesh fixing like the Bmesh blender add-on does but like ChatGPT because some daz models need fixing

    I spent a lot of time on my Google Voice recognition I think I gave you guys the free code if you wanna rob that and add voice functionality to diffeomorphic…. I'll also post back when I have ChatGPT functionality I already have openCV functionality but you have to use some sort of computer vision object detection…. And there's a ways to retrieve the coordinates of items in the viewport and feed it to open CV I just haven't done it yet… I know big words but we're in the artificial intelligence age and ChatGPT 4 will just write all this stuff for you anyways might as well think big now ….(if you don't know yet on blender code if ChatGPT messes up a line and the console tells you what line it is …find the command by Googling likely it's from an old version blender ….find what the right command IS in the latest version of blender…. pull up that page of the API paste the entire page into chat GPT or as much as you can and tell it in natural language that's what you did… that's the most streamlined process I found so far you could optimize your processes in development by acting more as prompt engineers) Remember you could steal anything you want from my add-on and it will just make me feel like I'm helping…. I got an update on my activate diffuse that I was told should be way better and iterate through group nodes no problem so you're activate diffuse ….if you want that when I get finished…. could be upgraded to just work on all blender models even better.

  15. Log in to comment