PDA

View Full Version : Trouble with saving out weights


Funkenstein
05-11-2008, 06:50 AM
Im trying to make a script that will load a preset file from a directory. Now this will work everytime IF I remove the envelope, re-envelope then run this script. If i do not remove the envelope then i get an error the second time i run the script.

Here is my script:

var oPPG = XSIFactory.CreateObject("CustomProperty")
oPPG.Name = "Load Weights" ;

oPPG.AddParameter3( "Directory", siString );

var oLayout = oPPG.PPGLayout

oLayout.AddItem( "Directory", "Path", siControlFolder ) ;
oLayout.AddButton( "Load" ) ;

oLayout.Logic = Load_OnClicked.toString() ;
oLayout.Language = "JScript" ;

InspectObj( oPPG,null,"Load Weights" );


function Load_OnClicked()
{

GeoToWeight = SelectAllUsingFilter("PolygonMesh", siIgnoreComponentVisibility, 1, 0);
for (i = 0; i < GeoToWeight.count; i++)
{
logmessage(Directory + "\\" + GeoToWeight(i) + ".Preset");
SILoadPreset(Directory + "\\" + GeoToWeight(i) + ".Preset", GeoToWeight(i) + ".polymsh.cls.EnvelopWeightCls.Envelope_Weights");
}
DeleteObj( PPG.Inspected ) ;
PPG.Close() ;

}


If it works this i what I get:

SetValue("customparamset<19225>.Directory", "I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights", null);
SelectAllUsingFilter("PolygonMesh", siIgnoreComponentVisibility, 1, null);
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport8.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport8.Preset", "headusOBJexport8.polymsh.cls.EnvelopWeightCls.Enve lope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport6.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport6.Preset", "headusOBJexport6.polymsh.cls.EnvelopWeightCls.Enve lope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport9.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport9.Preset", "headusOBJexport9.polymsh.cls.EnvelopWeightCls.Enve lope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport17.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport17.Preset", "headusOBJexport17.polymsh.cls.EnvelopWeightCls.Env elope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polym sh4.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ polymsh4.Preset", "polymsh4.polymsh.cls.EnvelopWeightCls.Envelope_Wei ghts");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\Jerki nFlaps.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ JerkinFlaps.Preset", "JerkinFlaps.polymsh.cls.EnvelopWeightCls.Envelope_ Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polym sh8.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ polymsh8.Preset", "polymsh8.polymsh.cls.EnvelopWeightCls.Envelope_Wei ghts");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\Jerki n_FINAL.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ Jerkin_FINAL.Preset", "Jerkin_FINAL.polymsh.cls.EnvelopWeightCls.Envelope _Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polym sh.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ polymsh.Preset", "polymsh.polymsh.cls.EnvelopWeightCls.Envelope_Weig hts");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polym sh9.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ polymsh9.Preset", "polymsh9.polymsh.cls.EnvelopWeightCls.Envelope_Wei ghts");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport11.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport11.Preset", "headusOBJexport11.polymsh.cls.EnvelopWeightCls.Env elope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport5.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport5.Preset", "headusOBJexport5.polymsh.cls.EnvelopWeightCls.Enve lope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport10.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\ headusOBJexport10.Preset", "headusOBJexport10.polymsh.cls.EnvelopWeightCls.Env elope_Weights");
DeleteObj("customparamset<19239>");


And if it fails I get this:

SetValue("customparamset<19239>.Directory", "I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights", null);
SelectAllUsingFilter("PolygonMesh", siIgnoreComponentVisibility, 1, null);
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headu sOBJexport8.Preset
SILoadPreset(null, "headusOBJexport8.polymsh.cls.EnvelopWeightCls.Enve lope_Weights");
// ERROR : 2000 - Argument 1 (InputObj) is invalid
// ERROR : 2001-FILE-SILoadPreset - Argument 1 is invalid
// ERROR : Invalid procedure call or argument - [line 8]
// ERROR : Property Page Script Logic Error (Microsoft JScript runtime error)
// ERROR : [6] {
// ERROR : [7] logmessage(Directory + "\\" + GeoToBind(i) + ".Preset");
// ERROR : >[8] SILoadPreset(Directory + "\\" + GeoToBind(i) + ".Preset", GeoToBind(i) + ".polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// ERROR : [9] (null)
// ERROR : [10] }
// ERROR : Invalid procedure call or argument

