Automate copy paste Excel ranges dynamically from different sheets - excel

I have tables in different sheets of excel and requirement is to copy second last row of table to last row. Can someone pls help me how can we dynamically find table size so that code wont be required to change evrytime when table size changes? There are many tables and we want to automate this task using vba code and macro button.
I have written a code but that is range specific and everytime I need to update the range and process become cumbersome.
Sub history_copy()
Set obj = ActiveWorkbook.Sheets("sheet A")
obj.Range("E12:N12").Value = obj.Range("E11:N11").Value
obj.Range("E34:N34").Value = obj.Range("E33:N33").Value
obj.Range("E46:N46").Value = obj.Range("E45:N45").Value
obj.Range("E57:N57").Value = obj.Range("E56:N56").Value
Set obj1 = ActiveWorkbook.Sheets("sheet b ")
obj1.Range("G21:O21").Value = obj1.Range("G20:O20").Value
Set obj2 = ActiveWorkbook.Sheets("sheet c")
obj2.Range("D4:M4").Value = obj2.Range("D3:M3").Value
obj2.Range("D14:M14").Value = obj2.Range("D13:M13").Value
obj2.Range("D23:M23").Value = obj2.Range("D22:M22").Value
obj2.Range("D33:M33").Value = obj2.Range("D32:M32").Value
obj2.Range("D43:M43").Value = obj2.Range("D42:M42").Value
obj2.Range("D52:M52").Value = obj2.Range("D51:M51").Value
obj2.Range("D61:M61").Value = obj2.Range("D60:M60").Value
obj2.Range("D70:M70").Value = obj2.Range("D69:M69").Value
obj2.Range("D79:M79").Value = obj2.Range("D78:M78").Value
obj2.Range("D88:M88").Value = obj2.Range("D87:M87").Value
obj2.Range("D97:M97").Value = obj2.Range("D96:M96").Value
obj2.Range("D106:M106").Value = obj2.Range("D105:M105").Value
obj2.Range("D114:M114").Value = obj2.Range("D113:M113").Value
Set obj3 = ActiveWorkbook.Sheets("sheet d")
obj3.Range("D4:L4").Value = obj3.Range("D3:L3").Value
Set obj5 = ActiveWorkbook.Sheets("sheet f")
obj5.Range("D4:L4").Value = obj5.Range("D3:L3").Value
Set obj6 = ActiveWorkbook.Sheets("sheet e")
obj6.Range("C4:C12").Value = obj6.Range("B4:B12").Value
obj6.Range("H4:H8").Value = obj6.Range("G4:G8").Value
obj6.Range("N4:N11").Value = obj6.Range("M4:M11").Value
obj6.Range("S4:S10").Value = obj6.Range("R4:R10").Value
obj6.Range("X4:X18").Value = obj6.Range("W4:W18").Value
obj6.Range("AD4:AD9").Value = obj6.Range("AC4:AC9").Value
obj6.Range("AI4:AI13").Value = obj6.Range("AH4:AH13").Value
obj6.Range("AO4:AO6").Value = obj6.Range("AN4:AN6").Value
obj6.Range("AT4:AT11").Value = obj6.Range("AS4:AS11").Value
obj6.Range("AY4:AY20").Value = obj6.Range("AX4:AX20").Value
obj6.Range("BD4:BD10").Value = obj6.Range("BC4:BC10").Value
obj6.Range("BI4:BI21").Value = obj6.Range("BH4:BH21").Value
Set obj7 = ActiveWorkbook.Sheets("sheet i")
obj7.Range("C4:C12").Value = obj7.Range("B4:B12").Value
obj7.Range("H4:H8").Value = obj7.Range("G4:G8").Value
obj7.Range("N4:N11").Value = obj7.Range("M4:M11").Value
obj7.Range("S4:S10").Value = obj7.Range("R4:R10").Value
obj7.Range("X4:X18").Value = obj7.Range("W4:W18").Value
obj7.Range("AD4:AD9").Value = obj7.Range("AC4:AC9").Value
obj7.Range("AI4:AI13").Value = obj7.Range("AH4:AH13").Value
obj7.Range("AO4:AO6").Value = obj7.Range("AN4:AN6").Value
obj7.Range("AT4:AT11").Value = obj7.Range("AS4:AS11").Value
obj7.Range("AY4:AY20").Value = obj7.Range("AX4:AX20").Value
obj7.Range("BD4:BD10").Value = obj7.Range("BC4:BC10").Value
obj7.Range("BI4:BI21").Value = obj7.Range("BH4:BH21").Value
End Sub

