daz script source: injecting ERC Links in a PP2 File
mCasual
Posts: 4,607
i created a prop with 8 holes and a pipe
each hole rim has 4 morphs attached to it
because i want it to be fully customizable
but this means 144 morphs
so for convenience i created ERC Links to group all this in 28 controls
but Duke533's good old PP2 Exporter script doesn't write those in the PP2 file
so i created the code below
which creates the 28 'master' controls
and inserts the many ERC Links
everything is hard-coded but the ideas are all there
the precious piece of information that took some digging is
when the master channels are not in a figure but in the prop itself
you use this
valueOpDeltaAdd Figure propName masterchannelname, deltaAddDelta 1.000000
as you can see the Figure name is ... nothing
possibly you can use the word _NO_FIG_ or _NONE_
// DAZ Studio version 3.1 filetype DAZ Script// you must load the prop named "mcjTwinQuadPlateOnePipe" in the scene// You must hard-code the path to the source pp2 file and output file// in my case it's a prop file created by Duke533's script PP2 Exporter// re-named oldmcjTwinQuadPlateOnePipe.pp2// this prop file lacks ERC Links// the script herein will use lists of prefixes and suffixes to put// the 144 morphs under the control of around 28 'master' controls// basically it creates ERC Linksvar g_propName = "mcjTwinQuadPlateOnePipe";var g_valueParams = new Array();var g_assignments = new Array();process();//==============================================================================////==============================================================================function process(){ var path_runtime = "C:/Program Files (x86)/DAZ/Studio/content/Runtime/" var path_props = path_runtime + "libraries/props/"; var path_myProps = path_props + "mcasual/" // Warning !! the prop was manually renamed to old_mcjTwinQuadPlateOnePipe.pp2 // and we are about to write or OVERWRITE mcjTwinQuadPlateOnePipe.pp2 var filenameIn = path_myProps + "old" + g_propName + ".pp2" var filenameOut = path_myProps + g_propName + ".pp2" // morph channels with names containing these key words // will be controlled by master channels with names like // "AllHolesSharp", "AllTopHolesSharp" ... AllPipesSharp" // "AllHolesRadius", "AllTopHolesRadius" ... AllPipesRadius" var groups = [ "Hole", "TopHole", "BotHole", "Corner", "TopCorner", "BotCorner", "Pipe" ]; var subGroups = [ "Sharp", "Radius", "AwayX", "AwayZ" ]; // create the list of valueParams ( master channels ) // and the list of valueOp ( links from each morph to its many masters ) buildAssignments( groups, subGroups ); var currentMorph = "nah"; //current opened morph block in the prop file var key2 = "interpStyleLocked"; var fIn = new DzFile( filenameIn ); if( !fIn ) return( 1 ); var ok = fIn.open( fIn.ReadOnly ); if( !ok ) return( 2 ); var fOut = new DzFile( filenameOut ); if( !fOut ) return( 3 ); var ok = fOut.open( fOut.WriteOnly ); if( !ok ) return( 4 ); var state = 0; //state-machine state while( !fIn.eof() ) { var str = fIn.readLine(); switch( state ) { case 0: //waiting for first morph var nuMorph = readMorph( str ); if( nuMorph ) { currentMorph = nuMorph; printMasters( fOut ); state = 2; } fOut.write( str ); break; case 1: //waiting for morph var nuMorph = readMorph( str ); if( nuMorph ) { currentMorph = nuMorph; state = 2; } fOut.write( str ); break; case 2: //waiting for insertion point var p = str.indexOf( key2 ); if( p >= 0 ) { assign( fOut, currentMorph ); state = 1; } fOut.write( str ); break; } } fIn.close(); fOut.close();}//==============================================================================////==============================================================================function readMorph( str ){ var key1 = "targetGeom"; var currentMorph; var p = str.indexOf( key1 ); if( p >= 0 ) { currentMorph = str.replace( "\n", "" ); currentMorph = currentMorph.replace( "\r", "" ); currentMorph = currentMorph.right( currentMorph.length - ( p + 1 + key1.length ) ); return( currentMorph ) } return( 0 );}//==============================================================================////==============================================================================function valueOp( fOut, name ){ var strs = [ " valueOpDeltaAdd", " Figure", " " + g_propName, " " + name, " deltaAddDelta 1.000000", ]; var n = strs.length; for( var i = 0; i < n; i++ ) { fOut.writeLine( strs[ i ] ); }}//==============================================================================////==============================================================================function printMasters( fOut ){ var n = g_valueParams.length; for( var i = 0; i < n; i++ ) { valueParm( fOut, g_valueParams[ i ] ); }} //==============================================================================////==============================================================================function valueParm( fOut, name ){ var strs = [ " valueParm "+name+"", " {", " name "+name+"", " initValue 1.00", " hidden 0", " forceLimits 0", " min -1.00", " max 1.00", " trackingScale 0.01", " keys", " {", " static 0", " k 0 0.00", " }", " interpStyleLocked 0", " } " ]; var n = strs.length; for( var i = 0; i < n; i++ ) { fOut.writeLine( strs[ i ] ); }}//==============================================================================////==============================================================================function buildAssignments( groups, subGroups ){ var morphableNode = Scene.findNodeByLabel( g_propName ); var obj = morphableNode.getObject(); var numModifiers = obj.getNumModifiers(); debug( numModifiers + " modifiers" ); var ngroups = groups.length; for( var j = 0; j < ngroups; j++ ) { var group = groups[j]; for( var i = 0; i < numModifiers; i++ ) { var mod = obj.getModifier( i ); if( mod.inherits( "DzMorph" ) ) { var modname = mod.name; var nSubGroups = subGroups.length; for( k = 0; k < nSubGroups; k++ ) { var subGroup = subGroups[k]; if( modname.indexOf( subGroup ) >= 0 ) { if( modname.indexOf( group ) >= 0 ) buildAssignment( "All" + group + "s" + subGroup, modname ); } } } } }}//==============================================================================////==============================================================================function buildAssignment( ctlname, modname ){ g_valueParams.pushIfNotExists( ctlname ) g_assignments.push( [ctlname, modname] )}//==============================================================================////==============================================================================function assign( fOut, morphName ){ var n = g_assignments.length for( var i = 0; i < n; i++ ) { if( g_assignments[ i ][1] == morphName ) { valueOp( fOut, g_assignments[ i ][0] ) debug( g_assignments[ i ] ); } } }
Post edited by Richard Haseltine on
Comments
note: the initial phase builds the list of controllers to be added
and the list of ERC Links like this
the mcjTwinQuadPlateOnePipe prop
groupings by calling this immediately before the call to printMasters()
i read that this is a Poser 5 feature, so, better specify version 5 in the pp2 header because i think by default it's version 4