Even though in the //Info i get the correct path.

Anyone know whats wrong?

Thanks in advance.

Sinchi
06-05-2008, 10:02 AM
I think your error is on this line :
SILoadPreset(Directory + "\\" + GeoToWeight(i) + ".Preset", GeoToWeight(i) + ".polymsh.cls.EnvelopWeightCls.Envelope_Weight s");

You are assuming that your weight property is name "Envelope_Weight", but this name changes when you load a preset and takes the name of the preset. That is why it works when you remove the envelope and apply a new one since the name then resets to "Envelope_Weight"

You should get a handle to the weight property before running this line and pass the object as the argument. This way it would work whatever the name is.

Hope this helps ;)

Funkenstein
06-05-2008, 11:42 AM
wow I didnt expect anyone to reply ^^

I can see now why it wasnt working. Im gonna try to fix this tonight.

Thanks!

floyd1510
06-30-2008, 03:30 AM
Hi Carlos,

Can you please explain getting a handle to the weight property before running the line and pass the object as the argument, from an example of code. Hopefully this is not a stupid question.

Cheers,
Vikram.

Funkenstein
06-30-2008, 01:56 PM
Here is working code on how to save out weights

var oPPG = XSIFactory.CreateObject("CustomProperty")
oPPG.Name = "SaveWeights" ;
oPPG.AddParameter3( "Directory", siString );
oLayout = oPPG.PPGLayout
oLayout.AddItem( "Directory", "Path", siControlFolder ) ;
oLayout.AddButton( "Export" ) ;
oLayout.Logic = Export_OnClicked.toString() ;
oLayout.Language = "JScript" ;
InspectObj( oPPG,null,"Export Weights" );
function Export_OnClicked()
{
GeoToBind = SelectAllUsingFilter("PolygonMesh", siIgnoreComponentVisibility, 1, null);
for (i = 0; i < GeoToBind.count; i++)
{
var oObj = GeoToBind(i);
var oGeometry = oObj.activeprimitive.geometry.clusters;
for (j =0; j < oGeometry.count; j++)
{
myNewObj = oGeometry(j).FullName;
if(myNewObj.indexOf ( "Envelop") != "-1")
SavePreset(oGeometry(j), oObj + ".Preset", Directory, null, null, null, null);
}
}
DeleteObj( PPG.Inspected ) ;
PPG.Close() ;
}

Sinchi
07-08-2008, 04:46 PM
Hi Vikram,

Sorry for the delay, I was in vacations.

Here's an old piece of vbscript to get the envolope cluster :


Function FindEnvWeightsCluster(oGeo)
'This function returns the first envelope cluster property found on oGeo

'declare variables
dim oClusters, oCls, oClsProps, oProp


'Init variables
set FindEnvWeightsCluster = Nothing
set oClusters = oGeo.ActivePrimitive.Geometry.Clusters

'Find envelope cluster property

for each oCls in oClusters
set oClsProps = oCls.Properties
for each oProp in oClsProps
if oProp.type = "envweights" then
set FindEnvWeightsCluster = oProp
exit function
end if
next
next
End Function


From there you can use that to load a preset on that cluster property. For example :


PresetPath = Application.InstallationPath( siUserPath ) & "\Data\DSPresets\Properties\"
PresetFile = PresetPath&"WeightTransfer.Preset"
set oEnvWeightsCluster = FindEnvWeightsCluster(MyGeo)
LoadPreset PresetFile, oEnvWeightsCluster.fullname


I hope this helps ;)

floyd1510
08-11-2008, 08:52 PM
Thanks a lot Carlos and Joe. Worked like a charm:clap:

Sinchi
09-16-2008, 04:25 PM
Just for reference, here is another way to get the envelope weights property and the envelope cluster of an envelope operator.


function GetEnvWeightsProperty(oEnvelope)
dim oPort
set oPort = oEnvelope.PortAt( 4, 0, 0 )
set GetEnvWeightsProperty = oPort.Target2
end function

function GetEnvCluster(oEnvelope)
dim oPort
set oPort = oEnvelope.PortAt( 3, 0, 0 )
set GetEnvCluster= oPort.Target2
end function

'Example of use on first selected object
logmessage GetEnvWeightsProperty(selection(0).envelopes(0))
logmessage GetEnvCluster(selection(0).envelopes(0))