Convert to SubD script

I`d like to include a script to convert the selected item to SubD.

Actually, the idea is to create presets so the user can toggle between 0 and 1 subdivisions for the selected item.

I don`t know where to look at, so I would appreciate a help with this, please.

Comments

  • jag11jag11 Posts: 885

    The first thing that comes to my mind is trigger the DzSubDAction, then through properties change the subdivision values.

    Here is simple code to trigger an action.

  • algovincianalgovincian Posts: 2,562
    edited September 2017
    Hellboy said:

    I`d like to include a script to convert the selected item to SubD.

    Actually, the idea is to create presets so the user can toggle between 0 and 1 subdivisions for the selected item.

    I don`t know where to look at, so I would appreciate a help with this, please.

    This should give you an idea how you can set the properties you're looking for, Hellboy:

    var nodes = Scene.getSelectedNodeList();
    var n = nodes.length;

    for( var i = 0; i < n; i++ )
    {
        var oObject = nodes[i].getObject();
        if( oObject )
        {
            var oShape = oObject.getCurrentShape();
            if( oShape )
            {
                oProp = oShape.findPropertyByLabel("SubDivision Level");
                if ( oProp )
                {
                    oProp.setValue(0);
                }
            }
        }
    }

     

    Hope this helps.

    - Greg

    Post edited by algovincian on
  • HellboyHellboy Posts: 1,437

    Oh yes! It does help indeed! This is really helpful.

    Thanks to you both! :D

  • Hello!!!

    I was looking for this thing exactly... a way to have a script for ON OFF the SubD... but I am not too good as for writing this code or I am doing something wrong because it doesn´t work on me...

    How can I make these scripts??? Please help!

    Fabi

  • jag11jag11 Posts: 885
    edited November 2017

    I modified algovincian's code to check if SubD has been applied, then sets the desired sub level, you can turn off SubD by setting the value to 0, or turn it on by setting a desired level from 1 to 5.

    Just copy this snippet to a script file(.DSA)

    (function () {	var actionMgr = MainWindow.getActionMgr();	var action = null;	/* SubDLevel value meaning		0 = OFF		1 to 5 = ON	*/	var subDLevel = 2; // &lt;&lt;&lt; set your desired value	var nodes = Scene.getSelectedNodeList();	var n = nodes.length;	for (var i = 0; i &lt; n; i++) {		var oObject = nodes[i].getObject();		if (oObject) {			if ((oShape = oObject.getCurrentShape())) {				if ((oProp = oShape.findProperty("lodlevel")) 					&amp;&amp; oProp.getNumItems() == 1 &amp;&amp; (action = actionMgr.findAction("DzSubDAction"))) {					action.trigger();				}				if ((oProp = oShape.findProperty("SubDIALevel"))) {					oProp.setValue(subDLevel);				}			}		}	}})();

     

    Post edited by jag11 on
  • thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    Thank you for this script.

    I want to start with scripting and picked this example to understand what this does.

    However I tried it to also set the Resolution Level to Base with no succes. There are a few things I want to know - but my fist question is:

    You asking for "oShape.findProperty("lodlevel")) && oProp.getNumItems() && actionMgr.findAction()" but Property "lodlevel" Resolution Level keeps in High Resolution state after this script.

    Now I want to set the Property "lodlevel" Resolution Level to Base - but I cant set lodlevel=Resolution Level to My_MeshResLevel = 0 why? [Edit]: [Solved]

    See my Example:

    // DAZ Studio version 4.10.0.107 filetype DAZ Script/********************************************************************** 	No Copyright (C) 2002-2017 Daz 3D, Inc. No Rights Reserved. No warranty of any kind. 	This script is provided as part of the &gt;&gt; Daz Script Developer Discussion &gt;&gt; Convert to SubD script	Thread opener OP:  Hellboy @ September 15 - 2017	- Post by: algovincian @ September 18	- Post by: jag11 @ November 27  	To contact Daz 3D or for more information about Daz Script visit the	Daz 3D website: 	- http://www.daz3d.com	**********************************************************************	Modification of the original Script Example / code snippet:	- Idea by: algovincian @ September 18	- Mod by: jag11 @ November 27 **********************************************************************		FileName: SubDivLevel-MeshResLevel_SetTo0.dsa	by Syrus_Dante @ 2017-12-14 **********************************************************************/// Source: https://www.daz3d.com/forums/discussion/197936/convert-to-subd-script// Define an anonymous function;// serves as our main loop,// limits the scope of variables(function () {	var actionMgr = MainWindow.getActionMgr();	var action = null;	/* SubDLevel value meaning		0 = OFF		1 to 5 = ON		Resolution Level value meaning ???		0 = Base		1 = High Resolution	*/	var My_subDLevel = 0;			// &lt;&lt;&lt; set your desired value for Property: View SubD Level (Render SubD Level will also be set)	var My_MeshResLevel = 0;	// &lt;&lt;&lt; set your desired value for Property: Resolution Level	var nodes = Scene.getSelectedNodeList();	var n = nodes.length;	for (var i = 0; i &lt; n; i++) {		var oObject = nodes[i].getObject();		if (oObject) {			if ((oShape = oObject.getCurrentShape())) {				if ((oProp = oShape.findProperty("lodlevel")) 					&amp;&amp; oProp.getNumItems() == 1 &amp;&amp; (action = actionMgr.findAction("DzSubDAction"))) {					action.trigger();				}				if ((oProp = oShape.findProperty("SubDIALevel"))) {					oProp.setValue(My_subDLevel);   //Set Property: View SubD Level				}				if ((oProp = oShape.findProperty("lodlevel"))) {					oProp.setValue(My_MeshResLevel);   //Set Property: Resolution Level				}			}		}	}})();

     

    Post edited by Syrus_Dante on
  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    ...sorry double post

    Post edited by Syrus_Dante on
  • jag11jag11 Posts: 885

    Excelente documentation.

    You are missing a closing paren.

     

    scrcap.PNG
    651 x 186 - 11K
  • Oh cool now its working laugh typical beginner mistake - forgive me its my fist one ever.

  • Syrus_DanteSyrus_Dante Posts: 983
    edited October 2018

    Hi,

    I want to show you my new completly reWritten version of this script Example. Therfore I have changed the FileName to this meaningful creation: ApplyOrZero_SubD_SubDivLevel_MeshResLevel.dsa

    I hope I could clean up this mess. I've also added a new idea I had as I read in this Example Script:

    Until now I have no Starter script to call this one to test the passed Arguments.

    But for now the Script IDE console tells me:

    Executing Script...
    general\dzscript.cpp(658): Unhandled error while executing script.
    QScriptEngine::popContext() doesn't match with pushContext()
    Result: 
    Script executed in 0 secs 655 msecs.

    Please help me with the Sring operations String.join () / String = text ("...") sad...and damn so much paren (((((...).).)).. wink

    //pass arguments to Apply - Or - Zero with no Arguments passed - at least I hope to get it to work this way - please comment if you have other suggestions.

     

     

    [Edit] 1: I've updated the code now the Script IDE tells me a not that fatal error anymore:

    Executing Script...

    Script Error: Line 40
    SyntaxError: Parse error
    Stack Trace: ()@:40
    Error executing script on line: 40 //its eigther the fist or the last line that shows me an error cant get anonymous function to run?

    Script executed in 0 secs 3 msecs.

    Still I cant get it to runsad - never could test anything in it - even I thought of a extended error detection - It should be foolproof to some extend now - with very detailed Infos in the resulting MessageBox.

     

     

    [Edit] 2: I've updated the code now the Script IDE tells me NO! error anymore but my MessageBox get showen at the end and the values get set:laugh

    Still no succes with passing Arguments I just dont know how the syntax should look for this to work. If I try I have eighter syntax error in the first or the last line.

    My other problem now is that I think I missused the String.Join () funcition no sMessage String is showen in the resulting MessageBox. I think I have to fill an ordenary array and then give it to sMessage in the last step. But still no luck.

    Please help I have no idea how to work with these strings? And "\n" is the "new line" symbol I thought or is it the strings last terminator symbol?

    eg. sMessage = String.join ( "This" + "This too" + "\n");

    eg. aMessage[aMessage.length + 1] = text (" ");

    eg. aMessage[nSucces + nError] = aMessage.concat (" ");

    eg. aMessage[nSucces + nError] = aMessage.join (" ");

    Maybe its better to just use print (""); to the console. But I would like to see what this scipt had done with my scene selection in the messagebox.

     

     

    [Edit] 3: I've updated the script finaly it does what it should. I've added some things and improved the code.

    Still no succes with passing Arguments but finaly a working version now.laugh

    Improvments:

    • the final messagebox is showing the detailed results now // wrong: InfoMsg = ( "this is a text message" ); right: InfoMsg ( "this is a text message" ); ...it took awhile until I get this.frown
    • Undo is now working the undo action is called "Change SubD Values on Selection" press Ctrl+Z and everything this script has done gets undone
    • even better error detection //Fool proof as I sayed - If you find an unhandled exception you have proofen you are not a fool wink
    • cleaned up and added some comment lines //yeah even this script is intended to read by Daz Studio its good to have some comments for humans to read so they may get what this script does - you can never have enougth comment lines
    • Added "bDebugConsole" switch to redirect the final message output to the console instead of showing the messagebox - Critical Error! messages show up in a messagebox

    Still much to improve. Im not happy with the formating of the messagebox output while I was writing this script without getting anything into the messagebox I was handling the text output more like a console output. I was experimenting with oObject.getLabel(); and oObject.getName(); but still it will show the label not the name of the item.

    To-Do:

    • passing Arguments
    • detect the label not the name of the object
    • maybe add the "get root node automation" if a figures bone is selected
    • maybe detect the name of the selected nodes with no geometry or skip to show erros for them

    See this example screenshot to get what I mean. I had Genesis 2 Female, a sphere, a cube, a Null and a Camera selected:

    Next I will have a closer look at the DzWidget Documentation. I would like to have something like this Action Accelerators for my final messagebox.

    Can I please borrow some of the DzWidget related Action Accelerators source code to have a propper listbox for the final message?

    I mean its a common userinterface element and if you look whats left from the other SubScript example code in my current script version - its basically the "function text( sText )" and the for-loop "for( var i = 0, nArgs = aArgs.length; i < nArgs; i += 1 )".

     

    I've skipped over to version 7 for this release now - maybe I should have thought of a better version numbering like v0.7beta for this.cheeky

    423 lines of code this time it dosnt fit into the Code Snippet container box anymore. It tells me Body is 2139 characters too long.

    Therfor no script preview anymore. Maybe better you dont have to scroll that long to the bottom of this thread by now. I wonder why you cant collapse this forums Code Snippet container by default?

    dsa
    dsa
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel.dsa
    8K
    dsa
    dsa
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v2.dsa
    12K
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v3.png
    166 x 111 - 20K
    dsa
    dsa
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v3.dsa
    14K
    dsa
    dsa
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v4.dsa
    15K
    dsa
    dsa
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v7.dsa
    20K
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v7_Succes1.png
    472 x 699 - 71K
    dsa
    dsa
    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v8.dsa
    22K
    Post edited by Syrus_Dante on
  • No Rights Reserved

    You can't use the sample scripts and make the result no rights reserved, the Open Source with Attribution license does plae restrictions (specifically that attribution must be given) on the script and anything derived from it.

    As for the error, we've seen that a couple of times - check that you are not redeclaring a variable inside a loop, especially if recursing.

  • jag11jag11 Posts: 885

    The for loop is not necessary, why dont just wrap the code like:

    var ConvertToSubDProgram = (function () {    function ConvertToSubDProgram() {    }    ConvertToSubDProgram.prototype.run = function (args) {        if (args.length != 2) {            this.notifyUser("wow wow wow!");            return;        }        try {            this.changeMeshResolution(parseFloat(args[0]), parseFloat(args[1]));        }        catch (e) {            this.notifyUser("WOW WOW WOW!");        }    };    ConvertToSubDProgram.prototype.changeMeshResolution = function (subDLevel, lodLevel) {    };    ConvertToSubDProgram.prototype.notifyUser = function (problem) {    };    return ConvertToSubDProgram;}());new ConvertToSubDProgram().run(getArguments());
  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    @jag11: Thanks, for the example code - this stuff is very useful to understand and can be quiet handy for bigger projects. Its like working with the include in Javascript or the C++ headers.h library.

    So instead of being lazy and run a anonymouse function you can define and descripe a whole set of functions.sub-functions within a single script file. If you have written a set of functions doing basic stuff you can work with them from outside in another script if you add the line: include( "MyCustomScriptsAndFunctions.dsa" ); on top you can add them to your next script project and write more advanced functions with them.

    Its this method of passing arguments that I'd like to understand - thats why I picked this SubScript Example.

    But I think I misunderstood the Callee_Script.dsa example. I thought the for-loop is necessary to determin the datatype of the passed arguments that are loosing their datatype by passed over in this string array that needs to be somehow detected and restored within this for-loop. But what I see now is that just for this special example the for-loop does convert all datatypes of the passed arguments to this sMessage string to see them in the Messagebox. And also "if ( nArgs > 0 )" dosnt makes sens in this for-loop I must have been half sleeping.

    Back to your script example: lets call it ConvertToSubD.dsa to use it in another script I just have to write this right?

    include( "ConvertToSubD.dsa" );var my_subDLevel = 2;   //View SubD Level: 2var my_lodLevel = 1;    //Resolution Level: High Resolutionif (ConvertToSubDProgram.changeMeshResolution (my_subDLevel, my_lodLevel)) {} else {   ConvertToSubDProgram.notifyUser ("Cant change Mesh Resolution!");};

    and this will give me two variables subDLevel, lodLevel ofType: float ???
    my_Array[i] = this.changeMeshResolution(parseFloat(args[0]), parseFloat(args[1]));

     

    @Richard Haseltine

    Sorry this was a joke - I'm not shure about this rights reversed thing but I wanted to include some header - copied the original DAZ one and added some lines to show the sources and inform about the modifications like from what I know the licence prescribes.

    As for the error, we've seen that a couple of times - check that you are not redeclaring a variable inside a loop, especially if recursing.

    Thanks for this good advice not to declare variables in loops now I see why - again a typical beginner mistake - dont show errors in the inspector console but can write a new variable to the memory with every loop I think.

    LOL its done even within the original code snippet:

    for (var i = 0; i &lt; n; i++) {		var oObject = nodes[i].getObject();};
    Post edited by Syrus_Dante on
  • Variables can be local, but I have had the pop context issue myself and sceen it from others and it seems to be related to having things out-of-scope in soem way, which redeclaring variables on each pass of a loop does seem prone to.

    As for licensing, it's important to remember that Rob is writing these sample script in his own time to help us get the most from DS, so beyond the simple legallity issue it's important to espect his wishes on usage. https://wiki.creativecommons.org/wiki/License_Versions#No_sublicensing explains that the license terms are set by the original author and can't be modifed by a subsequent user.

  • jag11jag11 Posts: 885
    edited December 2017

    Now I get what your are trying to do. Pick the stone according to the size of the toad. The previous skeleton code was designed to be called from another script.​​ The library code skeleton looks something like this:

    //supercoollibrary.dsavar MeshTools = (function () {    function MeshTools() {    }    MeshTools.changeMeshResolution = function (subDLevel, lodLevel) {        return null;    };    return MeshTools;}());

    ​To call functions inside your library, you need something just like this:

    //supercoolprogram.dsainclude();try {    MeshTools.changeMeshResolution(1, 3);}catch (e) {    this.notifyUser();}​

    MeshTools is defined like a static class and changeMeshResolution is a static method.

    Post edited by jag11 on
  • Variables can be local, but I have had the pop context issue myself and sceen it from others and it seems to be related to having things out-of-scope in soem way, which redeclaring variables on each pass of a loop does seem prone to.

    As for licensing, it's important to remember that Rob is writing these sample script in his own time to help us get the most from DS, so beyond the simple legallity issue it's important to espect his wishes on usage. https://wiki.creativecommons.org/wiki/License_Versions#No_sublicensing explains that the license terms are set by the original author and can't be modifed by a subsequent user.

    Apparently scope is never less than the function, so declaring the variables in the loop should be significant here. If you want to have a variable with limited scope you can use the same anonymous fnction technique used in most of the samples scripts within a function, though that will have an impact on performance.

    That's more of an aside than directly relevant, other than indicating that I was wrong to regard the location of your variable declarations as a plausible cause for the pop errors.

  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    See my [Edit] 2: I've updated the code now the Script IDE tells me NO! error anymore but my MessageBox get showen at the end and the values get set:laugh

     

    ApplyOrZero_SubD_SubDivLevel_MeshResLevel_v4.dsa

    I'm currently working on v5 that uses the undo Stack it works partialy but not for lodLevel for now.

     

    @Richard

    Dont worry about the QScriptEngine Error I did something completly wrong there - but it dosn't matter that much because with the new concept ideas from jag11 how to encapsulate the code I see that I have to do things different - much work to do and learn how to write working code now.

    I dont want to run into legallity issues here and I have great respect for robs work and wishes on usage. I only borrowed the source code of the Sub Script Example to demonstrate my new concept.

    I have included the licence URL and edited the legal notes with my update.


    @jag11

    You get it I aim for a much bigger plan than just get this "Convert to SubD Script" running.
    I would like to include some other code snippets that I saw in this forum and create a library for me and others to use and maintain.
    But it needs to be easy to use and with error detection and it should be foolproof to some extend.
    With messageboxes for the average user that can be switched to silent mode with bDebug or similar and print messages to the console for the script coders.
    Static Class MeshTools.. I dont know - how about SubD or is it allready in use?

    eg. SubD.ChangeViewSubDLevel (4);

    eg. SubD.ApplySubD();

     

    Post edited by Syrus_Dante on
  • jag11jag11 Posts: 885

    Name it whatever suits you best.

    As for error detection I prefer the old try/catch model, but if you validate enough, errors practically dissapear.

  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    I've updated my fourth post.

    [Edit] 3: I've updated the script finaly it does what it should.laugh I've added some things and improved the code.

    Post edited by Syrus_Dante on
  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    After a few more tests now with the current version v8 I see that it isn't that easy to tell if the SubD Modifierer is allready applied or not.

    Now I do the following: remember what the lodlevel was switched to before then try to switch it once off then on and see if this was possible - then turn it back to the remembered state it was before. Dose this make sense and whats the resulting state of lodlevel after this check? I'm a bit confused now this should be the best option for a workaround the other I can think of is checking if the View SubD level Property is hidden or not.

    The other thing is I'm surprised that its seems that I was able to undo the Convert to SubD action - maybe possible because the object wasn't saved as Content like a Figure/Prop Asset and its all just the current state in memory.

    See my current SubD check routine:

    // Check if the 'current' Selection / Node is an object with a shape//********************************************************************************if (oShape = oObject.getCurrentShape()) {	// Apply SubD (Convert To SubD)	//********************************************************************************	if ( ( Apply_SubD == true )		&amp;&amp; ( action = actionMgr.findAction("DzSubDAction") )		&amp;&amp; (oProp = oShape.findProperty("lodlevel") ) ) {		/********************************************************************************		if ( oShape.findProperty("SubDIALevel") )    //original check routine in v7		Property: View SubD Level found on 'current' Selection means SubD is allready applied		ERROR: the View SubD Level property is allready there all the time I think but hidden		SOLUTION: Now we remember the current setting set it to 0 then set it to 1		and if this was succesfully we know that the Selection is allready Converted to SubD		********************************************************************************/		if ( ( vCheckSubD = oProp.getValue("lodlevel") )			&amp;&amp; ( oProp.setValue( 0 ) )			&amp;&amp; ( oProp.setValue( 1 ) ) ) {			oProp.setValue( vCheckSubD );			ErrorMsg( "SubD is allready applied (Converted To SubD)", sObject, sType, "Apply_SubD = true", i );			} else {				action.trigger();	//Apply: SubD - DS-Action:[Convert to SubD...]				InfoMsg( "SubD applied (Convert To SubD)", sObject, sType, "Apply_SubD = true", i );				}		}else {			ErrorMsg( "Can't apply SubD (Convert To SubD)!", sObject, sType, "Apply_SubD = true", i );	}}

    Some checklist:

    • if ( ( oProp = oShape.findProperty("lodlevel") ) == true ){}; tells you that there is a Resolution Level Property this is true for all objects with geometry

    • vCheckSubD = oProp.getValue("lodlevel"); the value of vCheckSubD tells you if it is switched to Base = 0 or HighRes = 1

    • if ( ( oProp.setValue( 1 ) ) == false ){}; should tell you that it is not possible to set the value to HighRes = 1 because the object isn't yet Converted to SubD

    Post edited by Syrus_Dante on
  • jag11jag11 Posts: 885

    To find out if the SubD was already applied the code segment oProp.getNumItems() returns 1 only when it is not SubD'ed, after it is SubD'ed it must return 2 elements "Base" and "High Resolution".

    if ((oProp = oShape.findProperty("lodlevel"))            &amp;&amp; oProp.getNumItems() == 1             &amp;&amp; (action = actionMgr.findAction("DzSubDAction"))){     action.trigger();}

    Cheers

  • Ah thanks,

    and I thought of why to ask for Items because I only got the focus on one node - these Items != Scene Items.

    Slowly but continiously I get what these lines actually means.

  • Syrus_DanteSyrus_Dante Posts: 983
    edited December 2017

    So far so good

    With my current working version v8.2 I want to make things diffrent like before. Its time to break up all these long for loops and if/else condition chains all written into one continious anonymous function.

    You may had a look into my script v7 - I use the new functions InfoMsg ErrorMsg there - they do allot for me (write a single message line into the their Message array and count succes/error ) and by doing this, break up the task to manage into smaler tasks that are clearly layout.

    Currently I'm reaching the mark of 449 lines of script code - I'm loosing the overview by scrolling through especialy with the indents by tab stops. indecision

    I know, these are all just smale steps towards a final script program that should be well organized and follows the guidlines of a object orientated programming desing.

    I'm thankful for the suggestions from jag11 how wrap the code into seperate functions.
    My script function(s) isnt/arent yet able to be called from another script - but before that can happen I want to make shure the structure is well organized.

     

    External Script Editor Usage

    I dont use the Script IDE to write this - as long as the Script IDE pane dosnt jump into the line in wich the syntax error occured its not much of use - but to provide basic functionalities with the sytax error inspector.

    My tool of choice is https://en.wikipedia.org/wiki/UltraEdit current version 24 provides a solid scripting IDE interface.

    Key Features
    • <cite><var><samp>Facilitates the opening and editing of large files, up to 4GB and greater in size</samp></var></cite>

    • <cite><var><samp>Column (block) mode editing</samp></var></cite>

    • <cite><var><samp>Regular expression find and replace</samp></var></cite>

    • <cite><var><samp>Find/Replace in Files</samp></var></cite>

    • <cite><var><samp>Extensible code highlighting, with &#39;wordfiles&#39; already available for many languages&nbsp;</samp></var></cite>

    The Extensible code highlighting is customizable with Java or C++ settings its OK to work - maybe there could be a code highlighting for DazStudio Qt syntax?

    If you want to get real crazy you can use Find/Repace in Files to find and fix erros like wrong paths written in saved uncomressed *.duf files or use also their other tool -have a look at Ultra Compare.

    With all this - again some incompatibility between diffrent programs had to be fixed - so I had to reconfigure my script editor to use 4 instead of 3 spaces for a tab stop in DazStudio the tab stop is 4 spaces long and in the script snippet box the tabstop is huge 8 spaces long. On top of that - if you copy/paste code into the snippet box all //Commentlines jump way to far to the right - then you can delete tabs but not add them there.sad

    Sorry but this can mess up things quiet easy - especialy if you have to work with DazStudio in conjunction with the Script editor. And also copy paste code to the script snippet box.

    What I do is I load the script file *.dsa into the Script IDE pane and if I had made changes to the file with the extrenal script editor by Ctrl+S and want to test this script version I go to the IDE pane: File>Reload Script action or use my shortcut Ctrl+Shift+R to refresh the currently loaded file by DazStudio. This is one workaround I have found - one thing that I think is counter productive is that you cant drag&drop the script files *.dsa into the IDE pane from the Content Library. Maybe its possible to somehow trigger the action Reload Script if you switch tasks - like to hook Reload Script to some DzApp event?

     

    Questions about global / local declarations of variables acording to passed arguments in functions

    Its about what I did wrong in the first place - not knowing about the local/global scope of defining variables. With the following Example I want to show what I'm not shure of if there can occure conflicts with the names of global/local declarations. In this example nArgs, aArgs, aMessage are named the same in global and inside the local focus/scope of the Check_Args function - does DazStudio work with them like with local copys/clones of the global counterparts?

    • eg. //[Local COPY] ???: Define text variables for the message
    •         var aMessage = [];
    • Also I have seen this var Debug;   //Global Debug bool-switch ??? somewhere else - how to control that?
    	// Global scope: Declare working variables	/*********************************************************************/        var Debug;   //Global Debug bool-switch ???	var bDebug = true;		//Boolean: Switch - true: you get a MessageBox to see the passed Arguments with datatypes	var bDebugConsole = false;	//Boolean: Switch - true: instead of the final messagebox the final message gets written to the Script IDE console with the use of print("") - critical erros will still be showen with a messagebox	// Define text variables for the message	var aMessage = [];				//Array: to collect all messages from "passed Argument loop" and final results	var aMessageSucces = [];			//Array: to collect all messages from the function: InfoMsg	var aMessageError = [];				//Array: to collect all messages from the function: ErrorMsg	        Check_Args ( nArgs, aArgs, aMessage);   //call the function to run// Check_Args: A function for to Check for passed Arguments//********************************************************************************function Check_Args ( nArgs, aArgs, aMessage) { 	// Local scope: Declare working variables	/*********************************************************************/	var vArg;		//value of the passed Argument        var nArgs = 0;		//Number: of Arguments - by default no Arguments get passed if you run this stript	var sType;		//String: Type of 'current' Argument / later Type of 'current' Object see: sType = typeof( oObject )		//[Local COPY] ???: Define text variables for the message	var aMessage = [];	//Array: to collect all messages from "passed Argument loop" and final results	// Iterate over the arguments passed to the script	/*********************************************************************/	for( var i = 0, nArgs = aArgs.length; i &lt; nArgs; i += 1 ) {				// if we got more than 4 arguments passed cancel this for-loop		if ( nArgs &gt; 4) {			break;		}       .............       }       return aMessage; //what to return here nothing/.self/this. ???       ...}
    Post edited by Syrus_Dante on
  • As an end-user, just wanted to say Thank you! to all in this thread for this public resource. 

    DL'd Syrus Dante's v7 dsa, made 6 copies and modified each to a different setting.  Added all 6 one clicks to a Visual Menu (Bitwelder's product) and life got a bit quicker again.   smiley

Sign In or Register to comment.