Related

How to merge cells without losting data in libreoffice-calc?

Launch libreoffice-calc:
soffice --calc --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
Launch python shell to write data into the calc:
import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
svcmgr = context.ServiceManager
desktop = svcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", context)
oDoc = desktop.loadComponentFromURL( "private:factory/scalc","_blank", 0, () )
oSheet = oDoc.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("A1:C3")
Write data into oRange.
oRange.setDataArray((('a1','a2','a3'),('b1','b2','b3'),('c1','c2','c3'),))
The calc's appearance now:
I want to merge all data in oRange and format it with vertical and horizontal alignment.
My desired effect in the editing calc.
oRange.merge()
oCell = oSheet.getCellByPosition(0, 0)
oCell.HoriJustify = 2
oCell.VertJustify = 2
Merged data with vertical and horizontal alignment ,previous data in many cells b1-c1 and a2-c2 and a3-c3 lost.
The real effect.
How to fix my code to get the desired effect?
import uno
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
svcmgr = context.ServiceManager
desktop = svcmgr.createInstanceWithContext("com.sun.star.frame.Desktop", context)
oDoc = desktop.loadComponentFromURL( "private:factory/scalc","_blank", 0, () )
oSheet = oDoc.getSheets().getByIndex(0)
oRange = oSheet.getCellRangeByName("A1:C3")
tup = (('a1','a2','a3'),('b1','b2','b3'),('c1','c2','c3'),)
oRange.setDataArray(tup)
target =''
for item in tup:
tmp = ' '.join(item)
target = target + tmp + ' '
target = target.strip()
oRange.merge(True)
oCell = oSheet.getCellByPosition(0, 0)
oCell.String = target
oCell.HoriJustify = 2
oCell.VertJustify = 2
I'm not sure, but I think UNO has no way of knowing that you want to rearrange the data into the merged cell that way. What UNO does is "copy" the data from the "main" cell (the top left one) and "paste" its data into the merged cell. Therefore, what you could do is change the data of the main cell before merging. Check the example below.
# get range
oRange = oSheet.getCellRangeByName("A1:C3")
# build string
flat_list = [str(item) for sublist in oRange.getDataArray() for item in sublist]
string = ' '.join(flat_list)
# put string into main cell
main_cell = oRange.getCellByPosition(0, 0)
main_cell.setString(string)
# merge
oRange.merge()

Microsoft Excel is waiting for another application to complete an OLE action after 63rd loop

