Quantcast
Channel: Daz Script Developer Discussion - Daz 3D Forums
Viewing all 1025 articles
Browse latest View live

How to terminate a running script completely II

$
0
0

Hello,

I found different discussions, but none of them are helpful for my problem.

I build some common libraries that are used with include and I want to show a message when a user try to run such a script that this library is not intended to run for itself.

//==============================================================================
// S C R I P T   W A R N I N G
//==============================================================================
if (getScriptFileName().search("m42Logfile.ds") > 0)
{
   MessageBox.information(qsTr("This script is a library used by other scripts and can't be executed."), qsTr("Library - Information"), qsTr("&OK"));
   exit(); // I NEED TO LEAVE HERE
}
//==============================================================================


//==============================================================================
// I N C L U D E
//==============================================================================
include(scriptPath + "m42Project" + m42ScriptExt);

I need to leave the script after I show the message (the line where I tried exit() (and break or return)) without success.

The reason is that the include line(s) refer zur 2 variables that are defined in the main script before including the lib. And if the script is not "left" before this line it throws an error.

(An anonymous function doesn't work for obvious resasons)

Any idea how to break/stop/quit/exit the script at a specific line?

Thanks in advance for any hint.

With kind regards,

Ruediger Kabbasch

Sure, I can put the include lines into a function, but that forces me to call this routine in almost every routine I define in the script (or at least in a number of routines).

 


How to use an UI Dialog created by Qt Designer

$
0
0

Hi @all,

I want to use Qt-Designer, which is part of DAZ-Studio, but unfortunately I'm not able to show the dialog-widget. Please see this simple code fragment:

var loader = new DzUiLoader();
var dialog = new DzDialog();
var wgt    = loader.load("X:/.../test.ui", dialog);
dialog.exec();

This shows an empty dialog.

The second way I've found is:

var popup = new DzUIPopUpWgt(dialog);

brings the exception:  TypeError: no constructor for DzUIPopUpWgt

Altough a constructor is documented: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/uipopupwgt_dz

 

Can anyone help me with a little piece of code please ;-)

 

Need help trying to add suffix to materials of selected nodes

$
0
0

Hey folks,

I am currently trying to create a simple batch renamer. I basically have everything I need from some of the samples to go into my loop of iterating through each selected node, but I am not 100% sure how to access the material name so I can put this into a variable and then later write that back after I changed it with a simple string combine with my suffix variable. The string operation is no issue, that is simple, but reading out the correct data and then later writing it back, I really have no idea what I have to call.

This is my code snippet I have so far. I am on the right track as my little info output gives me correct number of materials and it is also doing it for each selected node, so in that regard all is good. I just dont know how to access the material name on that oMat, nor do I know how to write the data back afterwards. Please help me.

(function(){

	var oNode;
	var aNodes = Scene.getSelectedNodeList();
	var nNodes = aNodes.length;


	for( var i = 0; i < nNodes; i += 1 ){

		oNode = aNodes[i];

		var oObject = oNode.getObject();
		if (! oObject) continue;
		var nShapes = oObject.getNumShapes();

		for (var j=0; j < nShapes; j++) {
			var oShape = oObject.getShape(j);
			var nMat = oShape.getNumMaterials();

			for (var k=0; k < nMat; k++) {
				var oMat = oShape.getMaterial(k);
				// Info Output
				print ( oMat, "num ", k);
			}
		}
	}

})();

 

Anchor or alignment for controls

$
0
0

Hello,

is it possible to assign anchors and/or alignment to controls of a form (so they resize automatically when the form size is changed)?

If not is there an event of the form that is fired when the form is resized?

Thanks in advance for any hint.

With kind regards

Ruediger Kabbasch

Setting OpenGL render engine in a script

$
0
0

Hi, I'm new for DAZ. I found that the rendererList doesn't contain OpenGL. And I want to render a image by OpenGL and Iray.  Because of the lack of OpenGL, now I must save two Scene files, one for Iray and another for opengl. Is there a simple way to change Iray to OpenGL in a scene using script?

