This sample shows the use of both class and instance level scripts. The scripts change the display name of the object they are implemented on. In order to script at this class leve, this sample has a custom type under Types, named "My Sphere".
Click on the image to download the sample.
| 
|
This type inherits from a regular Sphere, the difference is a single even script. The script is for the OnStartUChanged event. The script is as follows:
IObject startUProperty = context.Site.GetPropertyByName("StartU"); string val = context.Site.GetValueAsString(startUProperty); context.Site.DisplayName = val;
This script gets the startU property value as a string, from the instance. It then sets this as the property grid display name for the instance.
There are two instances of MySphere in the scene. Their names are a numerical value. This is likely from the class level OnStartUChanged event script. However the first MySphere has an instance script. The script is for the OnRadiusChanged event, and is as follows:
IObject radiusProperty = context.Site.GetPropertyByName("Radius"); string val = context.Site.GetValueAsString(radiusProperty);
context.Site.DisplayName = val;
This script is almost the same as the class level script, except this instance script uses the radius value as its display name.
Try changing the Radius and StartU properties on the two spheres. The sample has two GUI sliders for this. The first slider modifies the first MySphere radius to activate the OnRadiusChanged event script. The second slider changes the second MySphere StartU to activate the class level OnStartUChanged event script.