I've been using the following script to run Agent trace reports on call center agents daily for our primary call center site, which has between 40 and 50 agents at any given time. I'm now expanding this reporting to our other sites, having to run the report for 234 agents at a time. I tried setting the loop for the full list of 234 agents, and after the 63rd agent is completed, I get the OLE error.
I've tried adding 'DoEvents" and 'Application.Wait' throughout the code to slow things down a bit and to ensure that the process completes before the next starts , I've also broken up the code from 1 loop of 234 into 4 loops of 60 (the last loop is only 54 for you math junkies), but I'm still getting the OLE error after agent 63 completes.
How can I determine what is causing this OLE error?
Sub CMSConn()
Dim cvsApp As Object
Dim cvsConn As Object
Dim cvsSrv As Object
Dim Rep As Object
Dim Info As Object, Log As Object, b As Object
Dim Agents(234) As String
Dim I As Integer
Set wk = ThisWorkbook
serverAddress = "xxx.xxx.xxx.xxx"
mydate = InputBox("Dates: ")
UserName = InputBox("User ID: ")
passW = InputBox("Password: ")
Agents(1) = "Abcede, Ronaldo"
Agents(2) = "Abella, Poltaqn"
Agents(3) = "Ablen, Armie"
Agents(4) = "Abon, Sherry Lou"
Agents(5) = "Acbang, MaryJane"
Agents(6) = "Acbang, MaryJane"
Agents(7) = "Alcantara, Luis Jaim"
Agents(8) = "Alfaro, Nio"
Agents(9) = "Aman, Sherwin"
Agents(10) = "Amar, Catherine"
Agents(11) = "Amor, Charlie"
Agents(12) = "Anonuevo, Hubert"
Agents(13) = "Antonio, Brian Antho"
Agents(14) = "Antonio, Diana Grace"
Agents(15) = "Aragon, Ramiro"
Agents(16) = "Araullo, Keith"
Agents(17) = "Arevalo, Jerome"
Agents(18) = "Arnel Decano"
Agents(19) = "Arriola, Paulo"
Agents(20) = "Asturias, Sheena"
Agents(21) = "Baguhin, Kathrin May"
Agents(22) = "Balatbat, Lauro"
Agents(23) = "Balena, Nathan"
Agents(24) = "Ballos, Evelyn"
Agents(25) = "Banaban, Nona"
Agents(26) = "Bansale, Jemma"
Agents(27) = "Bautista, Bernie"
Agents(28) = "Bautista, Domingo J"
Agents(29) = "Belen, Michelle"
Agents(30) = "Bicaldo, Catherine"
Agents(31) = "Bonifacio, Allan"
Agents(32) = "Borbon, Danny"
Agents(33) = "Brian Patrick Roxas"
Agents(34) = "Bundalian, Kristel J"
Agents(35) = "Bundalian, Paul"
Agents(36) = "Cabasa, Aidel Joy"
Agents(37) = "Cabauatan, Jacquelin"
Agents(38) = "Caldina, Joanne Nico"
Agents(39) = "Calumpiano, Jean"
Agents(40) = "Camarao, Maria There"
Agents(41) = "Capucao, Daisy"
Agents(42) = "Carpio, Rusell"
Agents(43) = "Caunca, Michael John"
Agents(44) = "Cequeña, Dianne"
Agents(45) = "Chinen, Jeffrey"
Agents(46) = "Chrisgeena Clemeno"
Agents(47) = "Clarin, Marco Leandr"
Agents(48) = "Clauag, Martin Paul"
Agents(49) = "Corbilla. Marcel"
Agents(50) = "Cruz, Cherrimei"
Agents(51) = "Cruz, Geran Judeth"
Agents(52) = "Cruz, Lorreine"
Agents(53) = "Cuaresma Sheila Mari"
Agents(54) = "Cudiamat, Catherine"
Agents(55) = "Cudiamat, Paul"
Agents(56) = "Cueva, Ruthie"
Agents(57) = "Dalida, Rowell"
Agents(58) = "De Guzman, Jennelyn"
Agents(59) = "De Vera, Chris Evert"
Agents(60) = "DeGuzman, Aubrey"
Agents(61) = "DeGuzman, Noel"
Agents(62) = "Del Monte, Mark"
Agents(63) = "Dela Fuente, Herner"
Agents(64) = "Dela Mesa, Randy"
Agents(65) = "Delape Jr., Evelio"
Agents(66) = "10404"
Agents(67) = "Delos Santos, Ervin"
Agents(68) = "Diaz, Jerosalem"
Agents(69) = "Diaz, Leila Ruth"
Agents(70) = "Dicen, Melanie"
Agents(71) = "Dimailig, Kenneth"
Agents(72) = "Dizon, Marc Anthony"
Agents(73) = "Doblas, Leora"
Agents(74) = "Domingo, Rafael"
Agents(75) = "Dulay, Susana Marie"
Agents(76) = "Dy, Jerwin"
Agents(77) = "Elnas, Bernadette"
Agents(78) = "Elnas, Elsha Marie"
Agents(79) = "Enumerable, Gary"
Agents(80) = "Escobal, Aubrey"
Agents(81) = "Escorpion, Genix"
Agents(82) = "Espaldon, Eveleen"
Agents(83) = "Esquivel, Jean Paul"
Agents(84) = "Estabillo,Reygienald"
Agents(85) = "Esteban, Aaron Paul"
Agents(86) = "Esteban, Richard"
Agents(87) = "Fe Marie Jopia"
Agents(88) = "Fermin, Maricris"
Agents(89) = "Fresado, Marie"
Agents(90) = "Gagarin, Wilson"
Agents(91) = "Galero, Roxanne"
Agents(92) = "Gamboa, Aleli"
Agents(93) = "Garcia, Jayson"
Agents(94) = "Garcia, Rey"
Agents(95) = "Garganta, Angelie"
Agents(96) = "Gepolane, Jacinth Ka"
Agents(97) = "Geroche, Raul"
Agents(98) = "Gilera, Erwin"
Agents(99) = "Go, Mark Dexter"
Agents(100) = "Godillo, Albert"
Agents(101) = "Grospe, Noemi"
Agents(102) = "Gualin, Raymond"
Agents(103) = "Guela, Antonette"
Agents(104) = "Guevarra, Randy"
Agents(105) = "Guiang, Mary Paula"
Agents(106) = "Gumera, Diana Corina"
Agents(107) = "Hernandez, Jules"
Agents(108) = "Hora, Gene Patrick"
Agents(109) = "Hu Kwong Man"
Agents(110) = "Iballar, Maria Chris"
Agents(111) = "Ignacio, Florabel"
Agents(112) = "Ilaga, Eunice"
Agents(113) = "Inovero, Michelle"
Agents(114) = "Ismail, Amir"
Agents(115) = "Jaen, Ritchiedel"
Agents(116) = "Jimeno, Evita"
Agents(117) = "Joanne Marie Sai"
Agents(118) = "John Michael Abellar"
Agents(119) = "Julian, Desiree"
Agents(120) = "Justine Joy Lucban"
Agents(121) = "Justiniano, Eufraime"
Agents(122) = "Karen Cathley Digman"
Agents(123) = "Lamparas, Nenita"
Agents(124) = "Laxa, Catherine"
Agents(125) = "Lecoto, Vener"
Agents(126) = "Leuterio, Ilene"
Agents(127) = "Limbo, Karen"
Agents(128) = "Lingad, Raymond"
Agents(129) = "Liza, Joseph Jay"
Agents(130) = "Lomongo, Wilbert"
Agents(131) = "Loreto, Aguilar"
Agents(132) = "Lugtu , Jude"
Agents(133) = "Luzon, Liza"
Agents(134) = "Ma. Eleonor Tabing"
Agents(135) = "Mabborang, Queenly"
Agents(136) = "Mabini, Eve"
Agents(137) = "Macababda, Marijo"
Agents(138) = "Macutay, Charlotte"
Agents(139) = "Macutay, Mark Anthon"
Agents(140) = "Magtangob, Julius"
Agents(141) = "Manago, Roman Carlo"
Agents(142) = "Manaloto, Marlon"
Agents(143) = "Mangaoang, Carmel Ri"
Agents(144) = "Mapolon, Amie"
Agents(145) = "Martin, Maricar"
Agents(146) = "Martin, Sharon"
Agents(147) = "Mendoza, Dann Kristo"
Agents(148) = "Mendoza, Liezl"
Agents(149) = "Mesias, Hannah"
Agents(150) = "Miranda, Nicola Elan"
Agents(151) = "Miranda, Sheila"
Agents(152) = "Mirandilla, Paulo"
Agents(153) = "Mislang Jr., Roberto"
Agents(154) = "Montances, Raquel"
Agents(155) = "Montefalcon, Erliza"
Agents(156) = "Munar, Rommel"
Agents(157) = "Naluz, Alexis Viktor"
Agents(158) = "Narbuada, Norman"
Agents(159) = "Nirza, Miguel"
Agents(160) = "Orteza, Gian Carlo"
Agents(161) = "Oteyza, Karen Rosell"
Agents(162) = "Panganiban, Karina"
Agents(163) = "Panganiban, Leah"
Agents(164) = "Papina, Roland"
Agents(165) = "Parel, Rose Ann Chri"
Agents(166) = "Parra, Nimfa"
Agents(167) = "Pascua, Ramon"
Agents(168) = "Pasuquin, Mary Grace"
Agents(169) = "Pauig, Sue Laine"
Agents(170) = "Perlas, Joby Jade"
Agents(171) = "Poñado, Rachal"
Agents(172) = "Puli, Ivan"
Agents(173) = "Pumar, Elora Ann"
Agents(174) = "Quintos, Stephen Ed"
Agents(175) = "Ramirez, Requel"
Agents(176) = "Ramos, Eumir"
Agents(177) = "Ramos, Rosemarie."
Agents(178) = "Rarangol, Jane"
Agents(179) = "Rebugio, Mark Joseph"
Agents(180) = "Reotutar, Neil Clark"
Agents(181) = "Resurreccion, Aimee"
Agents(182) = "Reyes, Lymuel"
Agents(183) = "Ricafranca, Nikolai"
Agents(184) = "Rino, Kim Eric"
Agents(185) = "Rioja, Daisy"
Agents(186) = "Robidillo, Fatima"
Agents(187) = "Rolando Lindog"
Agents(188) = "Romero, Darling"
Agents(189) = "Rosas, Bryan Carlo"
Agents(190) = "Rowena Rona"
Agents(191) = "Sacrez, Ma Aurora"
Agents(192) = "Sai, Joanna Marie"
Agents(193) = "Salvacion, Fairodz b"
Agents(194) = "Salvador Jr, Rolando"
Agents(195) = "Santibanez, Norman"
Agents(196) = "Santos, Mayleen Sa"
Agents(197) = "Saribay, Mark"
Agents(198) = "Saulog, Giovannie"
Agents(199) = "Seludo, Loida"
Agents(200) = "Sereno, Marjorie"
Agents(201) = "Serrano, Zacheus"
Agents(202) = "Sheremeil Tan"
Agents(203) = "Silverio II, Carlo"
Agents(204) = "Tambobong , Regina"
Agents(205) = "Tan, Boon Beng"
Agents(206) = "Tapia, Dianne Andrea"
Agents(207) = "Tingzon, Jan Therese"
Agents(208) = "Tolentino, Glennford"
Agents(209) = "Tolentino, Rodney"
Agents(210) = "Tolosa, Joy Maru"
Agents(211) = "Tolosa, Rod Jeffrey"
Agents(212) = "Toong, Rene"
Agents(213) = "Torilla, Nathaniel"
Agents(214) = "Tort, Mary Grace"
Agents(215) = "Trinidad, Francis"
Agents(216) = "Tubice, Janette"
Agents(217) = "Tudlasan, Mary Jo"
Agents(218) = "Tuguib, Rodney"
Agents(219) = "Tulawan, Joedelyn"
Agents(220) = "Uy, Gretchen Mari St"
Agents(221) = "Valebia, Kristine"
Agents(222) = "Valenzuela, Demsey"
Agents(223) = "Valenzuela, Myles"
Agents(224) = "Vargas, Christine"
Agents(225) = "Vargas, Jose"
Agents(226) = "Villanueva, Marcelle"
Agents(227) = "Villanueva, Vigie"
Agents(228) = "Villaver, Conrado"
Agents(229) = "Virtudazo, Joeurbett"
Agents(230) = "Viscante, Emelson"
Agents(231) = "Yap, Paul"
Agents(232) = "Ylagan, Celin"
Agents(233) = "Ylidon, Andrew"
Agents(234) = "Yrrverre, Neil Vince"
Set cvsApp = CreateObject("ACSUP.cvsApplication")
Set cvsConn = CreateObject("ACSCN.cvsConnection")
Set cvsSrv = CreateObject("ACSUPSRV.cvsServer")
Set Rep = CreateObject("ACSREP.cvsReport")
For I = 1 To 234
agentName = Agents(I)
If cvsApp.CreateServer(UserName, "", "", serverAddress, False, "ENU", cvsSrv, cvsConn) Then
If cvsConn.login(UserName, passW, serverAddress, "ENU") Then
On Error Resume Next
cvsSrv.Reports.ACD = 1
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Set Info = cvsSrv.Reports.Reports("Historical\Agent\Trace by Location")
If Info Is Nothing Then
If cvsSrv.Interactive Then
MsgBox "The Report " & "Historical\Agent\Trace by Location" & " was not found on ACD 1", vbCritical Or vbOKOnly, "CentreVu Supervisor"
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Else
Set Log = CreateObject("ACSERR.cvslog")
Log.AutoLogWrite "The Report " & "Historical\Agent\Trace by Location" & " was not found on ACD 1"
Set Log = Nothing
End If
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Else
b = cvsSrv.Reports.CreateReport(Info, Rep)
If b Then
Debug.Print Rep.SetProperty("Agent", Agents(I)) ' agentName)
Debug.Print Rep.SetProperty("Dates", mydate)
Debug.Print Rep.SetProperty("Times", "00:00-23:59")
b = Rep.ExportData("", 9, 0, False, True, True)
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
wk.Sheets(I).Select
wk.Sheets(I).Cells.ClearContents
wk.Sheets(I).Cells(1, 1).PasteSpecial
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing
Set Log = Nothing
Set Rep = Nothing
Set cvsSrv = Nothing
Set cvsConn = Nothing
Set cvsApp = Nothing
Set Info = Nothing
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
End If
End If
End If
End If
ActiveWorkbook.Save
DoEvents
Application.Wait (Now + TimeValue("0:00:01"))
Next I
cvsConn.logout
cvsConn.Disconnect
cvsSrv.Connected = False
DoEvents
MsgBox "Completed"
End Sub

