(This thread is a continuation of the "follow-on stuff" that was going on in the DS: Creating a slider on the Parameters tab that can ONLY have integer values (+follow-on stuff...) thread over on the Technical Help forum)
I've now created very simple test script to apply bidirectional linking of parameters on the Surfaces tab to parmeters on the Parameters tab.
The script was cobbled together from bits of the post_load_material_proxy_create.dsa and post_load_material_proxy_link_properties.dsa sample scripts and the DzSettings documentation, replacing the ephemeral 'DataItem' with good old hard-coded stuff.
I left the script using the bidirectional DzNumericProperty::linkTo() to set up the links because I couldn't work out how to create a unidirectional DzERCLink (the DzERCLink constructors creating 'controllers' is one level of Object Obfuscation beyond me at present!)
The main problem I'd come up against over on the other thread was that applying a material preset sometimes (i.e. under certain criteria) breaks these links.
What I'm trying to do is find a way to maintain (or reinstate) these links when (after) a material preset has been applied.
Use of the DzCallBack was proposed as a solution, but I really can't get my head around that stuff.
So that's the introduction to what this thread is about.
Here's the script in-line if you don't want to download it but could do with a laugh!
// This is just a simple test script to apply BIdirectional linking of parameters
// HOW TO USE:
// - Open DS4.8+,
// - Create a primitive sphere
// - apply a texture to the Diffuse Color (one that make changes to tiling offsets obvious)
// - create two new float parameters on the parameters tab (in a new group/path called 'TEST',or anything you want) - names are "Vertical Offset" and "Horizontal Offset"
// - run this script
// The tiling offsets on the Surfaces tab are now BIdirectionally linked to the twonewsliders on the parameters tab
MessageBox.information("STARTED...","INFO","OK");
var sSettings = [
'<Settings>',
' <Setting Type="Float" Key="Horizontal Offset">0</Setting>',
' <Setting Type="Float" Key="Vertical Offset">0</Setting>',
'</Settings>'
].join( "\n" );
var aNodes = Scene.getSelectedNodeList();
if ( aNodes.length == 1 ){
var oNode = aNodes[0];
var sName = "Default" // The material we're going to work with
if( oNode ){
var oObject = oNode.getObject();
if( oObject ){
var oShape = oObject.getCurrentShape();
if( oShape ){
var oMaterial = oShape.findMaterial( sName );
if( oMaterial ){
MessageBox.information("...FOUND MATERIAL","INFO","OK");
// var oPropertySettings = oSettings.getSettingsValue( "properties" );
var oPropertySettings = new DzSettings();
if( oPropertySettings.fromString( sSettings ) ){
MessageBox.information("Read of XML encoded data was successful.","INFO","OK");
print ("oPropertySettings = "+oPropertySettings);
if( oPropertySettings ){
MessageBox.information("...FOUND PROPERTY SETTINGS","INFO","OK");
var oMaterialProperty, oProxyProperty;
var sPropertyName, sProxyName;
// Iterate over the properties
for( var i = 0, nProps = oPropertySettings.getNumValues(); i < nProps; i += 1 ){
sPropertyName = oPropertySettings.getKey( i );
MessageBox.information("Searching for "+sPropertyName,"INFO","OK");
oMaterialProperty = oMaterial.findProperty( sPropertyName );
if( oMaterialProperty ){
MessageBox.information("...FOUND MATERIAL PROPERTY","INFO","OK");
sProxyName = String("%1 %2 Proxy").arg( oMaterial.name ).arg( sPropertyName );
sProxyName = oMaterial.name
print ("sProxyName = "+sProxyName);
//oProxyProperty = oNode.findProperty( sProxyName );
oProxyProperty = oNode.findProperty( sPropertyName );
if( oProxyProperty ){
MessageBox.information("...FOUND PROXY PROPERTY","INFO","OK");
if( oMaterialProperty.inherits( "DzNumericProperty" ) ){
oMaterialProperty.linkTo(oProxyProperty);
MessageBox.information("...SUCCESS!...","INFO","OK");
}
}
}
}
}
} else {
MessageBox.information("Could not read XML encoded data.","INFO","OK");
}
}
}
}
}
}
MessageBox.information("...FINISHED","INFO","OK");
Edit: Note that if the "Vertical/Horizontal Offset"values on the Parameters tab and/or the Surfaces tab are given non-zero values before running the script, then the "Vertical/Horizontal Offset" values on the Surfaces tab will be set to match those on the Parameters tab after running the script. So those on the Parameters tab are the 'masters'. which makes sense from the DzNumericProperty::linkTo() documentation - you call the method on the slave property, and pass the master property,i.e. 'oMaterialProperty.linkTo(oProxyProperty);'