Does RemoveParameter really remove the parameter?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 08 August 2008   #1
Does RemoveParameter really remove the parameter? [solved]

Hi all,

Iím new to the whole programming thing, but Iím trying to find my way through as a noob in the so exciting world of code. However, Iím stuck here for quite a while and I canít seem to get my head around it. Bare with me while I try to explain what I try to achieve. The code I added with this message can be run in the script editor and shows where my problem will be when you follow the explanation below.

First I create a custom property that does all kinds of stuff. When the button is pressed, depending what the outcome was a second custom property page is created with a parameter (combo box). This is represented by one push on one of the buttons.

Secondly you can push that same button another time, and more if you like. It will delete the existing second property and create a new one.

If the other button is pressed, the same second property will be used, and a new combo box will be added to it.

Now when one of the buttons are pressed again, one of the parameters from the custom property is deleted, but in the property page itself the combo box, related to this parameter, is still there. Checking the SDK Explorer, the parameter is clearly gone. I guess I need to refresh the PPGLayout somehow but all I tried seem to fail.

I hope my problem is clear, if not, please ask. I know Iím not really good in explaining. Sorry for that.

Here's the code in JScript:
var myButtonProp = Application.ActiveSceneRoot.AddCustomProperty("ButtonProp", false ) ;
   var oLayout = myButtonProp.PPGLayout;
   oLayout.AddButton("Button1");
   oLayout.AddButton("Button2");
   
   oLayout.Language = "Jscript" ;
   oLayout.Logic = Button1_OnClicked.toString() +
   			Button2_OnClicked.toString() +
   			createSecondProp.toString();
   
   InspectObj( myButtonProp ) ;
   
   function Button1_OnClicked ()
   {
      logmessage("pushed button 1");
      
      createSecondProp( "Button1Combo", "Button2Combo");
   }
   
   function Button2_OnClicked ()
   {
      logmessage("pushed button 2");
      
      createSecondProp( "Button2Combo", "Button1Combo");
   }
   
   function createSecondProp ( strAddCombo, strKeepCombo)
   {
      var oldSet, newSet;
      var oLayout;
      var bKeepPar = false, bRemovePar = false;
      var aCombo = new Array("one", 1, "two", 2, "three", 3);
      var oDeletePar;
      
      oldSet = Application.ActiveSceneRoot.Properties.item("SecondProp") ;
      
      // If the second prop doesn't exist yet, create it.
      if (oldSet == null)
      {
   	  newSet = Application.ActiveSceneRoot.AddCustomProperty("SecondProp", false ) ;
      }
      else
      {
   	  // Check the parameters of the second property.
   	  var oPar = oldSet.NestedObjects;
   	  for (i = 0; i < oPar.count; i++)
   	  {
   		 var oParName = oPar(i).Name;
   		 if (oParName == strKeepCombo)
   		 {
   			//If there is a parameter we want to keep, set the boolean true
   			bKeepPar = true;
   		 }
   		 if (oParName == strAddCombo)
   		 {
   			//If there is already a parameter of the same kind, we want to remove it
   			bRemovePar = true;
   			oDeletePar = oPar(i);
   		 }
   	  }
   
   	  if (bKeepPar)
   	  {
   		 if (bRemovePar)
   		 {
   			//remove the parameter that is not wanted.
   			oldSet.RemoveParameter(oDeletePar);
   		 }
   		 //The previous set can be used
   		 newSet = oldSet;
   	  }
   	  else
   	  {
   		 //If th existing parameters aren4t needed anymore, the property can be deleted and made from scratch.
   		 DeleteObj("Scene_Root.SecondProp");
   		 newSet = Application.ActiveSceneRoot.AddCustomProperty("SecondProp", false ) ;
   	  }
      }
      
      //now the new combo box can be added.
      newSet.AddParameter3(strAddCombo, siInt4) ;
   
      oLayout = newSet.PPGLayout ;
      
      oLayout.AddEnumControl(
   	  strAddCombo, 
   	  aCombo, 
   	  strAddCombo, 
   	  siControlCombo) ;
   
      oLayout.Language = "JScript" ;
      InspectObj( newSet ) ;
   }


