From 492385a4919b4c8ab31cfa005a84e70a0b484712 Mon Sep 17 00:00:00 2001 From: maxto8 Date: Thu, 15 Oct 2020 09:15:05 -0300 Subject: [PATCH] Update Daz to Cinema 4D.dsa --- .../scripts/support/DAZ/Daz to Cinema 4D.dsa | 1211 ++++++++--------- 1 file changed, 585 insertions(+), 626 deletions(-) diff --git a/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa b/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa index 6dd1522..8a91459 100644 --- a/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa +++ b/Daz Studio/appdir_common/scripts/support/DAZ/Daz to Cinema 4D.dsa @@ -1,695 +1,654 @@ // DAZ Studio version 4.12.0.86 filetype DAZ Script +var isFBX = false +var figs = Scene.getSkeletonList(); +// if (figs.length>0) +// isFBX = true +isFBX = true -(function(){ - - var s_oFileInfo = new DzFileInfo( getScriptFileName() ); - var s_sToolName = s_oFileInfo.baseName(); - s_oFileInfo.deleteLater(); - - var s_aSkeletons = Scene.getSkeletonList(); - var s_oPrimarySkeleton = s_aSkeletons.length > 0 ? s_aSkeletons[0] : undefined; - - var s_sExporter = "DzFbxExporter";//"DzDAZCOLLADAExporter" - var s_sExportExt = "fbx";//"dae" - var s_sExportPath = "C:/TEMP3D"; - if( App.platform() == DzApp.MacOSX ){ - s_sExportPath = "/users/Shared/temp3d"; - } - var s_sExportBaseName = "DazToC4D"; - - function getXRot( sBoneLabel ) - { - if( !s_oPrimarySkeleton || sBoneLabel.isEmpty() ){ - return undefined; - } - - var oBone = s_oPrimarySkeleton.findBoneByLabel( sBoneLabel ); - if( !oBone ){ - return undefined; - } - - var oControl = oBone.getXRotControl(); - var nValue = oControl.getValue(); - //print( ":: get x :: " + sBoneLabel + " :: " + nValue ); - return nValue; - }; - - function setXRot( sBoneLabel, nValue ) - { - if( !s_oPrimarySkeleton - || sBoneLabel.isEmpty() - || nValue == undefined ){ - return; - } - - //print( ":: set x :: " + sBoneLabel + " :: " + nValue ); - var oBone = s_oPrimarySkeleton.findBoneByLabel( sBoneLabel ); - if( !oBone ){ - return; - } - - var oControl = oBone.getXRotControl(); - oControl.setValue( nValue ); - }; - - function heelsFix( oSkeleton ) - { - if( oSkeleton ){ - return; - } - - //Left - try { var xRotLeftMetatarsals = getXRot( "Left Metatarsals" ); } catch( error ){} - try { var xRotLeftHeel = getXRot( "Left Heel" ); } catch( error ){} - try { var xRotLeftFoot = getXRot( "Left Foot" ); } catch( error ){} - try { var xRotLeftToes = getXRot( "Left Toes" ); } catch( error ){} - try { var xRotLeftBigToe = getXRot( "Left Big Toe" ); } catch( error ){} - try { var xRotLeftBigToe2 = getXRot( "Left Big Toe_2" ); } catch( error ){} - try { var xRotLeftSmallToe1 = getXRot( "Left Small Toe 1" ); } catch( error ){} - try { var xRotLeftSmallToe12 = getXRot( "Left Small Toe 1_2" ); } catch( error ){} - try { var xRotLeftSmallToe2 = getXRot( "Left Small Toe 2" ); } catch( error ){} - try { var xRotLeftSmallToe22 = getXRot( "Left Small Toe 2_2" ); } catch( error ){} - try { var xRotLeftSmallToe3 = getXRot( "Left Small Toe 3" ); } catch( error ){} - try { var xRotLeftSmallToe32 = getXRot( "Left Small Toe 3_2" ); } catch( error ){} - try { var xRotLeftSmallToe4 = getXRot( "Left Small Toe 4" ); } catch( error ){} - try { var xRotLeftSmallToe42 = getXRot( "Left Small Toe 4_2" ); } catch( error ){} - - //Right - try { var xRotRightMetatarsals = getXRot( "Right Metatarsals" ); } catch( error ){} - try { var xRotRightHeel = getXRot( "Right Heel" ); } catch( error ){} - try { var xRotRightFoot = getXRot( "Right Foot" ); } catch( error ){} - try { var xRotRightToes = getXRot( "Right Toes" ); } catch( error ){} - try { var xRotRightBigToe = getXRot( "Right Big Toe" ); } catch( error ){} - try { var xRotRightBigToe2 = getXRot( "Right Big Toe_2" ); } catch( error ){} - try { var xRotRightSmallToe1 = getXRot( "Right Small Toe 1" ); } catch( error ){} - try { var xRotRightSmallToe12 = getXRot( "Right Small Toe 1_2" ); } catch( error ){} - try { var xRotRightSmallToe2 = getXRot( "Right Small Toe 2" ); } catch( error ){} - try { var xRotRightSmallToe22 = getXRot( "Right Small Toe 2_2" ); } catch( error ){} - try { var xRotRightSmallToe3 = getXRot( "Right Small Toe 3" ); } catch( error ){} - try { var xRotRightSmallToe32 = getXRot( "Right Small Toe 3_2" ); } catch( error ){} - try { var xRotRightSmallToe4 = getXRot( "Right Small Toe 4" ); } catch( error ){} - try { var xRotRightSmallToe42 = getXRot( "Right Small Toe 4_2" ); } catch( error ){} - - Scene.selectAllNodes( false ); - - oSkeleton.select( true ); - - var oMgr = MainWindow.getActionMgr(); - var oAction = oMgr.findAction( "DzRestoreFigurePoseAction" ); - if( oAction ){ - oAction.trigger(); - } - - var nZero = 0; - - //Left - //print( "-----------------------------------------" ); - try { setXRot( "Left Metatarsals", xRotLeftMetatarsals ); } catch( error ){} - try { setXRot( "Left Heel", nZero ); } catch( error ){} - //try { setXRot( "Left Foot", xRotLeftFoot ); } catch( error ){} - try { setXRot( "Left Toes", xRotLeftToes ); } catch( error ){} - try { setXRot( "Left Big Toe", xRotLeftBigToe ); } catch( error ){} - try { setXRot( "Left Big Toe_2", xRotLeftBigToe2 ); } catch( error ){} - try { setXRot( "Left Small Toe 1", xRotLeftSmallToe1 ); } catch( error ){} - try { setXRot( "Left Small Toe 1_2", xRotLeftSmallToe12 ); } catch( error ){} - try { setXRot( "Left Small Toe 2", xRotLeftSmallToe2 ); } catch( error ){} - try { setXRot( "Left Small Toe 2_2", xRotLeftSmallToe22 ); } catch( error ){} - try { setXRot( "Left Small Toe 3", xRotLeftSmallToe3 ); } catch( error ){} - try { setXRot( "Left Small Toe 3_2", xRotLeftSmallToe32 ); } catch( error ){} - try { setXRot( "Left Small Toe 4", xRotLeftSmallToe4 ); } catch( error ){} - try { setXRot( "Left Small Toe 4_2", xRotLeftSmallToe42 ); } catch( error ){} - - //Right - //print( "-----------------------------------------" ); - try { setXRot( "Right Metatarsals", xRotRightMetatarsals ); } catch( error ){} - try { setXRot( "Right Heel", nZero ); } catch( error ){} - //try { setXRot( "Right Foot", xRotRightFoot ); } catch( error ){} - try { setXRot( "Right Toes", xRotRightToes ); } catch( error ){} - try { setXRot( "Right Big Toe", xRotRightBigToe ); } catch( error ){} - try { setXRot( "Right Big Toe_2", xRotRightBigToe2 ); } catch( error ){} - try { setXRot( "Right Small Toe 1", xRotRightSmallToe1 ); } catch( error ){} - try { setXRot( "Right Small Toe 1_2", xRotRightSmallToe12 ); } catch( error ){} - try { setXRot( "Right Small Toe 2", xRotRightSmallToe2 ); } catch( error ){} - try { setXRot( "Right Small Toe 2_2", xRotRightSmallToe22 ); } catch( error ){} - try { setXRot( "Right Small Toe 3", xRotRightSmallToe3 ); } catch( error ){} - try { setXRot( "Right Small Toe 3_2", xRotRightSmallToe32 ); } catch( error ){} - try { setXRot( "Right Small Toe 4", xRotRightSmallToe4 ); } catch( error ){} - try { setXRot( "Right Small Toe 4_2", xRotRightSmallToe42 ); } catch( error ){} - - //print( "-----" ); - }; - - // --- START convert_figure_to_props ---- - /********************************************************************** +function xValue(boneName) { + var bone = figs[0].findBoneByLabel(boneName); + cX = bone.getXRotControl(); + var xValue = cX.getValue(); + //print (":: get x :: " + boneName + " :: " + xValue); + return xValue; +} - The following is derived from a work published as part of the - Daz Script Documentation. This portion of the script, and/or any - portion thereof, may only be used in accordance with the - following license: +function setX(boneName, savedValue) { + //print (":: set x :: " + boneName + " :: " + savedValue); + var bone = figs[0].findBoneByLabel(boneName); + cX = bone.getXRotControl(); + cX.setValue(savedValue); +} - Creative Commons Attribution 3.0 Unported (CC BY 3.0) - - http://creativecommons.org/licenses/by/3.0 +function heelsFix() { + //for (var fig_idx = 0; fig_idx != figs.length; ++ fig_idx) { + //Left + try { var xvalueLeftMetatarsals = xValue("Left Metatarsals"); } catch (error) { } + try { var xvalueLeftHeel = xValue("Left Heel"); } catch (error) { } + try { var xvalueLeftFoot = xValue("Left Foot"); } catch (error) { } + try { var xvalueLeftToes = xValue("Left Toes"); } catch (error) { } + try { var xvalueLeftBigToe = xValue("Left Big Toe"); } catch (error) { } + try { var xvalueLeftBigToe2 = xValue("Left Big Toe_2"); } catch (error) { } + try { var xvalueLeftSmallToe1 = xValue("Left Small Toe 1"); } catch (error) { } + try { var xvalueLeftSmallToe12 = xValue("Left Small Toe 1_2"); } catch (error) { } + try { var xvalueLeftSmallToe2 = xValue("Left Small Toe 2"); } catch (error) { } + try { var xvalueLeftSmallToe22 = xValue("Left Small Toe 2_2"); } catch (error) { } + try { var xvalueLeftSmallToe3 = xValue("Left Small Toe 3"); } catch (error) { } + try { var xvalueLeftSmallToe32 = xValue("Left Small Toe 3_2"); } catch (error) { } + try { var xvalueLeftSmallToe4 = xValue("Left Small Toe 4"); } catch (error) { } + try { var xvalueLeftSmallToe42 = xValue("Left Small Toe 4_2"); } catch (error) { } - **********************************************************************/ - // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/nodes/convert_figure_to_props/start - - // - Modified to remove display of messages presented to the user - - function convert2Prop( oSelectedNode ) - { - // If the selected node is a bone - if( oSelectedNode.inherits( "DzBone" ) ){ - // Get the skeleton - oSelectedNode = oSelectedNode.getSkeleton(); - } - - // If we don't have a skeleton - if( !oSelectedNode.inherits( "DzSkeleton" ) ){ - return; + //Right + try { var xvalueRightMetatarsals = xValue("Right Metatarsals"); } catch (error) { } + try { var xvalueRightHeel = xValue("Right Heel"); } catch (error) { } + try { var xvalueRightFoot = xValue("Right Foot"); } catch (error) { } + try { var xvalueRightToes = xValue("Right Toes"); } catch (error) { } + try { var xvalueRightBigToe = xValue("Right Big Toe"); } catch (error) { } + try { var xvalueRightBigToe2 = xValue("Right Big Toe_2"); } catch (error) { } + try { var xvalueRightSmallToe1 = xValue("Right Small Toe 1"); } catch (error) { } + try { var xvalueRightSmallToe12 = xValue("Right Small Toe 1_2"); } catch (error) { } + try { var xvalueRightSmallToe2 = xValue("Right Small Toe 2"); } catch (error) { } + try { var xvalueRightSmallToe22 = xValue("Right Small Toe 2_2"); } catch (error) { } + try { var xvalueRightSmallToe3 = xValue("Right Small Toe 3"); } catch (error) { } + try { var xvalueRightSmallToe32 = xValue("Right Small Toe 3_2"); } catch (error) { } + try { var xvalueRightSmallToe4 = xValue("Right Small Toe 4"); } catch (error) { } + try { var xvalueRightSmallToe42 = xValue("Right Small Toe 4_2"); } catch (error) { } + + Scene.selectAllNodes(0); + figs[0].select(true); + var mgr = MainWindow.getActionMgr(); + func = mgr.findAction("DzRestoreFigurePoseAction") + func.trigger(); + + var zeroValue = 0; + + //Left + try { setX("Left Metatarsals", xvalueLeftMetatarsals); } catch (error) { } + try { setX("Left Heel", zeroValue); } catch (error) { } + //try { setX("Left Foot",xvalueLeftFoot);} catch (error ) {} + try { setX("Left Toes", xvalueLeftToes); } catch (error) { } + try { setX("Left Big Toe", xvalueLeftBigToe); } catch (error) { } + try { setX("Left Big Toe_2", xvalueLeftBigToe2); } catch (error) { } + try { setX("Left Small Toe 1", xvalueLeftSmallToe1); } catch (error) { } + try { setX("Left Small Toe 1_2", xvalueLeftSmallToe12); } catch (error) { } + try { setX("Left Small Toe 2", xvalueLeftSmallToe2); } catch (error) { } + try { setX("Left Small Toe 2_2", xvalueLeftSmallToe22); } catch (error) { } + try { setX("Left Small Toe 3", xvalueLeftSmallToe3); } catch (error) { } + try { setX("Left Small Toe 3_2", xvalueLeftSmallToe32); } catch (error) { } + try { setX("Left Small Toe 4", xvalueLeftSmallToe4); } catch (error) { } + try { setX("Left Small Toe 4_2", xvalueLeftSmallToe42); } catch (error) { } + //Right + try { setX("Right Metatarsals", xvalueRightMetatarsals); } catch (error) { } + try { setX("Right Heel", zeroValue); } catch (error) { } + //try { setX("Right Foot",xvalueRightFoot);} catch (error ) {} + try { setX("Right Toes", xvalueRightToes); } catch (error) { } + try { setX("Right Big Toe", xvalueRightBigToe); } catch (error) { } + try { setX("Right Big Toe_2", xvalueRightBigToe2); } catch (error) { } + try { setX("Right Small Toe 1", xvalueRightSmallToe1); } catch (error) { } + try { setX("Right Small Toe 1_2", xvalueRightSmallToe12); } catch (error) { } + try { setX("Right Small Toe 2", xvalueRightSmallToe2); } catch (error) { } + try { setX("Right Small Toe 2_2", xvalueRightSmallToe22); } catch (error) { } + try { setX("Right Small Toe 3", xvalueRightSmallToe3); } catch (error) { } + try { setX("Right Small Toe 3_2", xvalueRightSmallToe32); } catch (error) { } + try { setX("Right Small Toe 4", xvalueRightSmallToe4); } catch (error) { } + try { setX("Right Small Toe 4_2", xvalueRightSmallToe42); } catch (error) { } + + print("-----"); + //} +} + +function convert2Prop( oSelectedNode ) +{ + + // If the selected node is a bone + if( oSelectedNode.inherits( "DzBone" ) ){ + // Get the skeleton + oSelectedNode = oSelectedNode.getSkeleton(); + } + + // If we don't have a skeleton + if( !oSelectedNode.inherits( "DzSkeleton" ) ){ + return; + } + + // Provide busy feedback to the user + setBusyCursor(); + + // Declare working variables + var oNode, oParent; + + // Get the number of followers for the skeleton + var nFollowers = oSelectedNode.getNumFollowSkeletons(); + // Presize an array to collect the converted nodes + var aProps = new Array( nFollowers ); + + // Iterate over the followers; reverse order, + // the list will change with each conversion + for( var i = nFollowers - 1; i >= 0; i -= 1 ){ + // Get the 'current' follower + oNode = oSelectedNode.getFollowSkeleton( i ); + // Get the parent of the follower + oParent = oNode.getNodeParent(); + // If we have a parent + if( oParent ){ + // Unparent the follower, in place + oParent.removeNodeChild( oNode, true ); } - - // Provide busy feedback to the user - setBusyCursor(); - - // Declare working variables - var oNode, oParent; - - // Get the number of followers for the skeleton - var nFollowers = oSelectedNode.getNumFollowSkeletons(); - // Presize an array to collect the converted nodes - var aProps = new Array( nFollowers ); - - // Iterate over the followers; reverse order, - // the list will change with each conversion - for( var i = nFollowers - 1; i >= 0; i -= 1 ){ - // Get the 'current' follower - oNode = oSelectedNode.getFollowSkeleton( i ); - // Get the parent of the follower + + // Convert the follower to a prop and collect it + aProps[ i ] = oSelectedNode.convertFigureToProp( oNode, oNode.name ); + } + + // Create an array helper; to improve speed of resizing the array + var oArrayHelper = new DzArrayHelper(); + + // Get all of the child nodes of the figure + var aNodes = oSelectedNode.getNodeChildren( true ); + + // Iterate over the skeleton nodes + for( var i = 0; i < aNodes.length; i += 1 ){ + oNode = aNodes[ i ]; + // If the node is not a bone; its some sort of 'prop' + if( !oNode.inherits( "DzBone" ) ){ + // Get the parent of the node oParent = oNode.getNodeParent(); // If we have a parent if( oParent ){ - // Unparent the follower, in place + // Unparent the prop, in place oParent.removeNodeChild( oNode, true ); - } - - // Convert the follower to a prop and collect it - aProps[ i ] = oSelectedNode.convertFigureToProp( oNode, oNode.name ); - } - - // Create an array helper; to improve speed of resizing the array - var oArrayHelper = new DzArrayHelper(); - - // Get all of the child nodes of the figure - var aNodes = oSelectedNode.getNodeChildren( true ); - - // Iterate over the skeleton nodes - for( var i = 0; i < aNodes.length; i += 1 ){ - oNode = aNodes[ i ]; - // If the node is not a bone; its some sort of 'prop' - if( !oNode.inherits( "DzBone" ) ){ - // Get the parent of the node - oParent = oNode.getNodeParent(); - // If we have a parent - if( oParent ){ - // Unparent the prop, in place - oParent.removeNodeChild( oNode, true ); - // Add the prop to the list - aProps = oArrayHelper.addToArray( aProps, oNode ); - } - } - } - - // Convert the figure to a prop - oSelectedNode = oSelectedNode.convertFigureToProp( oSelectedNode, oSelectedNode.name ); - - // Iterate over the props - for( var i = 0; i < aProps.length; i += 1 ){ - // Get the 'current' prop - oNode = aProps[ i ]; - // Parent the prop to the figure, in place - oSelectedNode.addNodeChild( oNode, true ); - } - - // Update the user - clearBusyCursor(); - }; - - // --- END convert_figure_to_props ---- - - function doesHavingSkeleton() - { - return Scene.getNumSkeletons() > 0; - }; - - function doesHavingHip() - { - var oNode; - for( var i = 0, n = Scene.getNumNodes(); i < n; i += 1 ){ - // Get the current node - oNode = Scene.getNode( i ); - if( oNode.getName().toLowerCase() == "hip" ){ - return true; + // Add the prop to the list + aProps = oArrayHelper.addToArray( aProps, oNode ); } } + } + + // Convert the figure to a prop + oSelectedNode = oSelectedNode.convertFigureToProp( oSelectedNode, oSelectedNode.name ); + + // Iterate over the props + for( var i = 0; i < aProps.length; i += 1 ){ + // Get the 'current' prop + oNode = aProps[ i ]; + // Parent the prop to the figure, in place + oSelectedNode.addNodeChild( oNode, true ); + } + + // Update the user + clearBusyCursor(); +} + +function doesHavingSkeleton() +{ + for (i = 0; i < Scene.getNumNodes(); i++) { + // Get the current node + oNode = Scene.getNode(i); + if( oNode.inherits( "DzSkeleton" ) ) + return true; + } + return false; +} + +function doesHavingHip () +{ + for (i = 0; i < Scene.getNumNodes(); i++) { + // Get the current node + oNode = Scene.getNode(i); + if (oNode.getName().toLowerCase() == "hip") + return true; + } + return false; +} + +//start replaceInstance +var actionMgr = MainWindow.getActionMgr(); +function doAction( nm ) +{ + action = actionMgr.findAction( nm ); + action.trigger() +} + +function replaceInstance( node, srcNode ) +{ + var nodeparent = node.getNodeParent(); + Scene.selectAllNodes( false ); + + node.select( true ); + doAction( "DzCopyNodeAction" ); + node.select( false ); + + var nodez = Scene.getNodeList(); + var nn = nodez.length - return false; - }; - - // --- START replaceInstance ---- - // Adapted: https://www.daz3d.com/forums/discussion/comment/4940501/#Comment_4940501 + srcNode.select( true ); +// doAction( "DzDuplicateNodeHierarchyAction" ); + doAction( "DzDuplicateNodeAction" ); + srcNode.select( false ); + + nodez = Scene.getNodeList(); + nunode = nodez[nn] - function doAction( sClassName ) + if (nodeparent != null) { - var oMgr = MainWindow.getActionMgr(); - var oAction = oMgr.findAction( sClassName ); - if( !oAction ){ - return; - } - - oAction.trigger(); - }; + nodeparent.addNodeChild(nunode); + } + + nunode.select( true ); + doAction( "DzPasteNodeAction" ); + nunode.select( false ); + + var ctl = nunode.getScaleControl(); + if( ctl.getValue() == 0 ) ctl.setValue( 1 ); + var ctl = nunode.getXScaleControl(); + if( ctl.getValue() == 0 ) ctl.setValue( 1 ); + var ctl = nunode.getYScaleControl(); + if( ctl.getValue() == 0 ) ctl.setValue( 1 ); + var ctl = nunode.getZScaleControl(); + if( ctl.getValue() == 0 ) ctl.setValue( 1 ); - function replaceInstance( oInstance, oNode ) + + Scene.removeNode( node ); +} + + +function replaceInstanceAll() +{ + var listObjs = new Array(); + for (var i = 0; i < Scene.getNumNodes(); i++) { - var oParent = oInstance.getNodeParent(); - Scene.selectAllNodes( false ); - - oInstance.select( true ); - doAction( "DzCopyNodeAction" ); - oInstance.select( false ); - - var aNodes = Scene.getNodeList(); - var nNodes = aNodes.length; - - oNode.select( true ); - //doAction( "DzDuplicateNodeHierarchyAction" ); - doAction( "DzDuplicateNodeAction" ); - oNode.select( false ); - - aNodes = Scene.getNodeList(); - var oReplacement = aNodes[nNodes]; - - if( oParent ){ - oParent.addNodeChild( oReplacement ); - } - - oReplacement.select( true ); - doAction( "DzPasteNodeAction" ); - oReplacement.select( false ); - - var oControl = oReplacement.getScaleControl(); - if( oControl.getValue() == 0 ){ - oControl.setValue( 1 ); - } - - oControl = oReplacement.getXScaleControl(); - if( oControl.getValue() == 0 ){ - oControl.setValue( 1 ); - } - - oControl = oReplacement.getYScaleControl(); - if( oControl.getValue() == 0 ){ - oControl.setValue( 1 ); - } - - oControl = oReplacement.getZScaleControl(); - if( oControl.getValue() == 0 ){ - oControl.setValue( 1 ); + oNode = Scene.getNode(i); + try { + //replace(oNode, oNode.getTarget()); + debug(oNode.getLabel()+":"+oNode.getTarget().getLabel()); + listObjs.push(oNode); } - - Scene.removeNode( oInstance ); - }; - - // --- END replaceInstance ---- - - function replaceInstanceAll() + catch(error) {} + } + if (listObjs.length>0) { - var oNode; - var nNodes = Scene.getNumNodes(); - var aInstances = new Array( nNodes ); - for( var i = 0; i < nNodes; i += 1 ){ - oNode = Scene.getNode( i ); - if( oNode.inherits( "DzInstanceNode" ) ){ - //replace( oNode, oNode.getTarget() ); - //debug( oNode.getLabel() + ":" + oNode.getTarget().getLabel() ); - aInstances[i] = oNode; - } - } - - aInstances = aInstances.filter( Boolean ); - - if( aInstances.length > 0 ){ - var nResult = MessageBox.question( - qsTr( "Instances found. They need to be replaced before export. Replace them?" ), - s_sToolName, qsTr( "&Yes" ), qsTr( "&No" ) - ); - if( nResult == 0 ){ - //debug( "yes" ); - for( var i = 0; i < aInstances.length; i += 1 ){ - oNode = aInstances[i]; - //debug( oNode.getLabel() + ":" + oNode.getTarget().getLabel() ); - try { - replaceInstance( oNode, oNode.getTarget() ); - } - catch( error ){} + if( MessageBox.question( qsTr("Instances found, They need to be replaced before export. Replace them?\nUNDOABLE Operation (Save First if needed)"), qsTr("DazToMax"), qsTr("&Yes"), qsTr("&No") ) == 0 ) + { + debug("yes"); + for (i = 0; i < listObjs.length; i++) + { + oNode = listObjs[i]; + //debug(oNode.getLabel()+":"+oNode.getTarget().getLabel()); + try { + replaceInstance(oNode, oNode.getTarget()); } + catch(error) {} } + } + } + +} +//end replaceInstance +replaceInstanceAll(); +if (doesHavingSkeleton() == true) +{ + if (doesHavingHip() == false) + { + var listNode = new Array(); + for (i = 0; i < Scene.getNumNodes(); i++) { + // Get the current node + listNode.push (Scene.getNode(i)); + debug(oNode.getName()) } - }; - - replaceInstanceAll(); - - - if( doesHavingSkeleton() ){ - if( !doesHavingHip() ){ - var aConvert = Scene.getSkeletonList(); - var nConvert = aConvert.length; - if( nConvert > 0 ){ - var nResult = MessageBox.question( - qsTr( "Some objects needs to be converted to props. Convert?\nThis operation is NOT undoable! (save first if needed)" ), - s_sToolName, qsTr( "&Yes" ), qsTr( "&No" ) ); - if( nResult == 0 ){ - for( var i = 0; i < nConvert; i += 1 ){ - //debug( aConvert[i].getName() ); - try { - convert2Prop( aConvert[i] ) - } catch( error ){} - } + if (listNode.length>0) + { + //if( MessageBox.question( qsTr("Some objects needs to be converted to props. Convert?\nUNDOABLE Operation (Save First if needed)"), qsTr("DazToMax"), qsTr("&Yes"), qsTr("&No") ) == 0 ) + //{ + for (i = 0; i < listNode.length; i++) { + try { convert2Prop(listNode[i]) } catch (error) { } } - } + //} } } - - // --- START export_fbx_silent ---- - /********************************************************************** +} - The following is derived from a work published as part of the - Daz Script Documentation. This portion of the script, and/or any - portion thereof, may only be used in accordance with the - following license: +function exportDaz() { + + (function () { - Creative Commons Attribution 3.0 Unported (CC BY 3.0) - - http://creativecommons.org/licenses/by/3.0 + var oNode = Scene.getPrimarySelection(); + if (oNode) { + var oSkeleton = oNode.getSkeleton(); + if (oSkeleton) { + oNode = oSkeleton; + } + } - **********************************************************************/ - // Source: http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/export_fbx_silent/start - - // - Modified to support switching exporters - // - Other changes for this specific use case - - function exportScene( sClassName, sPath, sBaseName, sExt ) - { - // Get the export manager var oExportMgr = App.getExportMgr(); - // Find the exporter - var oExporter = oExportMgr.findExporterByClassName( sClassName ); - // If the exporter exists - if( oExporter ){ - // Create a settings object + var sClassName = "DzFbxExporter"; + var oExporter = oExportMgr.findExporterByClassName(sClassName); + if (isFBX == false) + { + n = oExportMgr.getNumExporters () + for (var i=0;i= 0x0004000900030016); - - // Get the options for the exporter - if( !oExporter.getOptions( oSettings, bShowOptions && bOptionsBeforeFile, "" ) ){ - // We're done... + if (!oExporter.getOptions(oSettings, bShowOptions && bOptionsBeforeFile, "")) { return; } - - if( sClassName == "DzFbxExporter" ){ - // Selected - oSettings.setBoolValue( "doSelected", false ); - // No Hidden - oSettings.setBoolValue( "doVisible", false ); - // Figures - oSettings.setBoolValue( "doFigures", true ); - // Props - oSettings.setBoolValue( "doProps", true ); - // Lights - oSettings.setBoolValue( "doLights", true ); - // Cameras - oSettings.setBoolValue( "doCameras", true ); - // Animations - oSettings.setBoolValue( "doAnims", false ); - // Morphs - oSettings.setBoolValue( "doMorphs", true ); - - // Morph Rules - // Format for rules is "Match1\nAction1\nMatch2\nAction2\nMatch3\nAction3", - // where Match# is a string to search for and Action# is one of Bake|Export|Ignore - // The names of the morphs are in the form: node_name.parameter_name - // The default action is to Bake - // So "FBMHeavy\nExport\nThin\nExport" would export all morphs that have FBMHeavy and all morphs that have Thin in the name - oSettings.setStringValue( "rules", "head\n1" ); - - // Format - // Format for format is "Year# -- Type", - // where Year# is one of 2006|2009|2010|2011|2012|2013|2014 and - // Type is one of Ascii|Binary - oSettings.setStringValue( "format", "FBX 2012 -- Binary" ); + if (isFBX) + { + oSettings.setBoolValue("doSelected", false); + oSettings.setBoolValue("doVisible", false); + oSettings.setBoolValue("doFigures", true); + oSettings.setBoolValue("doProps", true); + oSettings.setBoolValue("doLights", true); + oSettings.setBoolValue("doCameras", true); + oSettings.setBoolValue("doAnims", false); + oSettings.setBoolValue("doMorphs", true); + + oSettings.setStringValue("rules", "head\n1"); + oSettings.setStringValue("format", "FBX 2012 -- Binary"); + // Embed Textures - oSettings.setBoolValue( "doEmbed", true ); + oSettings.setBoolValue("doEmbed", true); // Collect Textures To Folder - oSettings.setBoolValue( "doCopyTextures", false ); + oSettings.setBoolValue("doCopyTextures", false); // Merge Diffuse and Opacity Textures - oSettings.setBoolValue( "doDiffuseOpacity", false ); + oSettings.setBoolValue("doDiffuseOpacity", false); // Merge Clothing Into Figure Skeleton - oSettings.setBoolValue( "doMergeClothing", true ); + oSettings.setBoolValue("doMergeClothing", true); // Convert Clothing to Static Geometry - oSettings.setBoolValue( "doStaticClothing", false ); + oSettings.setBoolValue("doStaticClothing", false); // Allow Degraded Skinning - oSettings.setBoolValue( "degradedSkinning", true ); + oSettings.setBoolValue("degradedSkinning", true); // Allow Degraded Scaling - oSettings.setBoolValue( "degradedScaling", true ); + oSettings.setBoolValue("degradedScaling", true); // SubD Information - oSettings.setBoolValue( "doSubD", false ); + oSettings.setBoolValue("doSubD", false); // Collapse UV Tiles - oSettings.setBoolValue( "doCollapseUVTiles", false ); - } else if( sClassName == "DzDAZCOLLADAExporter" ){ - /* - oSettings.setIntValue( "ExportProfile", 0 ); - oSettings.setBoolValue( "RemoveUnusedVerts", true ); - oSettings.setBoolValue( "IgnoreInvisibleNodes", false ); - oSettings.setBoolValue( "BakeScale", false ); - oSettings.setBoolValue( "MergeFollowingSkeletons", false ); - oSettings.setBoolValue( "SparseMorphs", true ); - oSettings.setBoolValue( "WeldGeometry", false ); - oSettings.setBoolValue( "UseModifierLists", true ); - oSettings.setBoolValue( "CombineMorphs", true ); - oSettings.setStringValue( "ImageCopyPath", "" ); - oSettings.setBoolValue( "CopyImagesToFolder", false ); - oSettings.setBoolValue( "InvertAlphaImage", false ); - oSettings.setBoolValue( "CombineAlphaImageIntoDiffuse", false ); - oSettings.setStringValue( "CombineAlphaImageIntoDiffuseExt", "png" ); - oSettings.setBoolValue( "MergeMaterials", false ); - oSettings.setBoolValue( "ExportAnimations", false ); - oSettings.setBoolValue( "AnimationIncludesTransformations", false ); - oSettings.setBoolValue( "AnimationsIncludeMorphs", false ); - */ + oSettings.setBoolValue("doCollapseUVTiles", false); + } + else + { + //https://www.daz3d.com/forums/discussion/231971/silent-export-without-showing-options-and-without-showing-file-dialog + oSettings.setBoolValue("doSelected", false); + oSettings.setBoolValue("doVisible", false); + oSettings.setBoolValue("doLights", true); + oSettings.setBoolValue("doCameras", true); + + // Do not ignore the geometry of invisible nodes + oSettings.setBoolValue( "IgnoreInvisible", false ); + // Do not remove vertices that are floating, connected to nothing - i.e. LOD + oSettings.setBoolValue( "RemoveUnusedVerts", false ); + // Set the scale to write the data + oSettings.setFloatValue( "Scale", 1.0 ); + // Embed Textures + oSettings.setBoolValue("doEmbed", true); + // Collect Textures To Folder + oSettings.setBoolValue("doCopyTextures", false); + // Merge Diffuse and Opacity Textures + oSettings.setBoolValue("doDiffuseOpacity", false); + + } - + // If the version is 4.9.3.22 or newer - if( App.version64 >= 0x0004000900030016 ){ + if (App.version64 >= 0x0004000900030016) { // Define whether or not to show the options after prompting for a file; // prior to 4.9.3.22 this exporter ignored this option entirely, // running silent was implied by virtue of being run via script - oSettings.setIntValue( "RunSilent", (bShowOptions && !bOptionsBeforeFile ? 0 : 1) ); + oSettings.setIntValue("RunSilent", (bShowOptions && !bOptionsBeforeFile ? 1 : 1)); } - + // Debug //print( oSettings.toJsonString() ); - - // Ensure the path exists - var oDir = new DzDir( sPath ); - oDir.mkdir( sPath ); - - // Write the file using the options specified - oExporter.writeFile( - String( "%1/%2.%3" ).arg( sPath ).arg( sBaseName ).arg( sExt ), - oSettings ); - //print( oSettings.toJsonString() ); - + + // If we've got a node, construct the path using the + // exporter's last path, the node's name, and the + // exporter's extension... + // Otherwise, just use the exporter's last path + + if (App.platform() == DzApp.MacOSX) { + var oDir = new DzDir("/users/Shared/temp3d"); + oDir.mkdir("/users/Shared/temp3d"); + oExporter.writeFile("/users/Shared/temp3d/DazToC4D.fbx", oSettings); + } else { + var oDir = new DzDir("C:/TEMP3D"); + oDir.mkdir("C:/TEMP3D"); + oExporter.writeFile("C:/TEMP3D/DazToC4D.fbx", oSettings); + print(oSettings); + } + // Clean up; don't leak memory oExporter.deleteLater(); - // We didn't find an exporter with the class name we wanted + // We didn't find an exporter with the class name we wanted } else { // Inform the user - MessageBox.critical( qsTr("An exporter with the class name \"%1\" " + - "could not be found.").arg( sClassName ), - qsTr("Critical Error"), qsTr("&OK") ); + MessageBox.critical(qsTr("An exporter with the class name \"%1\" " + + "could not be found.").arg(sClassName), + qsTr("Critical Error"), qsTr("&OK")); } - }; - - // --- END export_fbx_silent ---- - - - //for( var i = 0, n = s_aSkeletons.length; i < n; i += 1 ){ - // heelsFix( s_aSkeletons[i] ); - //} - - exportScene( s_sExporter, s_sExportPath, s_sExportBaseName, s_sExportExt ); - - - // ---------------------------------------------------------- - // ---------------------------------------------------------- - // ---------------------------------------------------------- - // SAVE maps to file... bump, specular, etc.... - // ---------------------------------------------------------- - - - function label2Variable( sLabel ) - { - var sLabelLwr = sLabel.toLowerCase(); - var sAlpha ='abcdefghijklmnopqrstuvwxyz0123456789_'; - var sResult = ''; - for( var i = 0; i < sLabelLwr.length; i += 1 ){ - if( sAlpha.search( sLabelLwr[i] ) >= 0 ){ - sResult += sLabel[i]; - } - - if( sLabelLwr[i] == ' ' ){ - sResult += '_'; - } - } - - if( sResult == "Luminance_cdm^2" ){ - sResult = "Luminance_cdm_2"; + // Finalize the function and invoke + })(); +} + + +// try { +// heelsFix(); +// } catch (error) { } +// DAZ Studio version 4.12.0.86 filetype DAZ Script + +for (i = 0; i < Scene.getNumNodes(); i++) { + // Get the current node + oNode = Scene.getNode(i); + + myTempObj = oNode.getObject(); + if (myTempObj != null && (oNode.inherits( "DzFigure" )== false )) { + pNode = oNode.getNodeParent() + if (pNode != null) + { + pNode.removeNodeChild(oNode,inPlace=true) + debug(oNode.getName()) } + //oNode.removeAllNodeChildren(); - return sResult; - }; - - function fixFilename( sFilename ) - { - return sFilename.replace( "&", "(_)" ); - }; + } + //position + if ( oNode.getXPosControl() ) { + oNode.getXPosControl().lock( true ); + } + if ( oNode.getYPosControl() ) { + oNode.getYPosControl().lock( true ); + } + if ( oNode.getZPosControl() ) { + oNode.getZPosControl().lock( true ); + } + //scale + if ( oNode.getXScaleControl() ) { + oNode.getXScaleControl().lock( true ); + } + if ( oNode.getYScaleControl() ) { + oNode.getYScaleControl().lock( true ); + } + if ( oNode.getZScaleControl() ) { + oNode.getZScaleControl().lock( true ); + } + //rotation + if ( oNode.getXRotControl() ) { + oNode.getXRotControl().lock( true ); + } + if ( oNode.getYRotControl() ) { + oNode.getYRotControl().lock( true ); + } + if ( oNode.getZRotControl() ) { + oNode.getZRotControl().lock( true ); + } - function value2XMLString( oElement, sPropLabel ) +} +exportDaz(); + + +// ---------------------------------------------------------- +// ---------------------------------------------------------- +// ---------------------------------------------------------- +// SAVE maps to file... bump, specular, etc.... +// ---------------------------------------------------------- + + +function label2Variable(label) +{ + var newlabel = label.toLowerCase() + var alpha ='abcdefghijklmnopqrstuvwxyz0123456789_' + var result = '' + for (var i = 0; i < newlabel.length; i++) { - try { - var oProperty = oElement.findPropertyByLabel( sPropLabel ); - - if( oProperty ){ - var sAttrib = label2Variable( sPropLabel ); - var sResult = ''; - var oTexture; - - //oElement.getName() == 'Walls' && - if( sPropLabel == 'Diffuse Texture' ){ - //debug( '12zzzzzzzzzzzzzzzzzzzzzzzzzzzzz ' + sPropLabel + ' ' + oProperty.getValue() ); - if( oProperty.inherits( "DzImageProperty" ) ){ - oTexture = oProperty.getValue(); - if( oTexture ){ - sResult += ' Diffuse_Color_Map="' + fixFilename( oTexture.getFilename() ) + '"'; - } - } - } else { - if( oProperty.inherits( "DzNumericProperty" ) ){ - oTexture = oProperty.getMapValue(); - if( oTexture ){ - sResult = sAttrib + '_Map="' + fixFilename( oTexture.getFilename() ) + '"'; - } - } - - if( oProperty.inherits( "DzColorProperty" ) ){ - var clrVal = oProperty.getColorValue(); - sResult += ' '+ sAttrib + '="Color ' + clrVal.red + ' ' + clrVal.green + ' ' + clrVal.blue + '"'; - } else { - sResult += ' '+ sAttrib + '="'+ oProperty.getValue() + '"'; - } - } - - return( sResult ); + if (alpha.search(newlabel[i])>=0) + result += label[i] + if (newlabel[i] == ' ') + result += '_' + } + if (result == "Luminance_cdm^2") + result = "Luminance_cdm_2" + return result +} +function fixFilename(filename) +{ + filename = filename.replace( "&", "(_)"); + return filename +} +function value2XMLString(mat,propLabel) +{ + try { + var prop = mat.findPropertyByLabel(propLabel); + propType = 1; + //if (mat.getName() =='Walls')// && propLabel=='Diffuse Textture') + // debug('zzzzzzzzzzzzzzzzzzzzzzzzzzzzz '+propLabel) + if (propLabel.search('Color') >=0) propType=2; + if (prop != null) { + var objName = label2Variable(propLabel) + var temp = '' + //mat.getName() =='Walls' && + if ( propLabel=='Diffuse Texture') + { + //debug('12zzzzzzzzzzzzzzzzzzzzzzzzzzzzz '+propLabel+' '+prop.getValue()) + temp += ' Diffuse_Color_Map="'+fixFilename(prop.getValue().getFilename()) +'"'; } - } catch( error ){ - return( '' ); + else + { + + if (prop.getMapValue()!= null) + temp = objName+'_Map="'+fixFilename(prop.getMapValue().getFilename()) +'"'; + + if (propType == 2){ + var color = prop.getColorValue(); + temp += ' '+objName+'="Color '+color.red +' '+color.green +' '+ color.blue +'"'; + } + if (propType == 1){ + temp += ' '+objName+'="'+prop.getValue() +'"'; + } + } + return(temp); } - - return( '' ); - }; + } catch (error) { + return('') + } + return(''); +} +function savePropertiesToFile() { + var sFile; + if (App.platform() == DzApp.MacOSX) { + var sFile = '/users/Shared/temp3d/DazToC4D.xml' + } else { + var sFile = 'C:\\TEMP3D\\DazToC4D.xml' + } - function savePropertiesToFile( sExporter, sExportPath, sExportBaseName, sExportExt ) - { - var sFile = "%1/%2.xml".arg( sExportPath ).arg( sExportBaseName ); - - var oConfigFile = new DzFile( sFile ); - oConfigFile.open( DzFile.WriteOnly ); - - oConfigFile.writeLine( ''.arg( sExportBaseName ).arg( sExportExt ) ); - - var numI = Scene.getNumNodes(); - var numIMat; - var numIShad; - var oNode; - var myTempObj; - var myTempShape; - var myWorkMat; - var myWorkProperty; - // Get the total number of scene nodes - - var listMat = new Array(); - // Iterate over each node - var ii = 0; - for( var i = 0; i < numI; i += 1 ){ - // Get the current node - oNode = Scene.getNode( i ); - myTempObj = oNode.getObject(); - // does it have geometry? - if( myTempObj != null ){ - myTempShape = myTempObj.getCurrentShape(); - // now digging for the materials!! - numIMat = myTempShape.getNumMaterials(); - // iterating aaaagain - for( var j = 0; j < numIMat; j += 1 ){ - myWorkMat = myTempShape.getMaterial( j ); - //debug( myWorkMat.getName() + ' - ' + myWorkMat.getNumProperties() ); - //var allMats = myWorkMat.getAllMaps(); - //var numMaps = allMats.length; - var matName = myWorkMat.getName(); - var n = listMat.length; - //listMat.pushIfNotExists( myTempObj.getName() + '-' + oNode.getLabel() + '-'+ matName ); - listMat.pushIfNotExists( myTempObj.getName() + '-' + matName ); - var n1 = listMat.length; - if( n1 > n ){ - ii += 1; - //debug( i + '/' + ii + '-' + myTempObj.getName() + '-' + matName ); - //debug( i + '/' + ii + '-' + oNode.getLabel() + '-' + matName ); - var matText = ' '); + } + else { + oConfigFile.writeLine(''); + } + numI = Scene.getNumNodes(); + var i, j, k, numI, numIMat, numIShad; + var oNode; + var myTempObj; + var myTempShape; + var myWorkMat; + var myWorkProperty; + // Get the total number of scene nodes + + var listMat = new Array(); + // Iterate over each node + var ii = 0; + for (i = 0; i < numI; i++) { + // Get the current node + oNode = Scene.getNode(i); + myTempObj = oNode.getObject(); + // does it have geometry? + if (myTempObj != null) { + myTempShape = myTempObj.getCurrentShape(); + // now digging for the materials!! + numIMat = myTempShape.getNumMaterials(); + // iterating aaaagain + for (j = 0; j < numIMat; j++) { + myWorkMat = myTempShape.getMaterial(j); + //debug(myWorkMat.getName()+' - '+ myWorkMat.getNumProperties()); + //var allMats = myWorkMat.getAllMaps(); + //var numMaps = allMats.length; + var matName = myWorkMat.getName(); + var n = listMat.length; + //listMat.pushIfNotExists(myTempObj.getName()+'-'+oNode.getLabel()+'-'+matName); + listMat.pushIfNotExists(myTempObj.getName()+'-'+matName); + var n1 = listMat.length; + if (n1> n) + { + ii += 1; + //debug(i+'/'+ii+'-'+myTempObj.getName()+'-'+matName) + debug(i+'/'+ii+'-'+oNode.getLabel()+'-'+matName) + var matText = ' nn ){ - var temp = value2XMLString( myWorkMat, myWorkMat.getProperty( k ).getLabel() ); - if( temp != '' ){ - matText += ' ' + temp; - } - } - //debug( i + ' ' + myWorkMat.getProperty( i ).getLabel() + ' - ' + myWorkMat.getProperty( i ).getPath() ); - } - matText += '/>'; - oConfigFile.writeLine( matText ); + for ( var k = 0; k < myWorkMat.getNumProperties(); k++ ) { + var temp = value2XMLString(myWorkMat,myWorkMat.getProperty(k).getLabel()); + if (temp != '') matText += ' '+temp; + //debug(i + ' '+myWorkMat.getProperty(i).getLabel()+ ' - '+myWorkMat.getProperty(i).getPath()) } + matText += '/>'; + oConfigFile.writeLine(matText); } } - //the second iteration is ended above + } - oConfigFile.writeLine( '' ); - oConfigFile.close(); - }; - - savePropertiesToFile( s_sExporter, s_sExportPath, s_sExportBaseName, s_sExportExt ); - -})(); \ No newline at end of file + //the second iteration is ended above + } + oConfigFile.writeLine(''); + oConfigFile.close(); +} + +savePropertiesToFile(); +