import clr import sys clr.AddReference("Symyx.Framework") clr.AddReference("Symyx.Notebook") from Symyx.Framework.Vault import Workspace, VaultWorkspace, DataScope, RetrievalOptions, VaultId, VaultObjectTypes from Symyx.Framework.Vault.Security import Permissions 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 def GetPermission(application, permission): cid = 'ConfigurationVaultId' data = None ape = active_workspace.CurrentUser.ApplicationPermissions.GetApplicationPermissionFor(application, permission) if ape is not None and ape.ExtendedProperties.Contains(cid): vid = VaultId(ape.ExtendedProperties[cid].Value.ToString()) data = active_workspace.Get(vid, DataScope.All, RetrievalOptions.UseCachedVersionOffline) return data def GetPermissionData(appermission, name): reso = None if appermission is not None and not String.IsNullOrEmpty(name): for item in appermission: if item.Key == name: reso = item.Value.ToString().Replace("\r", "") break return reso assemblyLoaded = True proxy = None endpoint = None try: # This next line is only used if you are debugging an assembly. # This AddReference assumes that the SolutionCalc.dll is in perma = GetPermission('Recordati.Custom', 'Templates.LT') endpoint = GetPermissionData(perma, 'recnetWS') proxy = GetPermissionData(perma, 'recnetProxy') assembly = AssemblyCache.GetAssembly(proxy) clr.AddReference(assembly) from RecNetReg import RecNetIO #proxy = AssemblyCache.GetAssemblyFullName('AppHelpers') #assembly = AssemblyCache.GetAssembly(proxy) #clr.AddReference(assembly) #from AppHelpers import * except: assemblyLoaded = False errMsg = 'An error was encountered referencing a required assembly.' + proxy 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.SharedInstance(endpoint, userid) #recnet = RecNetIO() recnet.Initialize(endpoint, 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()