AdamUL Posted September 12, 2014 Share Posted September 12, 2014 After some research, I found something interesting. When you use the RGB property through COM, it sees it as BGR. Give this a try. .Shapes.Item(5).Fill.ForeColor.RGB = _WinAPI_SwitchColor(_WinAPI_RGB(255, 0, 0)) Adam Link to comment Share on other sites More sharing options...
water Posted September 12, 2014 Share Posted September 12, 2014 I noticed something similar when working on the ExcelChart UDF. I created an internal function to get the desired result - but using WinAPI is much cleaner I think.. It is completely insane to specify a red value and get a blue shape - that's why I love MS My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Jewtus Posted September 15, 2014 Author Share Posted September 15, 2014 This script sets the background color of item 5 to a dark blue and writes @error = 0 to the SciTE console. Tested with PP 2010. $oPPT = ObjCreate("PowerPoint.Application") If @error Then Exit MsgBox(0, "Error", "No PowerPoint available") AddSlide(2, 11, "Example Project") MsgBox(0, "Information", "Test ended.") Func AddSlide($slideNum, $format, $projectName) $oPresentation = $oPPT.Presentations.Open(@ScriptDir & "\Test.potx") If @error Then Exit MsgBox(0, "Error", "Error opening potx") $rows = 10 $cols = 3 $oSlide1 = $oPresentation.Slides.Add($slideNum, $format) With $oSlide1 .Shapes.Item(1).TextFrame.TextRange.Text = $projectName .Shapes.AddTextBox(1, 35, 60, 400, 50) ;type,left,top,width,height .Shapes.Item(2).TextFrame.TextRange.Text = "Overall Status" .Shapes.AddTextBox(1, 300, 60, 400, 50) .Shapes.Item(3).TextFrame.TextRange.Text = "Issues" .Shapes.AddTextBox(1, 500, 60, 400, 50) .Shapes.Item(4).TextFrame.TextRange.Text = "Next Week" .Shapes.AddShape(151, 30, 100, 200, 200) .Shapes.Item(6).Fill.ForeColor.RGB = 0xff0000 ; RGB(255, 0, 0) ConsoleWrite("@error = " & @error & @CRLF) .Shapes.AddTable($rows, $cols, 60, 120, 100, 100) EndWith EndFunc ;==>AddSlide I tried this and oddly I don't get any error (when I correct the shape index to 5 for the fill command), but the object still refuses to change colors.... Does there need to be a line around it first or something weird? After some research, I found something interesting. When you use the RGB property through COM, it sees it as BGR. Give this a try. .Shapes.Item(5).Fill.ForeColor.RGB = _WinAPI_SwitchColor(_WinAPI_RGB(255, 0, 0)) Adam I also tried this and again, no error, but no color change... Link to comment Share on other sites More sharing options...
water Posted September 15, 2014 Share Posted September 15, 2014 Which version of PowerPoint do you run (2010, 2013 ...)? On which operating sytem? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Jewtus Posted September 16, 2014 Author Share Posted September 16, 2014 Which version of PowerPoint do you run (2010, 2013 ...)? On which operating sytem? 2010 on a windows 7 machine. Link to comment Share on other sites More sharing options...
water Posted September 16, 2014 Share Posted September 16, 2014 I run the same version and it works just fine here. Can you try on another computer? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Jewtus Posted September 17, 2014 Author Share Posted September 17, 2014 Tried it on another machine and I still get the same output. The box shows up, but there is no fill. I'm using the portable version of Autoit so maybe there is something different in the _WinAPI_SwitchColor UDF? Link to comment Share on other sites More sharing options...
water Posted September 17, 2014 Share Posted September 17, 2014 The script I posted in #19 returns the following result. What do you get? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
trancexx Posted September 17, 2014 Share Posted September 17, 2014 And what do you get when you run this: expandcollapse popup#include <WinAPIGdi.au3> $oError = ObjEvent("AutoIt.Error", "MyErrFunc") Func MyErrFunc($oErrorParam) ConsoleWrite("COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oErrorParam.description & @CRLF & _ "err.windescription:" & @TAB & $oErrorParam.windescription & @CRLF & _ "err.number is: " & @TAB & $oErrorParam.number & @CRLF & _ "err.lastdllerror is: " & @TAB & $oErrorParam.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oErrorParam.scriptline & @CRLF & _ "err.source is: " & @TAB & $oErrorParam.source & @CRLF _ ) EndFunc $oPPT = ObjCreate("PowerPoint.Application") If @error Then Exit MsgBox(0, "Error", "No PowerPoint available") $oPPT.Visible = True $oPresentation = $oPPT.Presentations.Open(@ScriptDir & "\b.potx") If @error Then Exit MsgBox(0, "Error", "Error opening potx") With $oPresentation.Slides(1).Shapes .Item(1).TextFrame.TextRange.Text = "Example Thing" .AddTextBox(1, 35, 60, 400, 50) .Item(2).TextFrame.TextRange.Text = "Color changes, pay attention!" .Item(2).Fill.ForeColor.RGB = _WinAPI_SwitchColor(_WinAPI_RGB(255, 0, 0)) .AddTextBox(1, 300, 60, 400, 50) .Item(3).TextFrame.TextRange.Text = "Issues" .AddTextBox(1, 500, 60, 400, 50) .Item(4).TextFrame.TextRange.Text = "Next Weekx" .AddShape(151, 30, 100, 200, 200) $rows = 10 $cols = 3 .AddTable($rows, $cols, 60, 120, 100, 100) EndWith With $oPresentation.Slides(1).Shapes For $i = 0 To 255 If IsObj(.Item(2)) Then .Item(2).Fill.ForeColor.RGB = _WinAPI_SwitchColor(_WinAPI_RGB(255 - $i, $i/10, $i)) Sleep(10) Next EndWith ...with this (unzip it): b.zip ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Myicq Posted September 18, 2014 Share Posted September 18, 2014 (edited) Does it make a difference if you just use a "long" value instead of the RGB function ? RGB() in VBA returns a long = red*1 + green*256 + blue * 65536 This should give you full red debug.print RGB(255,0,0) ; will print 255 .Item(2).Fill.ForeColor.RGB = 255 If I try to use _WinAPI_RGB(255,0,0) I get : #include <WinAPIGdi.au3> ConsoleWrite(_WinAPI_RGB(255,0,0) & @LF) Output: 16711680 don't know why the formula is opposite in WinAPI. Edited September 18, 2014 by Myicq I am just a hobby programmer, and nothing great to publish right now. Link to comment Share on other sites More sharing options...
BrewManNH Posted September 18, 2014 Share Posted September 18, 2014 Because 0xFF0000 doesn't equal 255, it's 16711680 in decimal. If you're getting 255 back, it's being returned in BGR or COLORREF format and not in RGB format. Red = ## * 65536, while blue = ## * 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Jewtus Posted September 19, 2014 Author Share Posted September 19, 2014 After messing with this for a while, I found out I had windows updates to perform (which was causing a number of app on my PC to be semi functional). I installed the update and reset and the code posted in #19 is now working. Thanks everyone! Link to comment Share on other sites More sharing options...
water Posted September 19, 2014 Share Posted September 19, 2014 Glad that the problem could be solved My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Jewtus Posted September 19, 2014 Author Share Posted September 19, 2014 There was also a weird issue with the template I was using.. I just started from scratch and it used the same code and now it works much better. This is what it looks like in its final form: #include <WinAPIGdi.au3> $oPPT = ObjCreate("PowerPoint.Application") If @error Then MsgBox(0, "Error", "No PowerPoint available") Exit EndIf AddSlide(2, 11, "Example Project") Func AddSlide($slideNum, $format, $projectName) $oPresentation = $oPPT.Presentations.Open(@ScriptDir & "\Test.pptx") If @error Then MsgBox(0, "Error", "Error opening Presentation") Exit EndIf $rows = 10 $cols = 3 $oSlide1 = $oPresentation.Slides.Add($slideNum, $format) With $oSlide1 .Shapes.Item(1).TextFrame.TextRange.Text = $projectName .Shapes.AddTextBox(1,35,60,400,50) ;type,left,top,width,height .Shapes.Item(2).TextFrame.TextRange.Text = "Overall Status" .Shapes.AddTextBox(1,300,60,400,50) .Shapes.Item(3).TextFrame.TextRange.Text = "Issues" .Shapes.AddTextBox(1,500,60,400,50) .Shapes.Item(4).TextFrame.TextRange.Text = "Next Week" .Shapes.AddShape(1,30,100,60,120) .Shapes.Item(5).Fill.ForeColor.RGB = _WinAPI_RGB(178,178,178) .Shapes.AddTable($rows, $cols, 120, 100, 130, 100) EndWith $oPresentation.SaveAs(@ScriptDir&"\Output.ppt") $oPresentation.Quit EndFunc ;==>AddSlide Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now