import clr import sys clr.AddReference("Symyx.Framework") from Symyx.Framework.Vault import VaultWorkspace from Symyx.Framework import Extensibility, UnitsHelper, UnitKey from Symyx.Framework.Chemistry import * from Symyx.Framework.Extensibility import * from System.Windows.Forms import DialogResult, MessageBox, MessageBoxButtons, MessageBoxIcon from System import String def FindSectionToUpdate(sectionName): for section in editor.Document.Sections: if(sectionName == section.Title): return section return None assemblyLoaded = True try: # This next line is only used if you are debugging an assembly. # This AddReference assumes that the SolutionCalc.dll is in # C:\Program Files\Symyx\Symyx Notebook\bin. Comment out this # line if you are loading the assembly from Vault. clr.AddReference("RecNetReg") # Uncomment the next two lines if you want to load the assembly # from Vault. You will need to match Version and PublicKeyToken # with those assigned to the DLL. # assembly = AssemblyCache.GetAssembly("IsMaterialLookup, Version=1.0.0.0, Culture=neutral, PublicKeyToken=861ce1c5ef4a55b3") # clr.AddReference(assembly) from RecNetReg import * except: assemblyLoaded = False errMsg = 'An error was encountered referencing a required assembly.' MessageBox.Show(errMsg, 'Assembly Reference Error', MessageBoxButtons.OK, MessageBoxIcon.Error) if assemblyLoaded: # The calls to the custom assembly follow. The first line userid = VaultWorkspace.Current.CurrentUser.UserName section = editor.ActiveDocumentSection bckSection = FindSectionToUpdate('Background') conto = bckSection.View.Forms['BaseForm1'].Controls labno = conto['GroupBox1'].Controls['TextBox1'].Text recnet = RecNetIO() recnet.Initialize('drdisc', 'chem', 'chem', 'chem', userid) rows = section.GetSelectedRows() rowIndex = 0 for row in rows: zebatch = row.PropertySets["Rec_Reg"]["B_BatchCode"].Value if zebatch is None: batch = Batch() molecule = Molecule() molecule.MolFile = row.PropertySets["Material"]["Structure"].Value.Chimestring molecule.Name = row.PropertySets["Material"]["Name"].Value #molecule.Program = row.PropertySets["Rec_Background"]["ProjectCode"].Value batch.LabNotebook = labno if row.PropertySets["ActualAmount"]["CalcMass"].Value.Unit != UnitKey.UNDEFINED: batch.Amount = UnitsHelper.Convert(row.PropertySets["ActualAmount"]["CalcMass"].Value, UnitKey.MILLIGRAM).Number if row.PropertySets["ActualAmount"]["Yield"].Value.Number > 0: batch.PctYield = row.PropertySets["ActualAmount"]["Yield"].Value.Number batch.Author = userid reso = recnet.Register(molecule, batch) if reso.result != RegistrationReturn.RegResult.Failed: row.PropertySets["Rec_Reg"]["PActive"].Value = reso.molecule.PActive row.PropertySets["Rec_Reg"]["MolCode"].Value = reso.molecule.Code row.PropertySets["Rec_Reg"]["Synonim"].Value = reso.molecule.Sinonimo row.PropertySets["Rec_Reg"]["C_Comment"].Value = reso.compound.Comment row.PropertySets["Rec_Reg"]["C_CorpId"].Value = reso.compound.CorpId row.PropertySets["Rec_Reg"]["C_ProdType"].Value = reso.compound.ProdType row.PropertySets["Rec_Reg"]["C_SaltCode"].Value = reso.compound.SaltCode row.PropertySets["Rec_Reg"]["C_Stereo"].Value = reso.compound.Stereo row.PropertySets["Rec_Reg"]["B_BatchCode"].Value = reso.batch.BCode row.PropertySets["Rec_Reg"]["B_Seq"].Value = reso.batch.SeqLotto sezio = FindSectionToUpdate('AnalysisRequestandResults') if sezio is not None: sampleid = String.Format('{0}_{1}_{2}', reso.molecule.PActive, reso.batch.SeqLotto, reso.batch.BCode) miro = sezio.AddRow() miro.PropertySets['AnalysisRequest']['SampleID'].Value = sampleid else: reso = recnet.EditBatch(zebatch) editor.RefreshView()