Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / Trouble with saving out weights
  RSS 2.0 ATOM  

Trouble with saving out weights
Rate this thread
 
30101
 
Permlink of this thread  
avatar
  • Total Posts: 7
  • Joined: 05 March 2008 03:49 PM

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\headusOBJexport8.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport8.Preset", “headusOBJexport8.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport6.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport6.Preset", “headusOBJexport6.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport9.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport9.Preset", “headusOBJexport9.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport17.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport17.Preset", “headusOBJexport17.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polymsh4.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\polymsh4.Preset", “polymsh4.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\JerkinFlaps.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\JerkinFlaps.Preset", “JerkinFlaps.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polymsh8.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\polymsh8.Preset", “polymsh8.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\Jerkin_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\polymsh.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\polymsh.Preset", “polymsh.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\polymsh9.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\polymsh9.Preset", “polymsh9.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport11.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport11.Preset", “headusOBJexport11.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport5.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport5.Preset", “headusOBJexport5.polymsh.cls.EnvelopWeightCls.Envelope_Weights");
// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport10.Preset
SILoadPreset("I:\\ShadowAwaits\\Characters\\ReUse_Rig\\weights\\headusOBJexport10.Preset", “headusOBJexport10.polymsh.cls.EnvelopWeightCls.Envelope_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);
[B]// INFO : I:\ShadowAwaits\Characters\ReUse_Rig\weights\headusOBJexport8.Preset[/B]
SILoadPreset(null, “headusOBJexport8.polymsh.cls.EnvelopWeightCls.Envelope_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.



Replies: 0
avatar
  • Sinchi
  • Posted: 05 June 2008 02: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 ;)



Replies: 0
avatar

wow I didnt expect anyone to reply ^^

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

Thanks!



Replies: 0
avatar

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.



Replies: 0
avatar

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() ;
}



Replies: 0
avatar
  • Sinchi
  • Posted: 08 July 2008 08:46 AM

Hi Vikram,

Sorry for the delay, I was in vacations.

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

[SIZE=2]Function FindEnvWeightsCluster(oGeo)
[INDENT]'This function returns the first envelope cluster property found on oGeo
 
'
declare variables
dim oClusters
oClsoClsPropsoProp

 
'Init variables
set FindEnvWeightsCluster = Nothing
set oClusters = oGeo.ActivePrimitive.Geometry.Clusters 
 
'
Find envelope cluster property

for each oCls in oClusters 
[INDENT]set oClsProps 
oCls.Properties 
for each oProp in oClsProps
[INDENT]if oProp
.type "envweights" then
[INDENT]set FindEnvWeightsCluster 
oProp
exit function
[/INDENT]end if
[/INDENT]next 
[
/INDENT]next 
[
/INDENT]End Function[/SIZE]


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

PresetPath Application.InstallationPathsiUserPath ) & "\Data\DSPresets\Properties\"
PresetFile PresetPath&"WeightTransfer.Preset"
set oEnvWeightsCluster FindEnvWeightsCluster(MyGeo)
LoadPreset PresetFileoEnvWeightsCluster.fullname


I hope this helps ;)



Replies: 0
avatar

Thanks a lot Carlos and Joe. Worked like a charm:clap:



Replies: 0
avatar
  • Sinchi
  • Posted: 16 September 2008 08:25 AM

Just for reference, here is another way to get the envelope weights property and the envelope cluster of an envelope operator.

[SIZE=2][SIZE=2]function GetEnvWeightsProperty(oEnvelope)
[INDENT]dim oPort
set oPort 
oEnvelope.PortAt40
set GetEnvWeightsProperty oPort.Target2
[
/INDENT]end function
 
function 
GetEnvCluster(oEnvelope)
[INDENT]dim oPort
set oPort 
oEnvelope.PortAt30
set GetEnvClusteroPort.Target2
[
/INDENT]end function
 
'Example of use on first selected object
logmessage GetEnvWeightsProperty(selection(0).envelopes(0))
logmessage GetEnvCluster(selection(0).envelopes(0))
[/SIZE] 
[/SIZE]


Replies: 0