Upload
accelrys
View
471
Download
12
Tags:
Embed Size (px)
DESCRIPTION
Python scripting in Symyx Notebook provides a simple but powerful mechanism for extending the out-of-the-box capabilities of the Notebook. In this session we will review the scripting features of the ELN: where, why and how scripting can be done. We will walk through examples of writing toolbar button scripts, Experiment Editor event scripts, form scripts and various types of section scripts. And we will provide some tips and tricks for effective script programming, including a demonstration of the new script-profiling logging feature introduced in SN 6.6 Service Pack 1.Designed as an overview for people wanting to become familiar with the scripting capabilities of the Notebook, this session may also provide tips of interest for the beginning- to intermediate-level Notebook script programmer.
Citation preview
(ATS3-DEV01) Introduction to Scripting in Symyx Notebook
Mark BenzelPrincipal Software Engineer, R&D
The information on the roadmap and future software development efforts are intended to outline general product direction and should not be relied on in making a purchasing decision.
Scripting in Notebook
In-place Python editors are available in several places• Experiment Editor toolbars• Experiment Editor events• Form events and buttons• Table section events• Property events
Dynamic Toolbars
• Toolbar buttons backed by Python script can be added to the Experiment Editor
• Attached to Document Templates– Every experiment created from that template has the buttons
Demo• Dynamic toolbars
Dynamic Toolbars
• Can be attached at the document level or section level
• Script environment is populated with useful variables from Notebook– Key variables: editor, active_workspace
• Static Notebook classes are available to the script environment, and objects from the Notebook API may be instantiated
Experiment Editor Events
• Experiment Editor Events
– Scripts can be executed when a number of events in the Experiment Editor happen
– As with dynamic toolbars, they are associated with document templates, and can be attached at the document level or the document section level
– Some events can be canceled via script
Demo• Experiment Editor events
Experiment Editor Events• List of Experiment Editor Events:
OnApplicationClosingOnApplicationLoadedOnSavingOnSavedOnInsertingSectionOnLockingSectionOnRemovingSectionOnSectionInsertedOnSectionLockedOnSectionRemovedOnSectionUnlockedOnUnlockingSectionOnMenuItemEnabledStatesUpdatedOnToolBarButtonEnabledStatesUpdatedOnSectionActivatedOnSectionDeactivated
• Key variables: – e
• e.Section (for section-specific events)• e.Cancel, e.CancelReason (for cancelable events)
– editor• Represents the Experiment Editor• Properties and methods are defined in IDocumentEditor
– active_workspace• Provides services for contacting Vault
Forms Events
• Scripts can be attached to form and widget events– Form events:
• OnEdit• OnValueChanged
– Widget events:• OnReview• OnValidate• OnClick (buttons only)
Demo• Forms events
Forms Events
• OnEdit doesn’t fire when the form is in read-only mode– If OnApplicationLoaded is needed, you can put a form in a section template and have
users insert the template instead of the form
• Review Results can’t prevent a document from getting checked in– However the workflow Review activity can prevent a document from transitioning to
the next stage based on review results
Table Section Scripting• Can write scripts for the following events:
– After Cell Value Changed– After Import Row– After Record Weights– Before Import Row– Before Record Weights– Removing Row– Request Column Dictionary– Row Added– Row Changed– Row Removed– Signing Options
• Additional events for Materials sections– After Import Materials– Before Import Materials
• Additional hierarchical table events (Preparations, Formulations)
– Audit script– Component Added– Component Removed– Component Request Column Dictionary– Component Row Changed– Removing Component– Replicate Created
Demo• Table section scripting
Table Section Scripting
• Key script variables
– sender : the TableSection
– e• FieldName• OldValue• TheDataRow• Value
• Cancel, CancelMessage (if cancelable)
– row (for row-based events)
Property Events
• Property Set Definitions are reusable field definitions used by table and form sections.
• Can attach scripts to events at the property level:– Set Initial Value– Calculated Value– Property Changed– Validations
Demo• Property events scripting
Property Events
• Key variables– host_object
• property set host• E.g. Material
– properties– property– value: output parameter for Initial Value and Calculated Value scripts
– e• ValueChangedEventArgs• e.OldValueIsNull• e.NewValueIsNull• e.NewValue• e.OldValue• e.Key: QualifiedPropertyKey• ValidationResult[] ValidationResults
Tips and tricks
• Scripting Performance
– Beware of events that happen when the Experiment Editor loads, or when changing section.• OnApplicationLoaded• OnSectionActivated• OnSectionDeactivated• FormEdit
– Avoid the wire
– Use “Minimal Get’s” whenever possible
– Employ short-circuit coding
• Use the new script performance logging feature provided in Symyx Notebook 6.6 SP1
• Covered the various places scripting can be used in Symyx Notebook– Experiment Editor toolbars– Experiment Editor events– Form events and buttons– Table section events– Property events
• Resources– Symyx Notebook Developer’s Guide
• Section entitled “Scripting in Symyx Notebook”
– IronPython in Action
Summary
The information on the roadmap and future software development efforts are intended to outline general product direction and should not be relied on in making a purchasing decision.
For more information on the Accelrys Tech Summits and other IT & Developer information, please visit:https://community.accelrys.com/groups/it-dev