(ats3-dev01) introduction to scripting in symyx notebook
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/1.jpg)
(ATS3-DEV01) Introduction to Scripting in Symyx Notebook
Mark BenzelPrincipal Software Engineer, R&D
![Page 2: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/2.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/3.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/4.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/5.jpg)
Demo• Dynamic toolbars
![Page 6: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/6.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/7.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/8.jpg)
Demo• Experiment Editor events
![Page 9: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/9.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/10.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/11.jpg)
Demo• Forms events
![Page 12: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/12.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/13.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/14.jpg)
Demo• Table section scripting
![Page 15: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/15.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/16.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/17.jpg)
Demo• Property events scripting
![Page 18: (ATS3-DEV01) Introduction to Scripting in Symyx Notebook](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/18.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/19.jpg)
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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/20.jpg)
• 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](https://reader033.vdocuments.us/reader033/viewer/2022042613/54540acbaf795987748b5291/html5/thumbnails/21.jpg)
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