(ats3-dev01) introduction to scripting in symyx notebook

21
(ATS3-DEV01) Introduction to Scripting in Symyx Notebook Mark Benzel Principal Software Engineer, R&D [email protected]

Upload: accelrys

Post on 01-Nov-2014

467 views

Category:

Technology


12 download

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.

TRANSCRIPT

Page 1: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

(ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Mark BenzelPrincipal Software Engineer, R&D

[email protected]

Page 2: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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.

Page 3: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 4: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 5: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Demo• Dynamic toolbars

Page 6: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 7: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 8: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Demo• Experiment Editor events

Page 9: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 10: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Forms Events

• Scripts can be attached to form and widget events– Form events:

• OnEdit• OnValueChanged

– Widget events:• OnReview• OnValidate• OnClick (buttons only)

Page 11: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Demo• Forms events

Page 12: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 13: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 14: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Demo• Table section scripting

Page 15: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Table Section Scripting

• Key script variables

– sender : the TableSection

– e• FieldName• OldValue• TheDataRow• Value

• Cancel, CancelMessage (if cancelable)

– row (for row-based events)

Page 16: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 17: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

Demo• Property events scripting

Page 18: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 19: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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

Page 20: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

• 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

Page 21: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook

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