Dynamic combo boxes and disappearing global variables

If you are using dynamic combo boxes in a self-installing property you need to be aware that calling PPG.Refresh() will also flush your global variables as the plugin below demonstrates. If you are wondering if your globals are being flushed the ReloadCheck() object is a handy way of detecting this condition.

If you want to keep data around that is associated with the instance of the property define non-persisted parameters on the property to store your global data. The GridData is handly object for containing list of things. Unfortunately there's no way of storing a object on the customproperty - that would be handly.

The plugin below demonstrates the problem

SIAddProp("MyGlobals", "", "siDefaultPropagation", "", "");
// INFO : Warning: globals flushed
//  VERBOSE : MyGlobals_OnInit called
// Press ChangeList Button
//  VERBOSE : MyGlobals_ChangeList_OnClicked called
//  INFO : Warning: globals flushed
// Press PrintList Button
//  VERBOSE : MyGlobals_PrintList_OnClicked called
// <<ERROR you where expecting Dog, Cat, Fish to be printed
// MyGlobalsPlugin

var gItems1 = Array("Orange",0, "Pear",1, "Banana",2);
var gItems2 = Array("Dog",0, "Cat",1, "Fish", 2 )
var gItems = Array();

var gReloadCheck = new ReloadCheck();
function ReloadCheck()
{
	Application.LogMessage("Warning: globals flushed");
}

function XSILoadPlugin( in_reg )
{
	in_reg.Author = "sinwood";
	in_reg.Name = "MyGlobalsPlugin";
	in_reg.Email = "";
	in_reg.URL = "";
	in_reg.Major = 1;
	in_reg.Minor = 0;

	in_reg.RegisterProperty("MyGlobals");
	//RegistrationInsertionPoint - do not remove this line

	return true;
}

function XSIUnloadPlugin( in_reg )
{
	var strPluginName;
	strPluginName = in_reg.Name;
	Application.LogMessage(strPluginName + " has been unloaded.",siVerbose);
	return true;
}

function MyGlobals_Define( in_ctxt )
{
	var oCustomProperty = in_ctxt.Source;
	oCustomProperty.AddParameter2("Param",siInt4,0,0,100,0,100,siClassifUnknown,siPersistable | siKeyable);
	return true;
}

function MyGlobals_DefineLayout( in_ctxt )
{
	var oLayout,oItem;
	oLayout = in_ctxt.Source;
	oLayout.Clear();

	oLayout.AddEnumControl("Param", gItems1, "Dynamic Combo", siControlCombo );
	oLayout.AddButton("ChangeList","Change List");
	oLayout.AddButton("PrintList","Print List");

	return true;
}

function MyGlobals_OnInit( )
{
	Application.LogMessage("MyGlobals_OnInit called",siVerbose);
	gItems = gItems1;
}

function MyGlobals_OnClosed( )
{
	Application.LogMessage("MyGlobals_OnClosed called",siVerbose);
}

function MyGlobals_ChangeList_OnClicked( )
{
	Application.LogMessage("MyGlobals_ChangeList_OnClicked called",siVerbose);

	gItems = gItems2;
	PPG.PPGLayout.Item("Param").UIItems = gItems;
	PPG.Refresh();
}

function MyGlobals_PrintList_OnClicked( )
{
	Application.LogMessage("MyGlobals_PrintList_OnClicked called",siVerbose);

	for (var idx=0; idx< gItems.length; idx++)
	{
		Application.LogMessage("Item" + idx + "=" + gItems[idx]);
	}	
}


This page was last modified 14:00, 19 Nov 2008.
This page has been accessed 3673 times.

© Copyright 2009 Autodesk Inc. All Rights Reserved. Privacy Policy | Legal Notices and Trademarks | Report Piracy