How to inset a customer location through graph

Hello I am banging my head against the wall trying find the correct way to insert a customer location using a graph. I am currently using the PX.Objects.CR.CustomerLocationMaint graph. But when I insert or set current location it is always null.
Here is my code
private PX.Objects.CR.Location UpdateCustomerLocation(PX.Objects.AR.Customer cust, ListingRead currentListing, ListingContactRelnListing contact)
{
PX.Objects.AR.CustomerLocationMaint g = new PX.Objects.AR.CustomerLocationMaint();
g.Clear(PXClearOption.ClearAll);
g.BusinessAccount.Current = cust;
PX.Objects.CR.Location loc = new PX.Objects.CR.Location();
loc.BAccountID = cust.BAccountID;
loc.LocationCD = "RL" + contact.contact.id;
loc.Descr = currentListing.property.system_search_key;
loc.DefContactID = cust.DefContactID;
loc.IsActive = true;
loc.LocType = "CU";
g.Location.Current = loc;
loc = g.Location.Insert(loc);
PX.Objects.CR.Address addr = new PX.Objects.CR.Address();
addr.BAccountID = cust.BAccountID;
addr.AddressType = "BS";
addr.CountryID = "NZ";
addr.AddressLine1 = currentListing.property.adr_street_number + " " + currentListing.property.adr_street_name;
addr.AddressLine2 = currentListing.property.adr_suburb_or_town;
addr.AddressLine3 = currentListing.property.adr_state_or_region;
addr = g.Address.Insert(addr);
loc.DefAddressID = addr.AddressID;
g.Location.Update(loc);
g.Actions.PressSave();
return loc;
}