var oRenderMgr = App.getRenderMgr();
var oRenderList = oRenderMgr.getRendererList()
for(i=0;i<oRenderList.length;i++){
	print(oRenderList[i].getName())
}
/* output
NVIDIA Iray
3Delight
Scripted 3Delight
*/

 

Switch Block Question

$
0
0

I am working on a script and I want to read the  base color of the current material and have that output a result matching the RGBA array. It currently looks like this:

 

var oMat = Scene.getPrimarySelection().getObject().getCurrentShape().getMaterial(0);

 
var oEmissionColor = oMat.getBaseColor();
switch(oEmissionColor){
case [0,1,0,1]:
print("Green")
break;
case [0.0477758,0,0.21952,1]:
print("Purple")
break;
case [1,1,0,1]:
print("Yellow")
break;
case [1,0,0,1]:
print("Red")
break;
case [1,0.21952,0,1]:
print("Orange")
break;
case [0,0.21952,1,1]:
print("Blue")
break;
default:
print("this doesn't work")
break;
}

 

 Everything seems to be fine but the array matches the case array (I checked via print) and the script does not pick it up. Is it just that cases cannot be arrays?

Little help for a scripting newb please

$
0
0

i have an idea i want to achieve and i wonder if you can help me.

its relatively simple 

i would like a script that adds a camera to a scene pointing in the same direction as the active view, names it a specific name and sets a specific focal length. from there i would be able to workout everything else i need it to do 

any help is appreciated thanks :) 

Problem now solved thread can be closed

My first script - feedback sought

$
0
0

I've finally dipped my toe into the world of Daz scripting and written my first one. Here's what it does...

There are rendering errors that can occur in Iray if a character is too far away from the world origin. Eyes can turn black. Strange marks show on scalps. Maybe other stuff too. So what I've written is a script to move the selected object to (0,0,0) and everything else in the scene stays in the same place relative to it. The only thing that doesn't move is the Perspective View position (is it possible to move that via scripting?).

I've tested it, and it seems to work, but I'd appreciate a once-over from more experienced eyes. Is there anything that I've missed?

// DAZ Studio version 4.10.0.123 filetype DAZ Script
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables

(function(){

   /*********************************************************************/
   // String : A function for retrieving a translation if one exists

   function text( sText )
   {
      // If the version of the application supports qsTr()
      if( typeof( qsTr ) != "undefined" ){
         // Return the translated (if any) text
         return qsTr( sText );
      }
      // Return the original text
      return sText;
   };

   // Define common message variables
   var sButton = text( "&OK" );

   // Get the selected nodes
   var aNodes = Scene.getSelectedNodeList();
   // Get the number of nodes
   var nNodes = aNodes.length;

   if( nNodes != 1 ){
      // We're done...
      MessageBox.warning( "Please select a single item in the scene before invoking this script", "Selection Error", sButton, "" );
      return;
   }

   var oNode = aNodes[0];

    //Offset is the selected object's position, less any origin positioning
    //This should give the same figures that show in the X/Y/Z Translate properties
    // (for unparented items)

    var vOffset = oNode.getWSPos().subtract(oNode.getOrigin());

    var aAllNodes = Scene.getNodeList();
    var nAllNodes = aAllNodes.length;

    // Iterate over the nodes
    for( var i = 0; i < nAllNodes; i += 1 ){

       // Get the 'current' node
       oNode = aAllNodes[ i ];

       // If the node is a root node, move it by the offset amount
       // if it isn't, there's no need as it'll move with its parent

       if (oNode.isRootNode()) {
          var vNewPos = oNode.getWSPos().subtract(vOffset);
          oNode.setWSPos(vNewPos);
       }
   }

   // Finalize the function and invoke
})();

 


Daz Scripting & Integration with external app - for use in a possible Vendor Product

$
0
0

Hello all,

I have an idea for a script-based product and have begun working on a proof of concept. If the POC pans out I would eventually like to become a vendor and try my luck selling it on the daz store. With that in mind I've started reading through the script documentation for samples, object references, etc. but have a few basic questions that I think will shape my next steps. 

Part I - scripting questions for vendor products