Last edited by DracoDralion : 08 August 2008 at 10:24 AM. Reason: titlz changed
 
Old 08 August 2008   #2
Solution

After a good night sleep I found the solution to my problem. Not sure if it's the best way to go, but it works. Any other sugestions are still welcome.

Here's the code, if there are any questions, just shoot them:
var myButtonProp = Application.ActiveSceneRoot.AddCustomProperty("ButtonProp", false ) ;
 var oLayout = myButtonProp.PPGLayout;
 oLayout.AddButton("Button1");
 oLayout.AddButton("Button2");
 
 oLayout.Language = "Jscript" ;
 oLayout.Logic = Button1_OnClicked.toString() +
 				Button2_OnClicked.toString() +
 				createSecondProp.toString();
 
 InspectObj( myButtonProp ) ;
 
 function Button1_OnClicked ()
 {
 	logmessage("pushed button 1");
 	
 	createSecondProp( "Button1Combo", "Button2Combo");
 }
 
 function Button2_OnClicked ()
 {
 	logmessage("pushed button 2");
 	
 	createSecondProp( "Button2Combo", "Button1Combo");
 }
 
 function createSecondProp ( strAddCombo, strKeepCombo)
 {
 	var oldSet, newSet;
 	var oLayout;
 	var bKeepPar = false, bRemovePar = false;
 	var aCombo = new Array("one", 1, "two", 2, "three", 3);
 	var oDeletePar;
 	
 	oldSet = Application.ActiveSceneRoot.Properties.item("SecondProp") ;
 	
 	// If the second prop doesn't exist yet, create it.
 	if (oldSet == null)
 	{
 		newSet = Application.ActiveSceneRoot.AddCustomProperty("SecondProp", false ) ;
 	}
 	else
 	{
 		// Check the parameters of the second property.
 		var oPar = oldSet.NestedObjects;
 		for (i = 0; i < oPar.count; i++)
 		{
 			var oParName = oPar(i).Name;
 			if (oParName == strKeepCombo)
 			{
 				//If there is a parameter we want to keep, set the boolean true
 				bKeepPar = true;
 			}
 			if (oParName == strAddCombo)
 			{
 				//If there is already a parameter of the same kind, we want to remove it
 				bRemovePar = true;
 				oDeletePar = oPar(i);
 			}
 		}
 
 		if (bKeepPar)
 		{
 			if (bRemovePar)
 			{
 				//remove the parameter that is not wanted.
 				oldSet.RemoveParameter(oDeletePar);
 				
 				var oldLayout = oldSet.PPGLayout;
 				oldItem = oldLayout.Item(strAddCombo);
 				
 				//Change the label and the UIITems, just to see if it works.
 				oldItem.Label = "NewLabel";
 				oldItem.UIItems = new Array( "een", 1, "twee", 2);
 			}
 			//The previous set can be used
 			newSet = oldSet;
 		}
 		else
 		{
 			//If th existing parameters aren't needed anymore, the property can be deleted and made from scratch.
 			DeleteObj("Scene_Root.SecondProp");
 			newSet = Application.ActiveSceneRoot.AddCustomProperty("SecondProp", false ) ;
 		}
 	}
 	
 	//now the new combo box can be added.
 	newSet.AddParameter3(strAddCombo, siInt4) ;
 
 	oLayout = newSet.PPGLayout ;
 	
 	//The Combo box should only be added if it doesn't exist yet.
 	if(!bKeepPar || (bKeepPar && !bRemovePar))
 	{
 		oLayout.AddEnumControl(
 			strAddCombo, 
 			aCombo, 
 			strAddCombo, 
 			siControlCombo) ;
 	}
 	
 	oLayout.Language = "JScript" ;
 	InspectObj( newSet ) ;
 }
 
 
Old 08 August 2008   #3
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 08:44 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.