Commandline Script

How we can run a dazscript using commandline that will be executed AFTER all UI loaded and ready? normally it will run BEFORE UI loaded.

Post edited by MehdiZangenehBar on

Comments

  • OmnifluxOmniflux Posts: 427

    I have not noticed this. Have you tried waiting for the DzMainWindow::started() signal?

  • MehdiZangenehBarMehdiZangenehBar Posts: 140
    edited June 5
    MessageBox.information("Debug Message 001", "", "OK");
    
    function show_debug_message()
    {
    	MessageBox.information("Debug Message 002", "", "OK");
    }
    
    var main_window = MainWindow;
    main_window.started.connect
    (
        function()
        {
            show_debug_message()
        }
    )
    


    Dosn't work, first message box will raise, but second messagebox will not raise.

    Post edited by MehdiZangenehBar on
  • MehdiZangenehBarMehdiZangenehBar Posts: 140
    edited June 5

    ok, but none of the methods works for me, would you please show me a working example?
     

    function show_debug_message()
    {
        MessageBox.information("Application Startup", "Daz Studio has finished initializing. You can start working now.", "OK");
    }
    connect(App, "starting", this, "show_debug_message");
    
     
    function show_debug_message()
    {
        MessageBox.information("Application Startup", "Daz Studio has finished initializing. You can start working now.", "OK");
    }
    connect(DzMainWindow, "started", this, "show_debug_message");
    
    Post edited by MehdiZangenehBar on
  • OmnifluxOmniflux Posts: 427

    Use [object].scriptConnect, not [object].connect, as the latter is deprecated and can cause a memory leak if not used carefully (see the link Richard posted).

    MainWindow.started.scriptConnect(show_debug_message);

    I just tested this however, and it does not execute because the command line script is not run until after those two signals are sent; it appears they are available only for plugins.

    From everything I can see, the UI is ready at the point the script is run. What are you doing that it appears the script is running before the UI is ready?

  • MehdiZangenehBarMehdiZangenehBar Posts: 140
    edited June 6

    I want to locate a product in Smart Content pane, I got error. (normally when Daz is open, it works perfectly)
    It seems NONE of the callbacks works! can you show me frame change callback for example? (without dialog)

    Post edited by MehdiZangenehBar on
  • MehdiZangenehBarMehdiZangenehBar Posts: 140
    edited June 6

    This is the code by the way:
     

    var product_guid = "2dfde346-2098-4485-afc1-cab905333acd";
    var asset_manager = App.getAssetMgr();
    var product = asset_manager.findProductByGuid(product_guid);
    var pane_manager = MainWindow.getPaneMgr();
    var smart_content_pane = pane_manager.findPane("DzSmartContentPane");
    smart_content_pane.showProductInProductContentTab(product);
    

    Maybe I used wrong method? because showProductInProductContentTab is not officially listed. if yes, what is the correct method? Error:

    the chosen product(s) could not be found with the current filtering option
    
    Note that this code works perfectly when Dazstudio is already opened.
    Post edited by MehdiZangenehBar on
  • Richard HaseltineRichard Haseltine Posts: 107,953

    You may be waiting for the database to fire up, rather than the UI - it isn't complaining that it can't find the pane (in cases like this I would put a pront line after each real code line so the log can show how far it has got, and any unexpected results).

  • OmnifluxOmniflux Posts: 427

    If Richard is correct and you are waiting for the database (CMS), you could try checking DzAssetMgr::isConnectedToCMS() and waiting for the DzAssetMgr::cmsStarted() signal if not.

  • Would you please show me an example that will raise a messagebox when DzAssetMgr::cmsStarted()?

  • OmnifluxOmniflux Posts: 427
    function thingToDo()
    {
    	MessageBox.information("Test Script", "Doing thing.", "OK");
    }
    
    
    var oAssetMgr = App.getAssetMgr();
    if (oAssetMgr.isConnectedToCMS())
    {
    	thingToDo();
    }
    else
    {
    	var oCallBack = App.getCallBackMgr().createCallBack("Test Script");
    	oCallBack.setDeleteAfterExecution(true);
    	oCallBack.setConnection(oAssetMgr, "cmsStarted()");
    	oCallBack.setScriptFunction(thingToDo);
    }
    
  • Omniflux said:

    function thingToDo()
    {
    	MessageBox.information("Test Script", "Doing thing.", "OK");
    }
    
    
    var oAssetMgr = App.getAssetMgr();
    if (oAssetMgr.isConnectedToCMS())
    {
    	thingToDo();
    }
    else
    {
    	var oCallBack = App.getCallBackMgr().createCallBack("Test Script");
    	oCallBack.setDeleteAfterExecution(true);
    	oCallBack.setConnection(oAssetMgr, "cmsStarted()");
    	oCallBack.setScriptFunction(thingToDo);
    }
    

    First part will be executed, but the callback? NO
    That is the point. cmsStarted will be called before startup script run and UI will be loaded after. this startup sequence cause we can't write a startup script that will manupulate the UI. However if you think this is working, please pick a guid from one of your installed product in Smart Content, then test this code:

     

    function thingToDo()
    {
    	MessageBox.information("Test Script", "Doing thing.", "OK");
    	var product_guid = "b95d7185-d8b4-4011-947a-f55a20c5eecb";
    	var asset_manager = App.getAssetMgr();
    	var product = asset_manager.findProductByGuid(product_guid);
    	var pane_manager = MainWindow.getPaneMgr();
    	var smart_content_pane = pane_manager.findPane("DzSmartContentPane");
    	smart_content_pane.showProductInProductContentTab(product);
    }
    var oAssetMgr = App.getAssetMgr();
    var oCallBack = App.getCallBackMgr().createCallBack("Test Script");
    oCallBack.setDeleteAfterExecution(true);
    oCallBack.setConnection(oAssetMgr, "cmsStarted()");
    oCallBack.setScriptFunction(thingToDo);
    
  • OmnifluxOmniflux Posts: 427

    I think I've been trying to solve the wrong problem, and besides not being able to reproduce it, this should have clued me in earlier

    MehdiZangenehBar said:

    Error:

    the chosen product(s) could not be found with the current filtering option
    

    Can you try this

    (function(){
    	var sProductGUID = "fb63882b-4498-4215-bfa0-b2eef88eb3f7";	// Default Resources for DAZ Studio
    	
    	var oAssetMgr = App.getAssetMgr();
    	if (oAssetMgr)
    	{
    		if (oAssetMgr.isConnectedToCMS())
    		{
    			var oProductAssetContainer = oAssetMgr.findProductByGuid(sProductGUID);
    			if (oProductAssetContainer)
    			{
    				var oPane = MainWindow.getPaneMgr().findPane("DzSmartContentPane");
    				if (oPane)
    				{
    					var oProductContentTab = oPane.getProductContentTab();
    					if (oProductContentTab)
    					{
    						oProductContentTab.setCurrentFilter("");
    						oProductContentTab.setInstallStateFilterFlags(31);
    						oPane.showPane();
    						oPane.showProductInProductContentTab(oProductAssetContainer);
    					}
    					else
    						MessageBox.warning("Smart Content Product Content Tab not found.", "Error", "OK");
    				}
    				else
    					MessageBox.warning("Smart Content Pane not found.", "Error", "OK");
    			}
    			else
    				MessageBox.warning("No product found with GUID:\n\n%1".arg(sProductGUID), "Error", "OK");
    		}
    		else
    			MessageBox.warning("Not connected to CMS.", "Error", "OK");
    	}
    	else
    		MessageBox.warning("Asset Manager not found.", "Error", "OK");
    })();
    
  • MehdiZangenehBarMehdiZangenehBar Posts: 140
    edited June 7

    Omniflux said:

    I think I've been trying to solve the wrong problem, and besides not being able to reproduce it, this should have clued me in earlier

    MehdiZangenehBar said:

    Error:

    the chosen product(s) could not be found with the current filtering option
    

    Can you try this

    (function(){
    	var sProductGUID = "fb63882b-4498-4215-bfa0-b2eef88eb3f7";	// Default Resources for DAZ Studio
    	
    	var oAssetMgr = App.getAssetMgr();
    	if (oAssetMgr)
    	{
    		if (oAssetMgr.isConnectedToCMS())
    		{
    			var oProductAssetContainer = oAssetMgr.findProductByGuid(sProductGUID);
    			if (oProductAssetContainer)
    			{
    				var oPane = MainWindow.getPaneMgr().findPane("DzSmartContentPane");
    				if (oPane)
    				{
    					var oProductContentTab = oPane.getProductContentTab();
    					if (oProductContentTab)
    					{
    						oProductContentTab.setCurrentFilter("");
    						oProductContentTab.setInstallStateFilterFlags(31);
    						oPane.showPane();
    						oPane.showProductInProductContentTab(oProductAssetContainer);
    					}
    					else
    						MessageBox.warning("Smart Content Product Content Tab not found.", "Error", "OK");
    				}
    				else
    					MessageBox.warning("Smart Content Pane not found.", "Error", "OK");
    			}
    			else
    				MessageBox.warning("No product found with GUID:\n\n%1".arg(sProductGUID), "Error", "OK");
    		}
    		else
    			MessageBox.warning("Not connected to CMS.", "Error", "OK");
    	}
    	else
    		MessageBox.warning("Asset Manager not found.", "Error", "OK");
    })();
    

    I just replaced the guid with one on my products id (I didn't installed default Daz contents), and none of the messageboxes pops up, again I recieved :

    the chosen product(s) could not be found with the current filtering option
    

    Is this code works in your side? what message you got?

    Post edited by MehdiZangenehBar on
  • MehdiZangenehBarMehdiZangenehBar Posts: 140
    edited June 7

    i just got that message in another case. this time is not about callback or startup, when i double click on product and smart content pane is showing the asset inside that product, if i run the 

    showProductInProductContentTab
    

     

    again, i got the error:

     

    the chosen product(s) could not be found with the current filtering option
    
    Post edited by MehdiZangenehBar on
  • OmnifluxOmniflux Posts: 427

    Yes, this code works for me, but so does your original code. I close DS, then launch it like this

    C:\Users\Omniflux>"C:\Program Files\DAZ 3D\DAZStudio4\DAZStudio.exe" test.dsa

    DS launches, then switches to the Smart Content Pane and auto navigates to the product (it does not switch to the content pane with your original code, but does navigate to the product in the hidden pane).

     

    There are two filters that I could set to cause this error (although not at launch, only when DS was already running) and I cleared them in the script I posted. I could not cause the error with the other two filters, but you could try clearing them as well.

    oProductContentTab.setTypeFilters([]);
    oProductContentTab.setFilterByContext(false);

    This is an undocumented object, so there could be other filters I am missing as well...

Sign In or Register to comment.