1) I may not have found it yet, but is there a location in the daz installation files or the daz website with info on what is required for a vendor based script product? For instance, additional references for how to package it, minimum script requirements, best practices, etc.?

2) All the scripts I have bought off the store install to "My Daz Install dir \ My Daz Default Library \ Scripts \ Vendor and/or Product \" with the .dsa files there. Is this the correct place to assume I should be building to? I also see a scripts folder under "My Daz Install dir \ DazStudio4 \ scripts".

3) I'm a former java/javacript UI coder, but it's been many years so I decided to try using the QT Designer that came with Daz Studio to make the UI interface.  Is there any issue making a vendor product using a QT Designer made UI? Or is the tool there just for personal use-only creations?

4) If the answer to #3 is that I can use a QT Designer UI file is there a default directory I should store it to? I didn't think including it in a sub-folder under the \Scripts\ folders would be good practice so I'm wondering if a location you can't easily reach from the app such as "My Daz Install dir \ My Daz Default Library \ data \ Vendor Name \ Product Name \ UI \ " would be better?

5) Depending on #4, is there a built in method for finding the default library path? All the DzApp.getXXXPath() don't seem to get me where I expect them to go to...

Part 2 - Integration with an external app?

Part of the functionality I would like to automate is the image manipulation of post-rendered files. I don't yet see anything in the script documentation that would let me do this (but I may not have found it yet). My goal is to keep the user inside Daz Studio to do the post-render work as part of the value-add of my vendor script.

For this i'm not sure if there is a left-turn / right-turn requirement. If I can't directly do it via script calls, do I HAVE to try to make a plugin? I have not researched plugins at all so that may be a dumb question lol. 

I made an assumption from seeing DzProcess() that my script should be able to call an external program and pass arguments. As a specific example, I have installed the latest GraphicMagick on my pc and accomplished what I would like my script to do using it's command line options. Is this a valid approach for a vendor product - forcing users to go install another non-daz product?

Depending on the answers above, if I can use GraphicMagick to do the actual work, it seems from their license page I can use and package their app freely. Could I include their app within my vendor product instead of some kind of 'this script requires the latest installation of GraphicMagick' disclaimer?

Thanks again for taking the time to read through these and any help or feedback you can provide!

 

Control the tiggered dialog using script (get dialog manager)

$
0
0

Hi, I am facing a problem. I  fit Hair node to Genesis8Female node using script, but it tiggered a Auto-Fit dialog.

var oHair = Scene.findNodeByLabel(sHairLabel)
var oProp = oHair.findProperty("Fit to")
oProp.setValue(oPeople)

 

So I want to use script to accept the dialog.  Is there a function to get dialog manager? 

Thank you for help!

Running a script (not from another script) with arguments

$
0
0

Is there a way to start a Daz Studio script (.dsa or .duf) with an initial argument or parameter?  I'm trying to make better use of my StreamDeck, iCue hotkeys and Spacemouse and would like to be able to run a script that accepts a given value.  I know I can call a script from outside Daz Studio, such as from a Command Line or StreamDeck macro and it will execute inside the current Daz Studio instance.  The problem I have several scripts that would benefit from being able to pass them a value.  For example, the script below, which I got from ShareCG, decreases the rotation on the X-axis for selected nodes by the nodes Increment Value.  I can call it just by running the script as "RotateXDown.dsa" .  I'd like to be able to run something like "RotateXDown.dsa 10.5" and have the value change by "10.5" instead of by the default Increment Value.  In this way, I can use one script and just pass the value from the macro.

I've seen comments on how to do this from another script, but that just brings me back to the initial issue of passing the value in the first place.

Thanks in advance for any information, even if the answer is "Nope.  Ain't happenin'."

/*DAZ Studio Script
Decreases the xRotation by the sensitivity listed in the nodes parameter settings
	for all currently selected nodes.  
*/
var oNodes = Scene.getSelectedNodeList();
var nValue;
var nIncrement;
for ( var i = 0; i &lt; oNodes.length; i++ ) {
	nValue = oNodes[ i ].getXRotControl().getValue();
	nIncrement = oNodes[ i ].getXRotControl().getSensitivity();
	oNodes[ i ].getXRotControl().setValue( nValue - nIncrement );
} 

 