(Python/Pygame) Best way to load a LOT of images at the same time?

I have a function to load sounds, but not one for loading images. This is how my image loading is layed out currently:
if os.path.exists("themes/voltorb"):
vgui = pygame.image.load("themes/voltorb/gui.png")
voptions = pygame.image.load("themes/voltorb/options.png")
vachievements = pygame.image.load("themes/voltorb/achievements.png")
voverlay = pygame.image.load("themes/voltorb/overlay.png")
vconfirm = pygame.image.load("themes/voltorb/confirm.png")
vboom = pygame.mixer.Sound("themes/voltorb/boom.mp3")
vcoin = pygame.mixer.Sound("themes/voltorb/coin.mp3")
vtheme = {"gui":vgui,"options":voptions,"achievements":vachievements,"overlay":voverlay,"confirm":vconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"v":vtheme})
if os.path.exists("themes/fluttershy"):
fcoin = pygame.mixer.Sound("themes/fluttershy/coin.mp3")
fgui = pygame.image.load("themes/fluttershy/gui.png")
foptions = pygame.image.load("themes/fluttershy/options.png")
fachievements = pygame.image.load("themes/fluttershy/achievements.png")
foverlay = pygame.image.load("themes/fluttershy/overlay.png")
ftheme = {"gui":fgui,"options":foptions,"achievements":fachievements,"overlay":foverlay,"confirm":fconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"f":ftheme})
if os.path.exists("themes/mario"):
mgui = pygame.image.load("themes/mario/gui.png")
moptions = pygame.image.load("themes/mario/options.png")
machievements = pygame.image.load("themes/mario/achievements.png")
moverlay = pygame.image.load("themes/mario/overlay.png")
mtheme = {"gui":mgui,"options":moptions,"achievements":machievements,"overlay":moverlay,"confirm":mconfirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"m":mtheme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret1"):
s1gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/gui.png")
s1options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/options.png")
s1achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/achievements.png")
s1overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret1/overlay.png")
s1theme = {"gui":s1gui,"options":s1options,"achievements":s1achievements,"overlay":s1overlay,"confirm":s1confirm,"coin":vcoin,"boom":vboom,"music":vmusic}
themedb.update({"s1":s1theme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret2"):
s2gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/gui.png")
s2options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/options.png")
s2achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/achievements.png")
s2overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret2/overlay.png")
s2theme = {"gui":s2gui,"options":s2options,"achievements":s2achievements,"overlay":s2overlay,"confirm":s2confirm,"coin":s2coin,"boom":s2boom,"music":s2music}
themedb.update({"s2":s2theme})
if os.path.exists("%appdata%/KWScripts/Voltorb/themes/secret3"):
s3gui = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/gui.png")
s3options = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/options.png")
s3achievements = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/achievements.png")
s3overlay = pygame.image.load("%appdata%/KWScripts/Voltorb/themes/secret3/overlay.png")
s3theme = {"gui":s3gui,"options":s3options,"achievements":s3achievements,"overlay":s3overlay,"confirm":s3confirm,"coin":s3coin,"boom":s3boom,"music":s3music}
themedb.update({"s3":s3theme})
I'm not sure if there's any easy way to do this, but I have the most difficult way typed already. If anyone has an idea of how to shorten this, then thanks!
Take all your images and put them in a dict, where the key is the variable you were using, and the value is the path:
vimages = {'vgui': "themes/voltorb/gui.png", 'voptions': "themes/voltorb/options.png", 'vachievements': "themes/voltorb/achievements.png"} # and so on...
Then, iterate through vimages, checking for the existence of each individual file, then calling pygame.image.load() on it, and store the result in your already-existing dict (vtheme, in this case).
This way, you don't need to keep writing out pygame.image.load() over and over again.

Using automapper to reverse map from dto

Given the following code, is there anyway to get Automapper to do this instead of manually setting the properties? I'm trying to avoid having to do a one to one mapping at Mapper.CreateMap, since I;m constantly adding and removing fields from Contract, and at the moment have to remember to update this method with the changes.
private void MapModelToContract(ContractDto model, Contract contract)
{
contract.Id = model.Id;
contract.ContractDetail.BuyerCornhouseName = model.ContractDetailBuyerCornhouseName;
contract.ContractDetail.CnoCornLtdToBuyer = model.ContractDetailCnoCornLtdToBuyer;
contract.ContractDetail.CnoCornPartToCornLtd = model.ContractDetailCnoCornPartToCornLtd;
contract.ContractDetail.CnoSellerCornLtd = model.ContractDetailCnoSellerCornLtd;
contract.ContractDetail.CnoSellerCornPart = model.ContractDetailCnoSellerCornPart;
contract.ContractDetail.Commission = model.ContractDetailCommission;
contract.ContractDetail.ContractPrice = model.ContractDetailContractPrice;
contract.ContractDetail.SalesPriceToCornLtd = model.ContractDetailSalesPriceToCornLtd;
contract.ContractDetail.ContractedQuantity = model.ContractDetailContractedQuantity;
contract.ContractDetail.CostWarehouseToFob = model.ContractDetailCostWarehouseToFob;
contract.ContractDetail.Date = model.ContractDetailDate;
contract.ContractDetail.DeliveryDate = model.ContractDetailDeliveryDate;
contract.ContractDetail.FinalBuyerName = model.ContractDetailFinalBuyerName;
contract.ContractDetail.FinalSalesPrice = model.ContractDetailFinalSalesPrice;
contract.ContractDetail.Grade = model.ContractDetailGrade;
contract.ContractDetail.Notes = model.ContractDetailNotes;
contract.ContractDetail.PayableQuantity = model.ContractDetailPayableQuantity;
contract.ContractDetail.SalesShipmentPeriod = model.ContractDetailSalesShipmentPeriod;
contract.ContractDetail.SellerName = model.ContractDetailSellerName;
contract.ContractDetail.ToBePaidBy = model.ContractDetailToBePaidBy;
contract.ContractDetail.SalesBasis = model.ContractDetailSalesBasis;
contract.ContractDetail.SalesFreightValue = model.ContractDetailSalesFreightValue;
contract.CurrencyContract.Date = model.CurrencyContractDate;
contract.CurrencyContract.ExchangeRate = model.CurrencyContractExchangeRate;
contract.CurrencyContract.Number = model.CurrencyContractNumber;
contract.CurrencyContract.Value = model.CurrencyContractValue;
contract.CurrencyContract.IsAcc = model.CurrencyContractIsAcc;
contract.CurrencyContract.RepaidOn = model.CurrencyContractRepaidOn;
contract.CurrencyContract.RepaymentDate = model.CurrencyContractRepaymentDate;
contract.Discounts.Reason = model.DiscountsReason;
contract.Discounts.Value = model.DiscountsValue;
contract.DocumentControl.GuaranteeLetterReceived = model.DocumentControlGuaranteeLetterReceived;
contract.DocumentControl.PhotosReceived = model.DocumentControlPhotosReceived;
contract.GoodsStatus.ContainerNumber = model.GoodsStatusContainerNumber;
contract.GoodsStatus.EtaPort = model.GoodsStatusEtaPort;
contract.GoodsStatus.ExpectedDeliveryDate = model.GoodsStatusExpectedDeliveryDate;
contract.GoodsStatus.Port = model.GoodsStatusPort;
contract.GoodsStatus.ShippedStatus = model.GoodsStatusShippedStatus;
contract.GoodsStatus.VesselDeadline = model.GoodsStatusVesselDeadline;
contract.GoodsStatus.VesselName = model.GoodsStatusVesselName;
contract.GoodsStatus.HasSellerConfirmedRelease = model.GoodsStatusHasSellerConfirmedRelease;
contract.GoodsStatus.ReceivedShippingInstructions = model.GoodsStatusReceivedShippingInstructions;
contract.GoodsStatus.Notes = model.GoodsStatusNotes;
contract.NotaFiscalCornPart.Date = model.NotaFiscalCornPartDate;
contract.NotaFiscalCornPart.ExchangeRate = model.NotaFiscalCornPartExchangeRate;
contract.NotaFiscalCornPart.Number = model.NotaFiscalCornPartNumber;
contract.NotaFiscalSeller.Date = model.NotaFiscalSellerDate;
contract.NotaFiscalSeller.GoodsReleased = model.NotaFiscalSellerGoodsReleased;
contract.NotaFiscalSeller.Number = model.NotaFiscalSellerNumber;
contract.TransferToSeller.Date = model.TransferToSellerDate;
contract.TransferToSeller.TransferredFrom = model.ContractDetailBuyerCornhouseName;
contract.TransferToSeller.Value = model.TransferToSellerValue;
contract.CommissionLawyer.IsPaid = model.CommissionLawyerIsPaid;
}
The below mapper works for you.
If the Source (ContractDto) and Destination (Contract) have same property names.
Mapper.CreateMap<ContractDto, Contract>(); // Maps if ContractDto & Contract have same property names
If the Source (ContractDto) and Destination (Contract) have diff property names. Then
Mapper.CreateMap<ContractDto, Contract>()
.ForMember(destination => destination.BuyerCornhouseName, options => options.MapFrom(source => source.ContractDetailBuyerCornhouseName))
.ForMember(destination => destination.CnoCornLtdToBuyer, options => options.MapFrom(source => source.ContractDetailCnoCornLtdToBuyer));
// Explicitly you have specify for other properties also

Resources