why some duf file is ascii and other is binary?

$
0
0

hi, guy

I'am going to wrote some code to rewrite *.duf file. but when I save scnece in daz, the duf file saved is binary forme, not like json can text read. how to save duf file as ascii ? 

thank you.

Open a script (.dsa) in script ide per script

$
0
0

Hello,

is it possible to open a script file per script in the script ide?

(I saw the misc DzScript classes, but did not see anything like this)

Any hint is welcome.

Kind regards,

Ruediger Kabbasch

why duf file center_point infor dn't matched the paramater in joint editor

$
0
0

for my piple, export the character to maya , and do animation in maya, and data back to daz for render. the problem is the character exported in maya , the joint orientate and position is't straight line that will make ik slover in maya happen error that value is strange and is not fix limition inside daz. so i dicide to fix the joint position and oritentate. when i modify the duf file, for the document know center_point and end_point  and oritenation item is value for  position and oritentation of joint. the problem is joint editor value and the valude in the duf is't the same. the value will less a little, very small, can some body tell the relation of value in duf and the value in joint editor ?

thank you.

Problem with controls from array created with getChildrenOfWidget()

$
0
0

Hello.

I stumbled into a strange problem when using getChildrenOfWidget() to get the controls of a form.

(I didn't test all types yet, but I found 3 types where I can't get the value of the control)

I create 3 prompts of the following types: DzFloatSlider, DzIntSlider and DzColorWgt

When I access the objects direct it works as expected (although the class name is different):

ce_test_prompt_3: [object Object] (Class name: DsColorWgt) [x:216, y:250, w:560, h:24 || value.name: #256997] (Name: ce_test_prompt_3)
ne_test_prompt_4: [object Object] (Class name: DsIntSlider) [x:216, y:275, w:560, h:26 || min: -100, max: 100, value: 77 (Name: ne_test_prompt_4)
ne_test_prompt_5: [object Object] (Class name: DsFloatSlider) [x:216, y:305, w:560, h:26 || min: -1000, max: 1000, value: 12.34000015258789 (Name: ne_test_prompt_5)

But when I use getChildrenOfWidget() and pick the 3 controls from the array I get the following:

control: [object Object] (Class name: DzColorWgt)[<<<-Result of expression 'theVar.value' [undefined] is not an object.->>>] (Name: ce_test_prompt_3)
control: [object Object] (Class name: DzIntSlider) [x:216, y:275, w:560, h:26 || min: undefined, max: undefined, value: undefined (Name: ne_test_prompt_4)
control: [object Object] (Class name: DzFloatSlider) [x:216, y:305, w:560, h:26 || min: undefined, max: undefined, value: undefined (Name: ne_test_prompt_5)

The (e.g.) text property of a line edit control or the checked property of a checkbox show the correct value when picked from the array.

How can I access the values from the controls taken from the array?

Any hint is highly welcome.

With kind regards,

Ruediger Kabbasch

 


Possible to Render to a non-active camera via script? [SOLVED]

$
0
0

Hello all,

I'm working on a script trying to render from different cameras in the scene programatically. I'm referencing this script for the constructor 

DzImageRenderHandlerSize size, DzTime renderTime, String filename )

(which btw, does not run as-is with 4.12 without a few syntax fixes)

http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/imagerenderhandler_dz#a_1a503b91ae4ce48a7fd4259655af0b8fcb

the script gets the camera based on the camera being active in the viewport.

// Get the active viewport and camera
var oActiveView = MainWindow.getViewportMgr().getActiveViewport();
var oCamera = oActiveView.get3DViewport().getCamera();

In my script I am selecting a camera which may or may not be active in the viewport. When I run it the rendering starts, I get a progress popup window, but then there is no resulting image saved off. It makes me wonder if it is REQUIRED to only render from the camera which is active in the viewport?

If yes, then I need to change the user's current camera in the viewport (depending on what layout?) and then make it active, and then start the render?

thanks in advance for any info.

EDIT: Found the problem in my image path which caused the file not to output - it wasn't an issue with the camera being inactive. And yes, it allowed me to render from the camera that was not active in the viewport...

Determining the selected parameter(s)

$
0
0

Hello folks,

actually, I have two questions:

1) is there a way to find out in a script which single parameter or group of parameters was selected in the UI parameter tab?

2) I would like to create a keyframe for the selected parameter in the current, the previous, and the following frame and set the mode of change to constant. Is there an example somewhere?

How to discover if a property is Modifier/Pose or Modifier/Shape

$
0
0

I'd like to manipulate modifier/pose properties on nodes.  How can I discover which they are?

function Adjust_Pose_Morphs(node)
{
    var properties = node.getPropertyList();
    
    for (i = 0; i < properties.length; i++)
    {        
        var property = properties[i];
        
        if(??? Modifier/Pose || Modifier/Shape)
        {
            
        }
    }
}

 

 

Teach Me How To Checkbox

$
0
0

I've got a script I've been working on that will let the user select scene lights via a checkbox. What happens afterward is irrelevant at this point, because I'm trying to figure out how to get the checkbox dialog to actually DO anything. Right now I've got this code:

// DAZ Studio version 4.12.1.118 filetype DAZ Script


var oStyle = App.getStyle();
 
	var nBtnHeight = oStyle.pixelMetric( "DZ_ButtonHeight" );
 
	var wDlg = new DzBasicDialog();
	var wLyt = new DzVBoxLayout (wDlg);
	wLyt.autoAdd = true;
	
	var oDlgWgt = wDlg.getWidget();
 
	wDlg.caption = "This is a thing";
 
	var sKey = wDlg.caption.replace( / /g, "" ) + "Dlg";
 
	oDlgWgt.objectName = sKey;
	
var col1;	
	 col1 = new DzTextBrowser(wDlg);
	 col1.text = qsTr("Select scene lights");
	 wDlg.addWidget(col1);
var litelist = Scene.getLightList();
var lite;
var lyt;
var sel;
var nam;
var ind;
var wCheckWgt;
var chk;

for (i=0; i&lt;litelist.length; i++) {
	lite = Scene.getLight(i);
	ind = Scene.findNodeIndex(lite);
	sel = Scene.getNode(ind);
	sel.setPrimarySelection;

	wCheckWgt = new DzCheckBox( wDlg );
	wCheckWgt.name = "check" + i;	
	wCheckWgt.setFixedHeight( nBtnHeight );
	wCheckWgt.text = sel.getName();
	wDlg.addWidget( wCheckWgt );
}
	var sizeHint = oDlgWgt.minimumSizeHint;
 
	wDlg.setFixedSize( sizeHint.width, sizeHint.height );
 
 		
		
	if( wDlg.exec() ){

		var clk = [];
		var fnd = [];
 		var chk = [];
 		var wdg;
		for (i=0; i&lt;litelist.length; i++) {
			fnd = qsTr("check" + i);
			chk = wDlg.findChildOfWidget(fnd).name;
			wdg = wDlg.getWidget(chk);			
			if (wdg.isChecked) {			
				print(chk + " is checked");
				}
			}
					
	}	

Hopefully I'm doing a lot of unnecessary steps and the real process is much simpler. What the code SHOULD be doing is checking on execution to see which boxes are checked. I've tried several different methods, like changing "if (wdg.isChecked)" to "...isChecked = true", "...checked" and so on, and either no results are returned, or all results are returned regardless of what's checked. Am I looking in the wrong place for the parameter? Is there an extra declaration I should be making? What the dilly, yo?

"Clamped" DzIntSlider isn't really clamped

$
0
0

I've got the following code:

var sld = new DzIntSlider( wDlg );
sld.label = "On position";
sld.min = 1;
sld.max = 2;
sld.value = 1;
sld.clamped = true;
sld.labelVisible = true;
wDlg.addWidget(sld);

When I run the script, the slider starts with a value of 1 and goes up to 2, but 0 is still an option. How is that possible if the min is set to 1? Shouldn't the min be the lowest possible setting?

Viewing all 1025 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>